
% use this routine once the file(s) are in "mtl" format (i.e.columns)
% (sometimes requires running "nodc2mtl" or "prs2mtl" etc.)

load header.dat
h=header;
clear header;
mm=h(:,3);
dd=h(:,4)'
hh=h(:,5);
mm=h(:,6)'

wo=menu('What output?','Normal','with x & y (kms)','both');
%open File loop
for i=1:length(h);
  eval(['load sbe',num2str(h(i,2),'.mtl']);
  eval(['d=sbe',num2str(h(i,2),'(:,1)']);
  eval(['t=sbe',num2str(h(i,2),'(:,2)']);
  eval(['s=sbe',num2str(h(i,2),'(:,3)']);
  yd=julian(mm(i),dd(i),95,hh(i)*100+mm(i));
  ydv=yd*ones(length(d),1);
  [lat,lon]=ddmm2dec(h(i,8),h(i,9);
  latv=lat*ones(length(d),1);
  lonv=lon*ones(length(d),1);
  wdep=h(i,9)*ones(length(d),1);
  sta=h(i,2)*ones(length(d),1)

% write out to file
  if wo==1;
    y=[latv lonv d t s sta wdep]
  elseif wo==2;
    y=[latv lonv]
  end;
  fploopy(y,'big.dat');
end;

% Now convert lat/lon to x & y with Fortran routine
if wo==2;
  !/home3/ocn/jmanning/model/d3/ll2xy.exe

% load x & y conversion
  load out.dat
  x=out(:,1);
  y=out(:,2);

% generate a density vector
  path(path,'/home3/ocn/jmanning/m/seawater')
  dens=sw_dens(s,t,d)-1000;

% write out results
  y2=[x y d yd t s dens 0.1*ones(length(t),1) latv lonv ];
  path(path,'/home3/ocn/jmanning/m')
  fploopy(y2);
end;