Home > omviz > vmean.m

vmean

PURPOSE ^

function vmean(cdfin,cdfout,tind,tout)

SYNOPSIS ^

function vmean(cdfin,cdfout,tind,tout)

DESCRIPTION ^

function vmean(cdfin,cdfout,tind,tout)

 VMEAN computes mean U,V,W over time steps TIND 
    of the model output file CDFIN, and writes the
    resulting mean fields to timestep TOUT in 
    model output file CDFIN.
  
  tind is the indices of time steps to average over (1 is first step)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vmean(cdfin,cdfout,tind,tout)
0002 %function vmean(cdfin,cdfout,tind,tout)
0003 %
0004 % VMEAN computes mean U,V,W over time steps TIND
0005 %    of the model output file CDFIN, and writes the
0006 %    resulting mean fields to timestep TOUT in
0007 %    model output file CDFIN.
0008 %
0009 %  tind is the indices of time steps to average over (1 is first step)
0010 %
0011 disp('averaging velocity')
0012 cdfid1=mexcdf('open',cdfin,'nowrite');
0013 cdfid2=mexcdf('open',cdfout,'write');
0014 
0015 [nam,nx]=mexcdf('diminq',cdfid1,'xpos');
0016 [nam,ny]=mexcdf('diminq',cdfid1,'ypos');
0017 [nam,nz]=mexcdf('diminq',cdfid1,'zpos');
0018 
0019 for j=[1:max(nz-1,1)],
0020   utot=zeros(nx,ny);
0021   vtot=zeros(nx,ny);
0022   wtot=zeros(nx,ny);
0023   ketot=zeros(nx,ny);
0024   for i=tind,
0025     u=mexcdf('varget',cdfid1,'u',[i-1 j-1 0 0],[1 1 ny nx]);
0026     utot=utot+u;
0027 
0028     v=mexcdf('varget',cdfid1,'v',[i-1 j-1 0 0],[1 1 ny nx]);
0029     vtot=vtot+v;
0030     if(nz>1)
0031       w=mexcdf('varget',cdfid1,'w',[i-1 j-1 0 0],[1 1 ny nx]);
0032       wtot=wtot+w;
0033     end
0034     ketot=ketot+(u.^2+v.^2);
0035   end
0036   umean=utot/length(tind);
0037   vmean=vtot/length(tind);
0038   wmean=wtot/length(tind);
0039   ketot=sqrt(ketot/length(tind));
0040 % store mean velocity field in time step TOUT of cdfout
0041   mexcdf('varput',cdfid2,'u',[tout-1 j-1 0 0],[1 1 ny nx],umean);
0042   mexcdf('varput',cdfid2,'v',[tout-1 j-1 0 0],[1 1 ny nx],vmean);
0043   if(nz>1)
0044     mexcdf('varput',cdfid2,'w',[tout-1 j-1 0 0],[1 1 ny nx],wmean);
0045   end
0046 end
0047 mexcdf('close',cdfid1);
0048 mexcdf('close',cdfid2);

Generated on Thu 01-Dec-2005 08:50:35 by m2html © 2003