Home > omviz > cmean.m

cmean

PURPOSE ^

function cmean(cdfin,cdfout,varin,tind,tout)

SYNOPSIS ^

function cmean(cdfin,cdfout,varin,tind,tout)

DESCRIPTION ^

function cmean(cdfin,cdfout,varin,tind,tout)

  CMEAN computes the mean field of VARIN over time steps TIND 
     of the model output file CDFIN, and writes the
     resulting mean field to timestep TOUT in 
     model output file CDFIN.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cmean(cdfin,cdfout,varin,tind,tout)
0002 %function cmean(cdfin,cdfout,varin,tind,tout)
0003 %
0004 %  CMEAN computes the mean field of VARIN over time steps TIND
0005 %     of the model output file CDFIN, and writes the
0006 %     resulting mean field 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 varout=varin;
0012 
0013 disp(['averaging ' varin ])
0014 cdfid1=mexcdf('open',cdfin,'nowrite');
0015 cdfid2=mexcdf('open',cdfout,'write');
0016 
0017 [nam,nx]=mexcdf('diminq',cdfid1,'xpos');
0018 [nam,ny]=mexcdf('diminq',cdfid1,'ypos');
0019 [nam,nz]=mexcdf('diminq',cdfid1,'zpos');
0020 
0021 for j=[1:nz-1],
0022   stot=zeros(nx,ny);
0023   for i=1:length(tind),
0024     s=mexcdf('varget',cdfid1,varin,[tind(i)-1 j-1 0 0],[1 1 ny nx]);
0025     stot=stot+s;
0026   end
0027   smean=stot/length(tind);
0028 %
0029 % store mean field in the tout time step of cdfout
0030 %
0031   mexcdf('varput',cdfid2,varout,[tout-1 j-1 0 0],[1 1 ny nx],smean);
0032 end
0033 mexcdf('close',cdfid1);
0034 mexcdf('close',cdfid2);

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