function [u,z,jd]=ecomprof(cdf,var,i,j,iind);
% ECOMPROF extracts a profile from a 4D netCDF ECOM output file.
%
%   USAGE:  [u,z,jd]=ecomprof(cdf,var,i,j,tind]);
%
% cdf = cdf file e.g. 'ecomsi.cdf'
% var = variable to select , eg. 'temp'
% (i,j) = station location in grid coordinates
% iind = time index 
%
% u = matrix of variable 'var' with dimensions depth and time
% z = depth vector 
% jd = time vector  (digital Julian day)

% Rich Signell (rsignell@usgs.gov)

ncid=mexcdf('open',cdf,'nowrite');

[nam,nz]=mexcdf('diminq',ncid,'zpos');
[nam,nt]=mexcdf('diminq',ncid,'time');
istart=iind+1);
icount=1;
sigma=mexcdf('varget',ncid,'sigma',0,nz);
sigma=.5*(sigma(1:(nz-1))+sigma(2:nz));
depth=mexcdf('varget',ncid,'depth',[j-1 i-1],[1 1]);
z=depth*sigma;

base_date=[0 0 0 0 0 0];
base_date(1:3)=mexcdf('attget',ncid,'global','base_date');
t=mexcdf('varget',ncid,'time',istart,icount);
jd0=julian(base_date);
jd=jd0+t;

u=mexcdf('varget',ncid,var,[istart 0 j-1 i-1],[icount nz-1 1 1],1);
mexcdf('close',ncid);
