% checkout calibration of pressure sensors
% after considering the two plots(sled-up and sled -down)
% we decided that the calibration for the DR1050's is 
% to add: -11 to the DR1050 values to generate values that can be
% compared to the sled

load s13_009792
load s13_009791

%flight
%tow_start = 252.7878;
%tow_end = 252.8210;
%load ../sled/SAM_012_fl

%down
tow_start = 252.7697;
tow_end = 252.7878;
%load ../sled/SAM_012_down
load ../sled/SAM_012_up

aa=find(ti9792 >= tow_start & ti9792 <= tow_end);
bb=find(ti9791 >= tow_start & ti9791 <= tow_end);

if 0
tp1=[252.7709 252.7715];
tp2=[252.7717 252.7725];
tp3=[252.7727 252.7734];
tp4=[252.7736 252.7743];
tp5=[252.7747 252.7751];
tp6=[252.7755 252.7761];
tp7=[252.7762 252.7769];
tp8=[252.7772 252.7777];
tp9=[252.7780 252.7786];
tp10=[252.7788 252.7793];
tp11=[252.7797 252.7805];
tp12=[252.7808 252.7813];
tp13=[252.7816 252.7822];
tp14=[252.7826 252.7830];
tp15=[252.7834 252.7839];
tp16=[252.7842 252.7848];
tp17=[252.7853 252.7856];
tp18=[252.7863 252.7868];
end

if 1
  
  tp1=[ 252.8222  252.8228];
  tp2=[  252.8231  252.8235];
  tp3=[ 252.8239  252.8243];
  tp4=[  252.8246  252.8250];
  tp5=[ 252.8253  252.8258];
  tp6=[ 252.8262  252.8267];
  tp7=[ 252.8271  252.8276];
  tp8=[ 252.8280  252.8284];
  tp9=[ 252.8287  252.8292];
  tp10=[ 252.8294  252.8298];
  tp11=[ 252.8302  252.8306];
  tp12=[ 252.8309  252.8313];
  tp13=[ 252.8316  252.8320];
  tp14=[ 252.8325  252.8328];
  tp15=[252.8331  252.8334];
  tp16=[ 252.8338  252.8342];
  tp17=[ 252.8346  252.8350];
  tp18=[252.8353  252.8357];
end


for ii = 1:18
  eval(['tp=tp',int2str(ii),';'])
  aa=find(yearday >= tp(1) & yearday <=tp(2));
  bb=find( ti9792 >= tp(1) & ti9792 <=tp(2));

  %ms1d(ii)=mean(press(aa));
  %std_s1d(ii) = std(press(aa));
  %ns1d(ii) = length(aa);
  ms1u(ii)=mean(press(aa));
  std_s1u(ii) = std(press(aa));
  ns1u(ii) = length(aa);
  
  m9791=mean(pr9791(bb));
  m9792=mean(pr9792(bb));
  std_9791=std(pr9791(bb));
  std_9792=std(pr9792(bb));
  np1=length(bb);
  
  %d9791(ii)=ms1d(ii)-m9791;
  %d9792(ii)=ms1d(ii)-m9792;
  u9791(ii)=ms1u(ii)-m9791;
  u9792(ii)=ms1u(ii)-m9792;
end
  
%plot(ms1d,d9791,'.',ms1d,d9792,'.')
plot(ms1u,u9791,'.',ms1u,u9792,'.')
xlabel('Pressure')
ylabel('Pressure difference (sled-DR1050)')
legend('9791','9792')
%title('Pressure Sensor Calibration (Downcast) (SAM012)')
title('Pressure Sensor Calibration (Upcast) (SAM012)')