% plotdat_chl.m - to plot cast data - Chlorophyll and Temperature
% this one for EDDIES 07/05 OC415-2
% use for sampling casts with full downcast at begninning

printit=1;

set(0,'defaultaxesfontname','timesroman')
set(0,'defaultaxesfontsize',12)
% keep list of starting points for CTD downcast
% cast   1    2     3    4    5   6    7  8    9    10   11    12  13
st_ind=[1060 1683 4483 3062 2589 817 1238 862 1184 1205 2415 2758 ...
	1702 2459 1 1195 1 554];
% sample tow
st_ind=[nan nan 46];

mat_path = '/mnt/oc415-2a/oc415_2/sled/';

%cast = input('Enter cast number: ');

mint=18;maxth=30;
minchl=0;maxchl=1.28;
%minsig=23;maxsig=26.5;

if cast <10
  fn = ['SAM_00',int2str(cast)];
elseif cast <100
  fn = ['SAM_00',int2str(cast)];
end
%fn = ['cast0',int2str(cast)];
%dirstr = ['Down  ';'Up    '];

%for ii = 1:size(dirstr,1),
%  eval(['load ',mat_path,fn,'_',lower(dirstr(ii,:))])
  eval(['load ',mat_path,fn,'_down'])

  %readhdr

  % compute quantities
  theta0=theta;
    time=yearday;
  if floor(yearday(1)) == 207
    dstr='Jul 27 2005';
  elseif floor(yearday(1)) == 208
    dstr='Jul 28 2005';
  elseif floor(yearday(1)) == 209
    dstr='Jul 29 2005';
  elseif floor(yearday(1)) == 210
    dstr='Jul 30 2005';
  end
  hr = floor((yearday(1)-floor(yearday(1)))*24);
  minit = (((yearday(1)-floor(yearday(1)))*24)-hr)*60;
  timestr=sprintf('%2d%2d',hr,floor(minit));
  
  % initial plot of pressure vs time
  if 0
    figure
    plot(scan,press)                    
    set(gca,'ydir','reverse')
    orient landscape
    wysiwyg
    xlabel('Scan')
    ylabel('Pressure (db)')
    %title(['Cast: ',fn,' - ',dirstr(ii,:),' cast'])
    title(['Cast: ',fn])
    ax = axis;
    axis([scan(1) scan(length(scan)) -1 1010])
  end
  % this plots all 3 quantites on one plot
  figure(cast)
  clf
  %hold off
  bb = find(max(press) == press);
  bb = st_ind(cast):bb(1);

  cc=find(press(bb)>0 & sal0(bb)>20 & theta0(bb)>5);
  bb=bb(cc);
  
  if 1
    lim600 = 0;
    if lim600
      aa = find(press(bb) >200 & press(bb) <= 600);
    else
      aa = find(press(bb) >0 & press(bb) <= 200);
    end
    myax = 1;
    %miny = 200;
    miny = 0;
    if lim600
      maxy = 600;
    else
      maxy = 200;
    end
  else
    myax=0;
    aa=1:length(bb);
  end
  
  ntics = 10;
  ax1 = axes('Position',[.13 .11 .7750 .775]);
  h1 = line(temp0(bb(aa)),press(bb(aa)));
  set(ax1,'ydir','reverse')
  if myax
    axlim = axis;
    axis([axlim(1:2) miny maxy])
  end
  %axis([mint maxt miny maxy])
  grid
  xlabel(['Temperature (',setstr(176),' C) (-)'])
  ylabel('Pressure (db)')
  %title(['Cast: ',fn,' - ',dirstr(ii,:),' cast'])
  %keyboard
  hold on
  ax2 = axes('Position',get(ax1,'Position'),'xaxislocation','top', ...
	     'color','none','ydir','reverse');
  h2 = line(fl(bb(aa)),press(bb(aa)),'linestyle','--','parent',ax2);  
  if myax
    axlim = axis;
    axis([axlim(1:2) miny maxy])
  end
  %axis([minchl maxchl miny maxy])
  xlabel('Chlorophyll ug/l (- - -)')
  %title(['Cast: ',fn,' - ',dirstr(ii,:),' cast ',Lat,' ',Lon,' ', ...
	% date,' ',time])
   title(['Cast: ',fn,'  ',num2str(lat(1)),' N ',int2str(lon(1)),' W ', ...
	  dstr,' ',timestr],'interpreter','none')
  box on
  xlimits = get(ax1,'XLim');
  xinc = (xlimits(2)-xlimits(1))/ntics;
  set(ax1,'XTick',[xlimits(1):xinc:xlimits(2)])
  x2limits = get(ax2,'XLim');
  xinc = (x2limits(2)-x2limits(1))/ntics;
  set(ax2,'XTick',[x2limits(1):xinc:x2limits(2)])

  if 0
    ax3 = axes('Position',get(ax1,'Position'),'visible','off', ...
	     'color','none','ydir','reverse');
    h3 = line(sigma0(bb(aa)),press(bb(aa)), ...
	    'linestyle','-.','parent',ax3);
    if myax
      axlim = axis;
      axis([axlim(1:2) miny maxy])
    end
    axis([minsig maxsig miny maxy])
    ax3lim = get(ax3,'XLim');
    xinc = (ax3lim(2)-ax3lim(1))/ntics;
    set(ax3,'XTick',[ax3lim(1):xinc:ax3lim(2)])
    axpos = get(ax1,'Position');
    ax4 = axes('position',[axpos(1) .05 axpos(3) .005]);
    set(ax4,'xlim',ax3lim)
    set(ax4,'XTick',[ax3lim(1):xinc:ax3lim(2)],'yticklabel',[])
    txl=xlabel('Sigma (kg/m^3) ( _ . _ . _ )');
    set(txl,'interpreter','none')
  end
  orient tall
  wysiwyg
%end

if printit
  print('-dpng',['SAM_00',int2str(cast),'_down_chl']);
  %print -Poceanpr2
end
