% For WHOI WHP CTD format
% Set the following for the station range desired
jsta = 4:5;
ndepth = 2750;
ctd_template = '/home/ulua/science/kn9412/ctd/prs/ka45d%03d.prs';
station_file_dir = '/home/ulua/science/kn9412/ladcp/proc/';

eval(['load ' station_file_dir 'stations.asc']);
[ss, xx, yy] = sta_xy(stations);

nsta = length(jsta);
T = NaN * zeros(ndepth,nsta);
S = T;
p =  ((1:ndepth) - 1) * 2;
x = zeros(nsta, 1);
y = x;

for ii = 1:nsta
   sta = jsta(ii);
   ixy = find(ss == sta);
   if length(ixy) ~= 1
      disp(['Warning: missing or duplicate lat lon at station ' sta])
   else
      x(ii) = xx(ixy);
      y(ii) = yy(ixy);
   end
   [pp, TT, SS] = read_prs(sprintf(ctd_template, sta));
   T(:,ii) = pad(TT, ndepth);
   S(:,ii) = pad(SS, ndepth);
end

eval(['save ' sprintf('ts%.0f_%.0f', jsta(1), jsta(nsta))...
  ' T S p x y jsta nsta ndepth']);

