Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/Graphix/GraphixLoad.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit 4cf7d6e4 on 2006-06-29 18:52:07 UTC
4cf7d6e47a Dani*0001 function [data,xax,yax,time,pltslc,XG,YG] = ...
5bbd0d07c9 Dani*0002     GraphixLoad(fil,fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,avg,slc,pst,...
                0003                 LoadGridData,GraphixDebug,GridSuffix,ZcordFile,Index,...
                0004                 Dim,Vector,Mate,uFld,vFld,gmfile,KwxFld,KwyFld,Grads,...
                0005                 Year0Iter,SecPerYear,Months,PlotFld,XL,YL,ThetaToActT,...
e5f86a2f55 Dani*0006                 ThetaToThetaEc,DataIn,SecMom,TFld,T2Fld,EtaFld,Eta2Fld,...
4cf7d6e47a Dani*0007                 u2Fld,v2Fld,DevFromMean,WFld,W2Fld);
5bbd0d07c9 Dani*0008 
                0009 % Load parameters.
                0010 GraphixGenParam;
                0011 GraphixFieldParamA;
                0012 GraphixFieldParamO;
                0013 GraphixFieldParamI;
                0014 GraphixFieldParamC;
                0015 
                0016 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0017 %             Prepare for the various data types, set time                %
                0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0019 
                0020 % Time stuff (itr = 0 is start of new 360 day year).
                0021 if isempty(Months)
                0022     months = (itr-Year0Iter)./(30.*24.*3600./tst);
                0023 else
                0024     months = Months;
                0025 end
                0026 time = months/12;
                0027 
ec0c7036df Dani*0028 if Dim == 0 & ~isequal(dat,'Mon')
5bbd0d07c9 Dani*0029     if ismember(PlotFld,fields2D) | ismember(fln,fields2D), Dim = 2; end
                0030     if ismember(PlotFld,fields3D) | ismember(fln,fields3D), Dim = 3; end
                0031     if Dim == 0
                0032         error('Unknown field dimension!');
                0033     end
                0034 end
                0035 
                0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0037 %                             Read in data                                %
                0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                0039 
                0040 % Load grid information.
c578fd6b1e Dani*0041 if ~isequal(dat,'Gra')
e5f86a2f55 Dani*0042     [nc,dim,XC,XG,YC,YG,ZC,ZF,RAC,drC,drF,HFacC,...
c578fd6b1e Dani*0043      HFacW,HFacS,dxG,dyG,dxC,dyC,AngleCS,AngleSN] = ...
                0044         GraphixLoadGridData(LoadGridData,grd,gdf,flu,GridSuffix,ZcordFile);
                0045 end
5bbd0d07c9 Dani*0046 
                0047 % Load GRADS data
c578fd6b1e Dani*0048 if isequal(dat,'Gra')
5bbd0d07c9 Dani*0049     if GraphixDebug, disp(['  Debug -- Loading GRADS field.']); end
                0050     [data,xax,yax,zax,months,time,dim] = ...
c578fd6b1e Dani*0051         GraphixLoadGradsData(fil,dad,fln,GraphixDebug);
5bbd0d07c9 Dani*0052     GraphixDebug_Local(GraphixDebug,'data','load',data);
                0053     data = GraphixAverage(data,fln,avg,months,ddf,dim);
                0054     GraphixDebug_Local(GraphixDebug,'data','average',data);
                0055     [data,xax,yax,pltslc] = ...
                0056         GraphixSliceGradsData(fln,flu,slc,data,xax,yax,zax);
                0057     GraphixDebug_Local(GraphixDebug,'data','slice',data);
                0058 
                0059 % Load monitor data -- can be cleaned up.
ec0c7036df Dani*0060 elseif isequal(dat,'Mon')
5bbd0d07c9 Dani*0061     [data,time] = ...
                0062         GraphixLoadMonitor(fln,fil,dad,itr,tst,SecPerYear,GraphixDebug);
                0063     xax = time; yax = NaN; pltslc = 'timfld';
                0064 
                0065 % Load meridional overturning.
                0066 elseif ismember(fln,{'Bol','Psi','Res'})
                0067     if isequal(flu,'A'),     delM = - 1000*drF ./ g;
                0068     elseif isequal(flu,'O'), delM = drF;             end
                0069     if ismember(fln,{'Psi','Res'})
                0070         if isequal(ddf,'MDS')
c578fd6b1e Dani*0071             U = LocalLoad([dad,'/',uFld],uFld,itr,ddf,nc,DataIn);
                0072             V = LocalLoad([dad,'/',vFld],vFld,itr,ddf,nc,DataIn);
5acdb7b497 Andr*0073         elseif isequal(ddf,'MNC')
c578fd6b1e Dani*0074             U = LocalLoad([dad,'/',fil],uFld,itr,ddf,nc,DataIn);
                0075             V = LocalLoad([dad,'/',fil],vFld,itr,ddf,nc,DataIn);
5bbd0d07c9 Dani*0076         end
                0077         U = GraphixAverage(U,fln,avg,months,ddf,Dim);
                0078         V = GraphixAverage(V,fln,avg,months,ddf,Dim);
                0079         [psiavg,mask,ylat]=calc_PsiCube(delM,U.*HFacW,V.*HFacS,dxG,dyG);
                0080     end
                0081     if ismember(fln,{'Bol','Res'})
                0082         try
c578fd6b1e Dani*0083             kwx = LocalLoad([dad,'/',gmfile],KwxFld,itr,ddf,nc,DataIn);
                0084             kwy = LocalLoad([dad,'/',gmfile],KwyFld,itr,ddf,nc,DataIn);
5bbd0d07c9 Dani*0085         catch
c578fd6b1e Dani*0086             kwx = LocalLoad([dad,'/GM_Kwx-T'],'',itr,'MDS',nc,DataIn);
                0087             kwy = LocalLoad([dad,'/GM_Kwy-T'],'',itr,'MDS',nc,DataIn);
5bbd0d07c9 Dani*0088         end
                0089         kwx = GraphixAverage(kwx,fln,avg,months,ddf,Dim);
                0090         kwy = GraphixAverage(kwy,fln,avg,months,ddf,Dim);
                0091         [ub,vb]=calc_Bolus_CS(RAC,dxC,dyC,dxG,dyG,drC,kwx,kwy,HFacW,HFacS);
                0092         [psibol,mask,ylat]=calc_PsiCube(delM,ub.*HFacW,vb.*HFacS,dxG,dyG);
                0093     end
                0094     if isequal(fln,'Psi')
                0095         data = psiavg(2:end-1,:)';
                0096     elseif isequal(fln,'Bol')
                0097         data = psibol(2:end-1,:)';
                0098     elseif isequal(fln,'Res')
                0099         data = psibol(2:end-1,:)' + psiavg(2:end-1,:)';
                0100     end
                0101     if isequal(flu,'A'), data = data./1e6; end
                0102     xax = ylat; yax = ZF; pltslc = 'lathgt';
                0103               
                0104 % Second moments -- This can eventually be made more elegant.
e5f86a2f55 Dani*0105 elseif ~isequal(SecMom,'')
4cf7d6e47a Dani*0106     if ismember(SecMom,{'T','Eta','W'})
e5f86a2f55 Dani*0107         if isequal(SecMom,'Eta')
                0108             data  = LocalLoad([dad,'/',fil],EtaFld ,itr,ddf,nc,DataIn)./100  ;
                0109             data2 = LocalLoad([dad,'/',fil],Eta2Fld,itr,ddf,nc,DataIn)./10000;
                0110         elseif ismember(SecMom,{'T','ActT'})
                0111             data  = LocalLoad([dad,'/',fil],TFld ,itr,ddf,nc,DataIn);
                0112             data2 = LocalLoad([dad,'/',fil],T2Fld,itr,ddf,nc,DataIn);
4cf7d6e47a Dani*0113         elseif isequal(SecMom,'W')
                0114             data  = LocalLoad([dad,'/',fil],WFld ,itr,ddf,nc,DataIn);
                0115             data2 = LocalLoad([dad,'/',fil],W2Fld,itr,ddf,nc,DataIn);
e5f86a2f55 Dani*0116         end
                0117         data  = GraphixAverage(data ,fln,avg,months,ddf,Dim);
                0118         data2 = GraphixAverage(data2,fln,avg,months,ddf,Dim);
                0119         data = data2-data.^2;
                0120         if isequal(ThetaToActT,1)
                0121             pres = NaN.*zeros(size(data));
                0122             for iz=1:length(ZC), pres(:,:,iz)=ZC(iz); end
                0123             Exner = (pres./presrefA).^(RdA/cpA);
                0124             data=data.*Exner.^2;
                0125         end
                0126     elseif isequal(SecMom,'KE')
                0127         U  = LocalLoad([dad,'/',fil],uFld ,itr,ddf,nc,DataIn);
                0128         V  = LocalLoad([dad,'/',fil],vFld ,itr,ddf,nc,DataIn);
                0129         UU = LocalLoad([dad,'/',fil],u2Fld,itr,ddf,nc,DataIn);
                0130         VV = LocalLoad([dad,'/',fil],v2Fld,itr,ddf,nc,DataIn);
                0131         U  = GraphixAverage(U ,fln,avg,months,ddf,Dim);
                0132         V  = GraphixAverage(V ,fln,avg,months,ddf,Dim);
                0133         UU = GraphixAverage(UU,fln,avg,months,ddf,Dim);
                0134         VV = GraphixAverage(VV,fln,avg,months,ddf,Dim);
                0135         u_dim = size(U); nz=prod(u_dim(3:end));
                0136         U  = reshape(U ,[6*nc nc nz]); V  = reshape(V ,[6*nc nc nz]);
                0137         UU = reshape(UU,[6*nc nc nz]); VV = reshape(VV,[6*nc nc nz]);
                0138         [U_spl ,V_spl ] = split_UV_cub(U ,V );
                0139         [UU_spl,VV_spl] = split_UV_cub(UU,VV);
                0140         U_spl  = reshape(U_spl ,[nc+1 nc nz 6]);
                0141         V_spl  = reshape(V_spl ,[nc nc+1 nz 6]);
                0142         UU_spl = reshape(UU_spl,[nc+1 nc nz 6]);
                0143         VV_spl = reshape(VV_spl,[nc nc+1 nz 6]);
                0144         U_spl  = (U_spl(1:nc,:,:,:)  +  U_spl(2:nc+1,:,:,:))./2;
                0145         V_spl  = (V_spl(:,1:nc,:,:)  +  V_spl(:,2:nc+1,:,:))./2;   
                0146         UU_spl = (UU_spl(1:nc,:,:,:) + UU_spl(2:nc+1,:,:,:))./2;
                0147         VV_spl = (VV_spl(:,1:nc,:,:) + VV_spl(:,2:nc+1,:,:))./2;
                0148         U  = reshape(permute(U_spl ,[1 4 2 3]),[6*nc nc nz]);
                0149         V  = reshape(permute(V_spl ,[1 4 2 3]),[6*nc nc nz]);
                0150         UU = reshape(permute(UU_spl,[1 4 2 3]),[6*nc nc nz]);
                0151         VV = reshape(permute(VV_spl,[1 4 2 3]),[6*nc nc nz]);
                0152         data = sqrt((UU + VV)-(U.*U + V.*V));
5bbd0d07c9 Dani*0153     end
                0154     [data,xax,yax,pltslc] = ...
e5f86a2f55 Dani*0155         GraphixSlice(data,fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,avg,...
                0156                      slc,pst,Dim,LoadGridData,GridSuffix,ZcordFile,...
                0157                      Vector,PlotFld,XL,YL);
c578fd6b1e Dani*0158 
5bbd0d07c9 Dani*0159 
                0160 % General reader.
                0161 else
                0162     if isequal(Vector,0)
                0163         if isempty(Index)
                0164             if     isequal(ddf,'MNC'), Index = {'+',fln};
                0165             elseif isequal(ddf,'MDS'), Index = {'+', ''}; end
                0166         end
                0167         for ii = 1:2:length(Index)
                0168             if isequal(ddf,'MNC')
c578fd6b1e Dani*0169                 d = LocalLoad([dad,'/',fil],Index{ii+1},itr,ddf,nc,DataIn);
5bbd0d07c9 Dani*0170             elseif isequal(ddf,'MDS')
c578fd6b1e Dani*0171                 d = LocalLoad([dad,'/',fil],fln,itr,ddf,nc,DataIn);
5bbd0d07c9 Dani*0172                 if ~isequal(Index{ii+1},'')
                0173                     if     isequal(Dim,2)
                0174                         d=squeeze(d(:,:,Index{ii+1},:));            
                0175                     elseif isequal(Dim,3)
                0176                         d=squeeze(d(:,:,:,Index{ii+1},:));
                0177                     end
                0178                 end
                0179             end
                0180             if ii == 1, eval(['data = '     ,Index{ii},' d;']);
                0181             else,       eval(['data = data ',Index{ii},' d;']); end
4cf7d6e47a Dani*0182             data(data==1e15)=0; % Set no values to zeros.
5bbd0d07c9 Dani*0183         end
                0184         GraphixDebug_Local(GraphixDebug,'data','load',data);
                0185         data = GraphixAverage(data,fln,avg,months,ddf,Dim);
                0186         GraphixDebug_Local(GraphixDebug,'data','average',data);
                0187         if ThetaToActT | ThetaToThetaEc
                0188             pres = NaN.*zeros(size(data));
                0189             for iz=1:length(ZC), pres(:,:,iz)=ZC(iz); end
                0190             temp=data.*(pres./presrefA).^(RdA/cpA);
                0191             data=temp;
                0192         end
                0193         if ThetaToThetaEc
                0194                 es=A_CC.*exp(Beta_CC.*(temp-K2C));
                0195             qstar=(RdA/RvA).*(es./pres);
                0196             data=theta.*exp(LHvapA.*qstar./cpA./temp);
                0197         end
                0198     elseif ~isempty(find([1,2]==Vector))
                0199         if isequal(ddf,'MDS')
c578fd6b1e Dani*0200             data = LocalLoad([dad,'/',fil],fln,itr,ddf,nc,DataIn);
                0201             if ~isempty(Index)
                0202                 if     isequal(Dim,2), data1 = squeeze(data(:,Index,:));
                0203                                        data2 = squeeze(data(:, Mate,:));
                0204                 elseif isequal(Dim,3), data1 = squeeze(data(:,:,Index,:));
                0205                                        data2 = squeeze(data(:,:, Mate,:));
                0206                 end
                0207             else
                0208                 data1 = data;
                0209                 data2 = LocalLoad([dad,'/',Mate],fln,itr,ddf,nc,DataIn);
                0210             end
5bbd0d07c9 Dani*0211         elseif isequal(ddf,'MNC')
c578fd6b1e Dani*0212             data1 = LocalLoad([dad,'/',fil],fln ,itr,ddf,nc,DataIn);
                0213             data2 = LocalLoad([dad,'/',fil],Mate,itr,ddf,nc,DataIn);
5bbd0d07c9 Dani*0214         end
                0215         if     isequal(Vector,1), U = data1; V = data2;
                0216         elseif isequal(Vector,2), U = data2; V = data1; end
                0217         GraphixDebug_Local(GraphixDebug,'U-dir vector','load',U);
                0218         GraphixDebug_Local(GraphixDebug,'V-dir vector','load',V);
                0219         U = GraphixAverage(U,fln,avg,months,ddf,Dim);
                0220         V = GraphixAverage(V,fln,avg,months,ddf,Dim);
                0221         GraphixDebug_Local(GraphixDebug,'U-dir vector','average',U);
                0222         GraphixDebug_Local(GraphixDebug,'V-dir vector','average',V);
ec0c7036df Dani*0223         [uE,vN] = rotate_uv2uvEN(U,V,AngleCS,AngleSN,'C');
5bbd0d07c9 Dani*0224         %[U,V]=uvcube2latlon(XC,YC,U,V,XL,YL);
                0225         if     isequal(Vector,1), data = uE;
                0226         elseif isequal(Vector,2), data = vN; end
                0227         GraphixDebug_Local(GraphixDebug,'data','vector manipulation',data);
                0228     end
c578fd6b1e Dani*0229 
5bbd0d07c9 Dani*0230     [data,xax,yax,pltslc] = ...
                0231         GraphixSlice(data,fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,avg,...
                0232                      slc,pst,Dim,LoadGridData,GridSuffix,ZcordFile,...
c578fd6b1e Dani*0233                      Vector,PlotFld,XL,YL);
5bbd0d07c9 Dani*0234     GraphixDebug_Local(GraphixDebug,'data','slice',data);
                0235     GraphixDebug_Local(GraphixDebug,'xax' ,'slice',xax);
                0236     GraphixDebug_Local(GraphixDebug,'yax' ,'slice',yax);
                0237 end
                0238 
4cf7d6e47a Dani*0239 if DevFromMean
                0240     if size(xax,1) == 1
                0241         datazon = mean(data,2);
                0242         for ii = 1:length(xax)
                0243             data(:,ii) = data(:,ii) - datazon;
                0244         end
                0245     else
                0246         error('DevFromMean for cube grid not yet implemented!');
                0247     end
                0248 end
                0249 
5bbd0d07c9 Dani*0250 %-------------------------------------------------------------------------%
                0251 %                            Local functions                              %
                0252 %-------------------------------------------------------------------------%
                0253 
                0254 % Thus is merely a local function that calls the load data functions
                0255 % according to the DataFormat for the data specified by dfm.  The (some-
                0256 % times length) load calls can be avoided by directly passing the desired
                0257 % data matrix with the 'DataIn' agruement.
                0258 function data = LocalLoad(fil,fln,itr,dfm,nc,DataIn)
                0259     if isempty(DataIn)
                0260         if isempty(dir([fil,'*'])), ls([fil,'*']); end
                0261         if isequal(dfm,'MDS'),     data = rdmds(fil,itr);
4cf7d6e47a Dani*0262         elseif isequal(dfm,'MNC'), data = rdmnc([fil,'.*'],fln,'iter',itr);
5bbd0d07c9 Dani*0263         else error(['Unrecognized data type:  ',dfm]); end
                0264     else
                0265         data = DataIn;
                0266     end
                0267     if isequal(dfm,'MNC')
                0268         eval(['data = data.',fln,';']);
                0269         data = data(1:6.*nc,1:nc,:,:);
                0270     end
4cf7d6e47a Dani*0271     
5bbd0d07c9 Dani*0272 function GraphixDebug_Local(GraphixDebug,arrayname,operation,data)
                0273         if GraphixDebug
                0274         disp(['  Debug -- ''',arrayname,''' size after',...
                0275               ' ',operation,':  ',mat2str(size(data))]);
d0f71987d2 Andr*0276     end