% this one generates sig and plots it also
% temperature sensors: 10983 10984 10986 11177
% pressure sensors: 9791 9792

load cal_tpods

if sam == 1
  % for deployment 1 - hardwired start time 8/30(yd=241) 2300Z
  st_time=241+23/24;
  dt=5/60/60/24;
  % position on wire 
  h11177 = -28;
  h10986 = -16;
  % sled at 0
  h10983 = 16;% above sled
  h9792  = 20; 
  h9791 = 28;
  h10984 = 33;
  tow_start = 242.0414;
  tow_end = 242.5280;
elseif sam == 2
  % for deployment 2 - hardwired start time 8/31(yd=242) 2300Z
  st_time=242+23/24;
  dt=5/60/60/24;
  % height:
  h11177 = -30;
  h10986 = -15;
  % sled at 0
  h10983 = 15;
  h9792  = 20;
  h10984 = 30;
  h9791  = 35;
  tow_start = 243.0413;
  tow_end = 243.5064;
elseif sam == 3
  % for deployment 3 - hardwired start time 9/1(yd=243) 1900Z
  st_time=243+19/24;
  dt=5/60/60/24;
  % height:
  h11177 = -30;
  h10984 = -15;
  % sled at 0
  h10983 = 15;
  h9792  = 20;
  h10986 = 30;
  h9791  = 35;
  tow_start = 244.0420;
  tow_end = 244.5012;
elseif sam == 4
  % for deployment 4 - hardwired start time 9/2(yd=244) 1900Z
  st_time=244+19/24;
  dt=5/60/60/24;
  % height:
  h11177 = -30;
  h10986 = -15;
  % sled at 0
  h10983 = 15;
  h9791  = 20;
  h10984 = 30;
  h9792  = 35;
  tow_start = 245.0417;
  tow_end = 245.5004;
elseif sam == 5
  % this is the calibration cast
  % for deployment 5 - hardwired start time 9/3(yd=245) 1900Z
  st_time=245+19/24;
  dt=5/60/60/24;
  % height:
  h11177 = 0;
  h10986 = 0;
  % sled at 0
  h10983 = 0;
  h9791  = 0;
  h10984 = 0;
  h9792  = 0;
  tow_start = 245.8440;
  tow_end = 245.8819;
  sam=6
elseif sam == 6
  % for deployment 6 - hardwired start time 9/3(yd=245) 1900Z
  st_time=245+19/24;
  dt=5/60/60/24;
  % height:
  h11177 = -15;
  h10986 = -30;
  % sled at 0
  h10983 = 30;
  h9792  = 20;
  h10984 = 15;
  h9791  = 35;
  tow_start = 245.9987;
  tow_end = 246.4701;
  
elseif sam == 7
  % for deployment 7 - hardwired start time 9/4(yd=246) 2300Z
  st_time=246+23/24;
  dt=5/60/60/24;
  % height:
  h11177 = -30;
  h10986 = -15;
  % sled at 0
  h10983 = 15;
  h9792  = 20;
  h10984 = 30;
  h9791  = 35;
  tow_start = 247.0450;
  tow_end = 247.50;
  
elseif sam == 8
  % for deployment 8 - hardwired start time 9/5(yd=247) 2300Z
  st_time=247+23/24;
  dt=5/60/60/24;
  % height:
  h11177 = -14;
  h10986 = -29;
  % sled at 0
  h10983 = 30;
  h9792  = 20;
  h10984 = 15;
  h9791  = 35;
  tow_start = 248.0218;
  tow_end = 248.4787;
  
elseif sam == 9
  % for deployment 9 - hardwired start time 9/7(yd=249) 2300Z
  st_time=249+23/24;
  dt=5/60/60/24;
  % height:
  h11177 = -27;
  h10986 = -15;
  % sled at 0
  h10983 = 30;
  h9792  = 26;
  h10984 = 15;
  h9791  = 20;
  tow_start = 250.1003;
  tow_end = 250.5638;
  
elseif sam == 10
  % for deployment 10 - hardwired start time 9/8(yd=250) 2300Z
  st_time=250+23/24;
  dt=5/60/60/24;
  % height:
  h11177 = -15;
  h10986 = -30;
  % sled at 0
  h10983 = 15;
  h9792  = 35;
  h10984 = 30;
  h9791  = 20;
  tow_start = 251.0066;
  tow_end = 251.5036;
elseif sam == 11
  % for deployment 11 - hardwired start time 9/9(yd=251) 2300Z
  st_time=251+23/24;
  dt=5/60/60/24;
  % height:
  h11177 = -30;
  h10986 = -15;
  % sled at 0
  h10983 = 30;
  h9792  = 20;
  h10984 = 15;
  h9791  = 35;
  tow_start = 252.0004;
  tow_end = 252.5012;
  
elseif sam == 13
  % for deployment 13 - hardwired start time 9/10(yd=252) 2300Z
  pst_time=252+18.5/24;
  st_time=252+23/24;
  dt=5/60/60/24;
  % height:
  h11177 = -30;
  h10986 = -15;
  % sled at 0
  h10983 = 15;
  h9792  = 35;
  h10984 = 30;
  h9791  = 20;
  tow_start = 253.0362;
  tow_end = 253.5237;
  
else
  error('fill in values for this cast')
  keyboard
end

figure(1)
clf
clear h
%%%%%%%%%%%%%%%
% RBR DR-1050  3.50 009791
% get start time and interval

% this produces a vector of data
eval(['!tail +15 s',int2str(sam),'_009791.dat >xxx'])
load xxx
ttt=[0:length(xxx)-1]*dt+pst_time;

pr9791=xxx;
ti9791=ttt;


eval(['save s',int2str(sam),'_009791 pr9791 ti9791 h9791'])  

aa=find(ttt >= tow_start & ttt <= tow_end);
h(1)=plot(ttt(aa),xxx(aa),'b');
h1_str=['9791 ',num2str(h9791),'m'];
hold on

%%%%%%%%%%%%%%%
% RBR DR-1050  3.50 009792 
% get start time and interval

% this produces a vector of data
eval(['!tail +15 s',int2str(sam),'_009792.dat >xxx'])
load xxx
ttt=[0:length(xxx)-1]*dt+pst_time;

pr9792=xxx;
ti9792=ttt;
eval(['save s',int2str(sam),'_009792 pr9792 ti9792 h9792'])

aa=find(ttt >= tow_start & ttt <= tow_end);
h(2)=plot(ttt(aa),xxx(aa),'g');

h2_str=['9792 ',num2str(h9792),'m'];

% CTD
if sam < 10
  eval(['load ../sled/SAM_00',int2str(sam),'_fl'])
else
  eval(['load ../sled/SAM_0',int2str(sam),'_fl'])
end
bb=find(sampl==1);
h(3)=plot(yearday(bb),press(bb),'m');
s_str='sled at 0m';

ax=axis;
axis([tow_start tow_end ax(3:4)])

%legend(h,h1_str,h2_str,s_str)

xlabel('Yearday 2005')
ylabel('Pressure (dbar)')
title(['RBR DR-1050 data from Sample Tow: ',int2str(sam)])
axis ij

orient portrait
eval(['print -dpng sam',int2str(sam),'_p'])
orient landscape

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Temp.
figure(2)
clf
clear h

%%%%%%%%%%%%%%%

% RBR TR-1050  3.50 010983 (Windows: 5.14)
% get start time and interval

% this produces a vector of data
eval(['!tail +15 s',int2str(sam),'_010983.dat >xxx'])
load xxx
ttt=[0:length(xxx)-1]*dt+st_time;

te10983=xxx;
ti10983=ttt;

aa=find(ttt >= tow_start & ttt <= tow_end);
sig10983(aa) = get_sig_tpod(te10983(aa),10983);
eval(['save s',int2str(sam),'_010983 te10983 ti10983 h10983 sig10983'])

h(1)=plot(ttt(aa),xxx(aa)+cal_10983,'b');
h1_str=['10983 ',num2str(h10983),'m'];

hold on

%%%%%%%%%%%%%%%
% RBR TR-1050  3.50 010984
% get start time and interval

% this produces a vector of data
eval(['!tail +15 s',int2str(sam),'_010984.dat >xxx'])
load xxx
ttt=[0:length(xxx)-1]*dt+st_time;

te10984=xxx;
ti10984=ttt;
aa=find(ttt >= tow_start & ttt <= tow_end);
sig10984(aa) = get_sig_tpod(te10984(aa),10984);
eval(['save s',int2str(sam),'_010984 te10984 ti10984 h10984 sig10984'])

h(2)=plot(ttt(aa),xxx(aa)+cal_10984,'g');
h2_str=['10984 ',num2str(h10984),'m'];

%%%%%%%%%%%%%%%
% RBR TR-1050  3.50 010986
% get start time and interval

% this produces a vector of data
eval(['!tail +15 s',int2str(sam),'_010986.dat >xxx'])
load xxx
ttt=[0:length(xxx)-1]*dt+st_time;

te10986=xxx;
ti10986=ttt;
aa=find(ttt >= tow_start & ttt <= tow_end);
sig10986(aa) = get_sig_tpod(te10986(aa),10986);
eval(['save s',int2str(sam),'_010986 te10986 ti10986 h10986 sig10986'])

h(3)=plot(ttt(aa),xxx(aa)+cal_10986,'r');
h3_str=['10986 ',num2str(h10986),'m'];

%%%%%%%%%%%%%%%
% RBR TR-1050  3.50 011177
% get start time and interval

% this produces a vector of data
eval(['!tail +15 s',int2str(sam),'_011177.dat >xxx'])
load xxx
ttt=[0:length(xxx)-1]*dt+st_time;

te11177=xxx;
ti11177=ttt;
aa=find(ttt >= tow_start & ttt <= tow_end);
sig11177(aa) = get_sig_tpod(te11177(aa),11177);
eval(['save s',int2str(sam),'_011177 te11177 ti11177 h11177 sig11177'])

h(4)=plot(ttt(aa),xxx(aa)+cal_11177,'c');
h4_str=['11177 ',int2str(h11177),'m'];

% CTD
h(5)=plot(yearday(bb),temp0(bb),'m');
s_str='sled at 0m';
ax=axis;
axis([tow_start tow_end ax(3:4)])

legend(h,h1_str,h2_str,s_str)

legend(h,'10983','10984','10986','11177')
s_str='sled at 0m';
legend(h,h1_str,h2_str,h3_str,h4_str,s_str)

xlabel('Yearday 2005')
ylabel('Temperature (^oC)')
title(['RBR-TR-1050 data (CORRECTED) from Sample Tow: ',int2str(sam)])

if sam == 4
  ax=axis;
  axis([ax(1:2)  18.9 22.5])  
end

orient portrait
eval(['print -dpng sam',int2str(sam),'_t'])
orient landscape
