% routine to plot VPR section from "edt"
% two options for input data dealt with differently
% (Note: the 2nd option simple reformat to .data form for 
% hsec or versec to handle)

%wform=menu('What form is your data?','Galleger edt','Davis edt.mat');
wform=2;

if wform==1;
  load /data5/jmanning/ctd/vpr/en268v9.edt
  d=en268v9;
  [r,c]=size(d)
  inc=10;
 
  % make hours
  x=d(1:inc:r,1)+d(1:inc:r,2)/60+(d(1:inc:r,3)/60)/60;

  % make depth negative
  y=-1*d(1:inc:r,4);
  z=d(1:inc:r,7);

  % choose gridopts
  zto=.5;
  xysc=[.25 5];
  gd=4;

  [zi,xi,yi]=gridopts(x,y,z,gd,[zto],[xysc]);

  v=[32:.05:33];
  econtour(xi,yi,zi,v,'label','fill');

elseif wform==2;
  % load data
  load /data5/jmanning/vpr/vpr56edt

  % to reformat to a ".data" file we need to:
  % a) calculate x & y relative to Boston
  % b) calculate a "profile number 

  % a) calculate x & y relative to Boston
  lat=b(:,2);lon=-b(:,3);
  disp('click "existing lat/lon & dist to Boston"');
  disp('Calculating Distance from Boston...');
  ll2xy;

  % b) calculate a "profile number"
  % try calculating a diff(sign(diff(b(:,4)));
  disp('Calculating profile id  (ie cast number)...');
  kk=1;
  for k=1:length(b)-2;
    if diff(sign(diff([b(k,4) b(k+1,4);b(k+1,4) b(k+2,4)])))==2;
      kk=kk+1;
    end;
    pf(k)=kk;
  end;
  pf(length(b)-1)=k;
  pf(length(b))=k;

  y=[x' y'  -b(:,4) b(:,1) b(:,5) b(:,6) b(:,7) ...
      0.1*ones(length(b),1) b(:,2) -b(:,3) pf'];
  save /data5/jmanning/ctd/data/vpr56edt.data y -ascii
  return
end;
