% GETCTD.M
% Loads all the CTD data from a cruise into 2D arrays
%
% 2. Requires metcdf.mex, mcvgt.m
%
% Rich Signell               |  rsignell@crusty.er.usgs.gov
% U.S. Geological Survey     |  (508) 457-2229  |  FAX (508) 457-2310
% Quissett Campus            | 
% Woods Hole, MA  02543      |
%--------------------------------------------------------------------

% the coastline file is hard-wired (mat file containing the variable 'coast')
load mbay_coast
 
pointer=input('Input CTD pointer file name (i.e. mb01.dat): ','s');
command=['! sed -f $HOME/m/ctdscript.m ' pointer ' > tmpctd.m'];
eval(command)
eval('tmpctd')
[m,n]=size(sta);
mexcdf('setopts',0);
for j=1:m
  cdfid=mexcdf('open',sta(j,:),'nowrite');
  lat(j)=mexcdf('varget1',cdfid,'latitude',0);
  lon(j)=-(mexcdf('varget1',cdfid,'longitude',0));
  [name,depthlen(j)] = mexcdf('DIMINQ', cdfid, 'depth');
  rcode=mexcdf('close',cdfid);
end
maxd=max(depthlen);
salt=NaN*ones(maxd,m);
temp=NaN*ones(maxd,m);
dens=NaN*ones(maxd,m);
depth=NaN*ones(maxd,m);
for j=1:m
  cdf=sta(j,:);
  tmp=mcvgt(cdf,'depth');
  depth([1:length(tmp)],j)=tmp(:);
  tmp=mcvgt(cdf,'T_20');
  temp([1:length(tmp)],j)=tmp(:);
  tmp=mcvgt(cdf,'S_41');
  salt([1:length(tmp)],j)=tmp(:);
  tmp=mcvgt(cdf,'ST_70');
  dens([1:length(tmp)],j)=tmp(:);
end
