


ECOM_DEPAVEUV computes the depth-averaged value of velocity at
a given time step of a ECOM model run.
Usage: [wmean,x,y]=ecom_depaveuv(cdf,[tstep],[bounds])
where: cdf = ecomsi.cdf run
var = variable to depth-average
tstep = time step (default = 1)
bounds = [imin imax jmin jmax] limits
(default = [1 nx 1 ny])
wmean = depth-averaged velocity
x = x locations of the returned array wmean
y = y locations of the returned array wmean
Example 1: [wmean,x,y]=ecom_depave('ecomsi.cdf');
computes the depth-averaged velocity at the 1st time step
over the entire domain.
Example 2: [wmean,x,y]=ecom_depave('ecomsi.cdf',10);
computes the depth-averaged velocity at the 10th time step
over the entire domain.
Example 3: [wmean,x,y]=ecom_depave('ecomsi.cdf',10,[10 30 30 50]);
computes the depth-averaged velocity at the 10th time step
in the subdomain defined by i=10:30 and j=30:50.

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