function cdmean(cdfin,cdfout,tind)
%function cdmean(cdfin,cdfout,tind)
%
% CDMEAN computes mean,max,min of drag coefficent over time steps tind 
%    of a ecomsi model run.  cdfin is the ecomsi.cdf run, and
%    cdfout is a dummy ecomsi.cdf run that has at least three time
%    steps of varout that you don't mind writing over.  The mean value
%    is stored in the first time step, max in the 2nd time step, and
%    min in the 3rd time step 
%     
%  tind is the indices of time steps to average over (1 is first step)
% 
  varin='cd';
  varout='cd';
cdfid1=mexcdf('open',cdfin,'nowrite');
cdfid2=mexcdf('open',cdfout,'write');

[nam,nx]=mexcdf('diminq',cdfid1,'xpos');
[nam,ny]=mexcdf('diminq',cdfid1,'ypos');
[nam,nz]=mexcdf('diminq',cdfid1,'zpos');

  stot=zeros(nx,ny);
  smax=zeros(nx,ny);
  smin=32*ones(nx,ny);
  for i=tind,
    s=mexcdf('varget',cdfid1,varin,[i-1 0 0],[1 ny nx]);
    smax=max(s,smax);
    smin=min(s,smin);
    stot=stot+s;
  end
  smean=stot/length(tind);
% store mean salinity field in 1st time step of cdfout
  mexcdf('varput',cdfid2,varout,[0  0 0],[1  ny nx],smean);
% store max  salinity field in 2nd time step of cdfout
  mexcdf('varput',cdfid2,varout,[1  0 0],[1  ny nx],smax);
% store min  salinity field in 3rd time step of cdfout
  mexcdf('varput',cdfid2,varout,[2  0 0],[1  ny nx],smin);
mexcdf('close',cdfid1);
mexcdf('close',cdfid2);
