% plt_flt.m - to plot flight data

set(0,'defaultaxesfontsize',12)
mat_path = './';

cast = input('Enter cast number: ');
if cast < 10
  fn = ['INJ_00',int2str(cast)];
elseif cast < 100
  fn = ['INJ_0',int2str(cast)];
else
  fn = ['INJ_',int2str(cast)];
end

blue = [.2 .2 1];
eval(['load ',mat_path,fn,'_fl'])

psf6_1 = pump_1 + p1_sf6;
psf6_2 = pump_2 + p2_sf6;
indsf6 = find(psf6_1 == 2 | psf6_2 == 2);
indnosf6 = find(psf6_1 ~= 2 & psf6_2 ~=2);

figure
%%%% SIGMA0
sigma0_sf6 = sigma0;
sigma0_sf6(indnosf6) = nan;
sigma0_nosf6 = sigma0;
sigma0_nosf6(indsf6) = nan;

subplot(5,1,1)
hold off
plot(yearday,sigma0_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,sigma0_sf6,'linewidth',.5,'color',blue)
set(gca,'ydir','reverse','xticklabel',' ')
ylabel('\sigma_\theta (kg/m^3)')
title(['Cast: ',fn,' - ','Flight',' cast'],'interpreter','none')
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(sigma0_sf6) nanmax(sigma0_sf6)])

grid

%%%% TEMPERATURE
temp0_sf6 = temp0;
temp0_sf6(indnosf6) = nan;
temp0_nosf6 = temp0;
temp0_nosf6(indsf6) = nan;

temp1_sf6 = temp1;
temp1_sf6(indnosf6) = nan;
temp1_nosf6 = temp1;
temp1_nosf6(indsf6) = nan;

mint = nanmin([temp0_sf6; temp1_sf6;]);
maxt = nanmax([temp0_sf6; temp1_sf6;]);

subplot(5,1,2)
hold off
plot(yearday,temp0_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,temp0_sf6,'linewidth',.5,'color',blue)

plot(yearday,temp1_nosf6,'linewidth',.1,'color','k')
plot(yearday,temp1_sf6,'linewidth',.5,'color',[0 .5 0])

ylabel(['Temp. (^o C)'])
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) mint maxt])
set(gca,'xticklabel',' ')
grid

%%%% SALINITY
sal0_sf6 = sal0;
sal0_sf6(indnosf6) = nan;
sal0_nosf6 = sal0;
sal0_nosf6(indsf6) = nan;

subplot(5,1,3)
hold off
plot(yearday,sal0_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,sal0_sf6,'linewidth',.5,'color',blue)
ylabel('Salinity (PSU)')
ax = axis;
set(gca,'xticklabel',' ')
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(sal0_sf6) nanmax(sal0_sf6)])
grid

%%%% PRESSURE
press_sf6 = press;
press_sf6(indnosf6) = nan;
press_nosf6 = press;
press_nosf6(indsf6) = nan;

subplot(5,1,5)
hold off
plot(yearday,press_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,press_sf6,'linewidth',.5,'color',blue)
ylabel('Pressure (db)')
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(press_sf6) nanmax(press_sf6)])
grid
set(gca,'ydir','reverse')
orient landscape
xlabel('Yearday 2005')
wysiwyg

%%%% Chlorophyll
fl_sf6 = fl;
fl_sf6(indnosf6) = nan;
fl_nosf6 = fl;
fl_nosf6(indsf6) = nan;

subplot(5,1,4)
hold off
plot(yearday,fl_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,fl_sf6,'linewidth',.5,'color',blue)
ylabel('Chlor. (\mug/l)')
ax = axis;
set(gca,'xticklabel',' ')
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(fl_sf6) nanmax(fl_sf6)])
grid
orient portrait
eval(['print -dpng ',fn,'_timeseries_fl.png'])
orient landscape
wysiwyg

%%%%%%%%%% now plot'em by themselves %%%%%%%%%%%%

%%%% sigma
figure
plot(yearday,sigma0_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,sigma0_sf6,'linewidth',.5,'color',blue)
ylabel('Sigma0 (kg/m^3)')
title(['Cast: ',fn,' - ','Flight',' cast'],'interpreter','none')
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(sigma0_sf6) nanmax(sigma0_sf6)])
grid
set(gca,'ydir','reverse')
xlabel('Yearday 2005')
title(['Cast: ',fn,' - ','Flight',' cast'],'interpreter','none')
orient portrait
eval(['print -dpng ',fn,'_timeseries_fl.png'])
orient landscape
wysiwyg

%%%%% temperature
tf = figure;
plot(yearday,temp0_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,temp0_sf6,'linewidth',.5,'color',blue)

plot(yearday,temp1_nosf6,'linewidth',.1,'color','k')
plot(yearday,temp1_sf6,'linewidth',.5,'color',[0 .5 0])

ylabel(['Temperature (^o C)'])
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) mint maxt])
grid
xlabel('Yearday 2005')
title(['Cast: ',fn,' - ','Flight',' cast'],'interpreter','none')
orient portrait
eval(['print -dpng ',fn,'_timeseries_fl.png'])
orient landscape
wysiwyg

%%%% Salinity
figure
plot(yearday,sal0_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,sal0_sf6,'linewidth',.5,'color',blue)
ylabel('Salinity (PSU)')
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(sal0_sf6) nanmax(sal0_sf6)])
grid
xlabel('Yearday 2005')
title(['Cast: ',fn,' - ','Flight',' cast'],'interpreter','none')
orient portrait
eval(['print -dpng ',fn,'_timeseries_fl.png'])
orient landscape
wysiwyg

%%%% Chlorophyll
figure
plot(yearday,fl_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,fl_sf6,'linewidth',.5,'color',blue)
ylabel('Chlorophyll (\mug/l')
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(fl_sf6) nanmax(fl_sf6)])
grid
xlabel('Yearday 2005')
title(['Cast: ',fn,' - ','Flight',' cast'],'interpreter','none')
orient portrait
eval(['print -dpng ',fn,'_timeseries_fl.png'])
orient landscape
wysiwyg

%%%% Pressure
figure
plot(yearday,press_nosf6,'linewidth',.1,'color','k')
hold on
plot(yearday,press_sf6,'linewidth',.5,'color',blue)
ylabel('Pressure (dbar)')
ax = axis;
%axis([yearday(1) yearday(length(yearday)) ax(3:4)])
axis([yearday(1) yearday(length(yearday)) ...
      nanmin(press_sf6) nanmax(press_sf6)])
grid
xlabel('Yearday 2005')
title(['Cast: ',fn,' - ','Flight',' cast'],'interpreter','none')
set(gca,'ydir','reverse')
orient portrait
eval(['print -dpng ',fn,'_timeseries_fl.png'])
orient landscape
wysiwyg

return
% old stuff below here
if cast >= 16
  figure(tf)
  sbenum = [38 40 41 42];
  
  if cast == 16
    caststr = '0201A';
  elseif cast == 17
    caststr = '0202A';
  elseif cast == 18
    caststr = '0203A';
  elseif cast == 19
    caststr = '0204A';
  elseif cast == 20
    caststr = '0205A';
  elseif cast == 21
    caststr = '0206A';
  elseif cast == 23
    caststr = '0207A';
  else
    error('no SBE data for cast > 21 yet')
  end
  for isbe = sbenum
    if 0
      eval(['!tail +26 ../../sbe39/',int2str(isbe), ...
	  '_',caststr,'.ASC > temp'])
      !trans_sbe.pl <temp > temp2
      load temp2
      data=temp2;
      t = data(:,1);
      day = data(:,2);
      mon = data(:,3);
      hour = data(:,4);
      minit = data(:,5);
      sec = data(:,6);
    
    else
      eval(['load ../../sbe39/',int2str(isbe), ...
	  '_',caststr,'.flt'])
      eval(['data = X',int2str(isbe),'_',caststr,';']);
      t = data(:,1);
      day = data(:,2);
      mon = data(:,3);
      yr = data(:,4);
      hour = data(:,5);
      minit = data(:,6);
      sec = data(:,7);
    
    end
    
    days = [31 28];
    % this is good for Feb only!
    yd = 30 + day +hour/24 + minit/24/60 + sec/24/60/60;
    
    plot(yd,t);
  end
  if cast == 16
    axis([yearday(1) yearday(length(yearday)) ...
      8.5 12])
  elseif cast == 17
    axis([yearday(1) yearday(length(yearday)) ...
      9.25 11.25])
  elseif cast == 18
    axis([yearday(1) yearday(length(yearday)) ...
      9. 11.])
  elseif cast == 19
    axis([yearday(1) yearday(length(yearday)) ...
      8.7 10.8])
  elseif cast == 20
    axis([yearday(1) yearday(length(yearday)) ...
      8.9 10.7])
  elseif cast == 21
    axis([yearday(1) yearday(length(yearday)) ...
      8.75 11])
  elseif cast == 23
    axis([yearday(1) yearday(length(yearday)) ...
      8.9 10.65])
  else
    error(['set limits for cast: ',int2str(cast)])
  end
end


