--- MITgcm_contrib/enderton/Diagnostics/DiagLoad.m 2005/03/01 20:09:11 1.7 +++ MITgcm_contrib/enderton/Diagnostics/DiagLoad.m 2005/08/10 20:00:35 1.10 @@ -1,7 +1,7 @@ function [data,xax,yax,time,pltslc] = ... DiagLoad(fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,avg,slc,pst,... - LoadGridData,DiagDebug,GridSuffix,ZcordFile,Index,Dim,... - Grads,Year0Iter,SecPerYear,Months); + LoadGridData,DiagDebug,GridSuffix,ZcordFile,Index,Dim,Vector,Mate,... + Grads,Year0Iter,SecPerYear,Months,FieldName); % Load parameters. @@ -105,10 +105,10 @@ data = DiagAverage(data,fln,avg,months,ddf,Dim); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,flu,... - ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % Load coupled fields. Like AIM, the data is all stuffed into one file -% called either 'cplFld.*' (MDS) or 'cpl_tave.*' (MNC). Variables within +% called either 'cplFldtave.*' (MDS) or 'cpl_tave.*' (MNC). Variables within % the MDS files given in 'DiagGenParam', accessed directly with MNC. TX % and TY (stress on ocean) must be converted to lat-lon grid. elseif ismember(fln,cplparameters) @@ -138,7 +138,7 @@ data = DiagAverage(data,fln,avg,months,ddf,Dim); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,flu,... - ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % Load ice parameters. Note that as the ice variable names appear to be in % constant flux, this part quickly becomes out of date. @@ -153,7 +153,7 @@ data = DiagAverage(data,fln,avg,months,ddf,Dim); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,flu,... - ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % Load generic fields where no modifications are needed. elseif ismember(fln,{'S','T','Temp','aim_RH','phiHyd','Conv'}) @@ -161,7 +161,7 @@ data = DiagAverage(data,fln,avg,months,ddf,Dim); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,... - flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % Read vertical velocities, eta. Convert from [P] to [hPa] in atmosphere. elseif ismember(fln,{'W','wVel','Eta','ETA'}) @@ -170,7 +170,7 @@ data = DiagAverage(data,fln,avg,months,ddf,Dim); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,... - flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % Load horizontal velocities, convert to lat-lon grid. elseif ismember(fln,{'U','V','uVel','vVel','fizhi_U','fizhi_V'}) @@ -189,7 +189,7 @@ V = DiagAverage(V,fln,avg,months,ddf,Dim); [XC,XG,YC,YG,Ylat,ZC,ZG,RAC,drC,drF,HFacC,HFacW,HFacS,dxG,dyG,dxC,dyC] = ... DiagLoadGridData(LoadGridData,grd,gdf,flu,GridSuffix,ZcordFile); - [U,V]=uvcube2latlon(XC,YC,U,V,XL,YL); + %[U,V]=uvcube2latlon(XC,YC,U,V,XL,YL); if ismember(fln,{'U','uVel','fizhi_U'}) data = U; elseif ismember(fln,{'V','vVel','fizhi_V'}) @@ -197,7 +197,7 @@ end [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,... - flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % Meridional overturning. elseif ismember(fln,{'Bol','Psi','Res'}) @@ -280,7 +280,7 @@ end [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,... - avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % Read in variabilities. Here we must make some simple calculations. For @@ -296,7 +296,7 @@ data = DiagAverage(data,fln,avg,months,ddf,Dim); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,... - flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); elseif isequal(fln,'Tstd') T = DiagLoad_Local('T' ,dat,dad,grd,itr,ddf,filesuffix,mnchandle); TT = DiagLoad_Local('TT',dat,dad,grd,itr,ddf,filesuffix,mnchandle); @@ -304,49 +304,102 @@ data = DiagAverage(data,fln,avg,months,ddf,Dim); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,... - flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); elseif isequal(fln,'KEpri') U = DiagLoad_Local('uVel',dat,dad,grd,itr,ddf,filesuffix,mnchandle); V = DiagLoad_Local('vVel',dat,dad,grd,itr,ddf,filesuffix,mnchandle); UU = DiagLoad_Local('UU' ,dat,dad,grd,itr,ddf,filesuffix,mnchandle); VV = DiagLoad_Local('VV' ,dat,dad,grd,itr,ddf,filesuffix,mnchandle); if isequal(ddf,'MNC') - U = .5*( U(2:end,:,:,:) + U(1:end-1,:,:,:) ); - V = .5*( V(:,2:end,:,:) + V(:,1:end-1,:,:) ); - %UU = .5*( UU(2:end,:,:,:) + UU(1:end-1,:,:,:) ); % UU and VV might be incorrect. - %VV = .5*( VV(:,2:end,:,:) + VV(:,1:end-1,:,:) ); + U = U(1:end-1,:,:,:); UU = UU(1:end-1,:,:,:); + V = V(:,1:end-1,:,:); VV = VV(:,1:end-1,:,:); end - U = DiagAverage(U,fln,avg,months,ddf,Dim); - V = DiagAverage(V,fln,avg,months,ddf,Dim); + U = DiagAverage(U ,fln,avg,months,ddf,Dim); + V = DiagAverage(V ,fln,avg,months,ddf,Dim); UU = DiagAverage(UU,fln,avg,months,ddf,Dim); VV = DiagAverage(VV,fln,avg,months,ddf,Dim); data = sqrt(abs((U.*U + V.*V) - (UU + VV))); [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,... - flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); % If the field is not recognized, try best to try and open it. else disp([' Unknown field, attempting to load.']); data = DiagLoad_Local(fln,dat,dad,grd,itr,ddf,filesuffix,mnchandle); if DiagDebug, disp([' Debug -- ''data'' size after load: ',mat2str(size(data))]); end - if ~isequal(Index,0) + if isequal(Vector,1) | isequal(Vector,2) | isequal(Vector,3) + if isequal(Vector,1) | isequal(Vector,3) + if ~isequal(Index,0) + if isequal(Dim,2), U = squeeze(data(:,:,Index,:)); + elseif isequal(Dim,3), U = squeeze(data(:,:,:,Index,:)); end + end + if ~isequal(Mate,0) + if isequal(Dim,2), V = squeeze(data(:,:,Mate,:)); + elseif isequal(Dim,3), V = squeeze(data(:,:,:,Mate,:)); end + end + elseif isequal(Vector,2) + if ~isequal(Index,0) + if isequal(Dim,2), V = squeeze(data(:,:,Index,:)); + elseif isequal(Dim,3), V = squeeze(data(:,:,:,Index,:)); end + end + if ~isequal(Mate,0) + if isequal(Dim,2), U = squeeze(data(:,:,Mate,:)); + elseif isequal(Dim,3), U = squeeze(data(:,:,:,Mate,:)); end + end + end + U = DiagAverage(U,fln,avg,months,ddf,Dim); + V = DiagAverage(V,fln,avg,months,ddf,Dim); + [XC,XG,YC,YG,Ylat,ZC,ZG,RAC,drC,drF,HFacC,HFacW,HFacS,dxG,dyG,dxC,dyC] = ... + DiagLoadGridData(LoadGridData,grd,gdf,flu,GridSuffix,ZcordFile); + if isequal(Vector,1) | isequal(Vector,2) + [U,V]=uvcube2latlon(XC,YC,U,V,XL,YL); + end + if isequal(Vector,1) + data = U; + elseif isequal(Vector,2) + data = V; + elseif isequal(Vector,3) + if isequal(flu,'A'), delM = - 1000*drF ./ g; + elseif isequal(flu,'O'), delM = drF; end + [psiavg,mskG,ylat]=calc_PsiCube(delM,U.*HFacW,V.*HFacS,dxG,dyG); + data = psiavg(2:end-1,:)'; + if isequal(flu,'A'), data = data./1e6; end + xax = ylat; yax = ZG; pltslc = 'lathgt'; + end + if DiagDebug, disp([' Debug -- ''data'' size after vector manipulation: ',mat2str(size(data))]); end + else +% Sequence here for Vector = 0 + if ~isequal(Index,0) if isequal(Dim,2), data = squeeze(data(:,:,Index,:)); elseif isequal(Dim,3), data = squeeze(data(:,:,:,Index,:)); end + end + if DiagDebug, disp([' Debug -- ''data'' size after indexing: ',mat2str(size(data))]); end + data = DiagAverage(data,fln,avg,months,ddf,Dim); +% Actual Temperature -- When the FieldName says ActT we assume that +% the field that is pointed to in Index is potential temperature + if isequal(FieldName,'ActT') + [XC,XG,YC,YG,Ylat,ZC,ZG,RAC,drC,drF,HFacC,HFacW,HFacS,dxG,dyG,dxC,dyC] = ... + DiagLoadGridData(LoadGridData,grd,gdf,flu,GridSuffix,ZcordFile); + pres = NaN.*zeros(size(data)); + for iz=1:length(ZC), pres(:,:,iz)=ZC(iz); end + temp=data.*(pres./presrefA).^(RdA/cpA); + data=temp; + end + + if DiagDebug, disp([' Debug -- ''data'' size after average: ',mat2str(size(data))]); end end - if DiagDebug, disp([' Debug -- ''data'' size after indexing: ',mat2str(size(data))]); end - data = DiagAverage(data,fln,avg,months,ddf,Dim); - if DiagDebug, disp([' Debug -- ''data'' size after average: ',mat2str(size(data))]); end + if ~isequal(Vector,3) [data,xax,yax,pltslc] = ... DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,... - flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile); + flu,ddf,gdf,avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName); if DiagDebug, disp([' Debug -- ''data'' size after slice: ',mat2str(size(data))]); end if DiagDebug, disp([' Debug -- ''xax'' size: ',mat2str(size(xax))]); end if DiagDebug, disp([' Debug -- ''yax'' size: ',mat2str(size(yax))]); end if DiagDebug, disp([' Debug -- ''pltslc'': ',pltslc]); end + end end - %-------------------------------------------------------------------------% % Local functions % %-------------------------------------------------------------------------% @@ -354,16 +407,11 @@ % Thus is merely a local function that calls the load data functions % according to the DataFormat for the data specified by dfm. function data = DiagLoad_Local(fln,dat,dad,grd,itr,dfm,filesuffix,mnchandle) - if isequal(dfm,'MDS') data = rdmds([dad,'/',fln,filesuffix],itr); elseif isequal(dfm,'MNC') - iter = rdmnc_mod([dad,mnchandle],'T'); - iter = iter.T; - [dummy,indecies] = ismember(itr,iter); - data = rdmnc_mod([dad,mnchandle],[fln,filesuffix],'T',indecies); - iter = data.T; - if ~isequal(itr,iter'), error('Missing iterations in data!'); end + data = rdmnc_mod2([dad,mnchandle],[fln,filesuffix],'iter','T',itr); + if ~isequal(itr,data.iter'), error('Missing iterations in data!'); end eval(['data = data.',fln,filesuffix,';']); else error(['Unrecognized data type: ',dfm]);