function [u,jd,z]=tslice(cdf,var,xpos,ypos,zpos)
%
%  TSLICE  returns a timeseries of a scalar variable at
%          a i,j,[k] location from ECOMSI.CDF files
%    USAGE:
%    1. if the variable is a function of x, y and time: (e.g. elevation), do:
%       [u,t]=tslice(cdf,var,i,j);
%
%    2. if the variable is a function of x, y, z and time: (e.g. salinity), do:
%       [u,t]=tslice(cdf,var,i,j,k);
%

% rsignell@crusty.er.usgs.gov (Richard P. Signell) 1-21-93
%
if (nargin<4 | nargin>5),
  help tslice; return
end
[name, nt]=mcdinq(cdf,'time');
if nargin==4,
  u=mcvgt(cdf,var, [0, ypos-1, xpos-1],[nt 1 1]);
elseif nargin==5,
  depth=mcvgt(cdf,'depth',[ypos-1 xpos-1],[1 1]);
  sigma=mcvgt(cdf,'sigma');
  if(zpos==-1),
     u=mcvgt(cdf,var,[0 0, ypos-1, xpos-1],[nt -1 1 1]);
     [m,n]=size(u);
     u(:,n)=[];
     z=depth*sigma;
     z(n)=[];
  else
     u=mcvgt(cdf,var,[0 zpos-1, ypos-1, xpos-1],[nt 1 1 1]);
     z=depth*sigma(zpos);
  end
end
base=mcagt(cdf,'global','base_date');
jd0=julian([base 0 0 0]);
jd=mcvgt(cdf,'time',[0],[nt])+jd0;
