


DEPmax computes the depth-maxraged value of a 4D variable at
a given time step of a ECOM model run.
Usage: [cmax,x,y]=depmax(cdf,var,[tstep],[bounds])
where: cdf = ecomsi.cdf run
var = variable to depth-maxrage
tstep = time step (default = 1)
bounds = [imin imax jmin jmax] limits
(default = [1 nx 1 ny])
cmax = depth-maxraged quantity
x = x locations of the returned array cmax
y = y locations of the returned array cmax
Example 1: [smax,x,y]=depmax('ecomsi.cdf','salt');
computes the depth-maxraged salinity at the 1st time step
over the entire domain.
Example 2: [smax,x,y]=depmax('ecomsi.cdf','salt',10);
computes the depth-maxraged salinity at the 10th time step
over the entire domain.
Example 3: [smax,x,y]=depmax('ecomsi.cdf','salt',10,[10 30 30 50]);
computes the depth-maxraged salinity at the 10th time step
in the subdomain defined by i=10:30 and j=30:50.

0001 function [cmax,x,y]=depmax(cdfin,varin,tind,bounds) 0002 % DEPmax computes the depth-maxraged value of a 4D variable at 0003 % a given time step of a ECOM model run. 0004 % 0005 % Usage: [cmax,x,y]=depmax(cdf,var,[tstep],[bounds]) 0006 % 0007 % where: cdf = ecomsi.cdf run 0008 % var = variable to depth-maxrage 0009 % tstep = time step (default = 1) 0010 % bounds = [imin imax jmin jmax] limits 0011 % (default = [1 nx 1 ny]) 0012 % 0013 % cmax = depth-maxraged quantity 0014 % x = x locations of the returned array cmax 0015 % y = y locations of the returned array cmax 0016 % 0017 % Example 1: [smax,x,y]=depmax('ecomsi.cdf','salt'); 0018 % 0019 % computes the depth-maxraged salinity at the 1st time step 0020 % over the entire domain. 0021 % 0022 % Example 2: [smax,x,y]=depmax('ecomsi.cdf','salt',10); 0023 % 0024 % computes the depth-maxraged salinity at the 10th time step 0025 % over the entire domain. 0026 % 0027 % Example 3: [smax,x,y]=depmax('ecomsi.cdf','salt',10,[10 30 30 50]); 0028 % 0029 % computes the depth-maxraged salinity at the 10th time step 0030 % in the subdomain defined by i=10:30 and j=30:50. 0031 0032 if(nargin==2), 0033 tind=1; 0034 end 0035 % suppress netcdf warnings 0036 mexcdf('setopts', 0); 0037 % 0038 cdfid1=mexcdf('open',cdfin,'nowrite'); 0039 if(cdfid1==-1), 0040 disp(['file ' cdf ' not found']) 0041 return 0042 end 0043 [nam,nxr]=mexcdf('diminq',cdfid1,'xpos'); 0044 [nam,nyr]=mexcdf('diminq',cdfid1,'ypos'); 0045 [nam,nz]=mexcdf('diminq',cdfid1,'zpos'); 0046 if(nargin< 4), 0047 ix=0; 0048 iy=0; 0049 nx=nxr; 0050 ny=nyr; 0051 else 0052 if(bounds(2)>nxr|bounds(4)>nyr),disp('out of bounds'),return,end 0053 ix=bounds(1)-1; 0054 nx=bounds(2)-bounds(1)+1; 0055 iy=bounds(3)-1; 0056 ny=bounds(4)-bounds(3)+1; 0057 end 0058 depth=mexcdf('varget',cdfid1,'depth',[iy ix],[ny nx]); 0059 x=mexcdf('varget',cdfid1,'x',[iy ix],[ny nx]); 0060 y=mexcdf('varget',cdfid1,'y',[iy ix],[ny nx]); 0061 sigma=mexcdf('varget',cdfid1,'sigma',[0],[nz]); 0062 dsigma=-diff(sigma); 0063 h1=mexcdf('varget',cdfid1,'h1',[iy ix],[ny nx]); 0064 h2=mexcdf('varget',cdfid1,'h2',[iy ix],[ny nx]); 0065 area=h1.*h2; 0066 cmax=-1e16*ones(nx,ny); 0067 for j=[1:nz-1], 0068 c=mexcdf('varget',cdfid1,varin,[tind-1 j-1 iy ix],[1 1 ny nx],1); %get a layer 0069 cmax=max(cmax,c); 0070 end 0071 mexcdf('close',cdfid1); 0072 dind=find(depth==-99999 | depth==0); 0073 cmax(dind)=cmax(dind)*NaN; 0074