function [u,y,z] =yzslice(cdf,var,time,iindex)
%  YZSLICE  returns a vertical slice along i=iindex 
%           from an ECOMSI.CDF file.
%
%     The variable must be a function of x, y, z and time: (e.g. salinity)
%       USAGE: [u,y,z]=yzslice(cdf,var,time,iindex)
%
if nargin~=4 ,
  help yzslice; return
end
mexcdf('setopts',0);
ncid=mexcdf('open',cdf,'nowrite');
[name, ny]=mexcdf('diminq',ncid,'ypos');
[name, nz]=mexcdf('diminq',ncid,'zpos');
u=mexcdf('varget',ncid,var,[(time-1) 0 1 (iindex-1)],[1 nz-1 ny-2 1],1);
if nargout>1,
  d=mexcdf('varget',ncid,'depth',[1 (iindex-1)],[ny-2 1],1);
  ind=find(d==-99999.);
  d(ind)=d(ind)*0;
  u(ind,:)=u(ind,:)*NaN;
  sigma=mexcdf('varget',ncid,'sigma',0,nz,1);
  sigma=0.5*(sigma(1:nz-1)+sigma(2:nz));
  h2=mexcdf('varget',ncid,'h2',[1 (iindex-1)],[ny-2 1],1);
  y=cumsum(h2)/1000.;
  y=y*ones(1,nz-1);
  z=d*(sigma');
end
mexcdf('close',ncid);
