% cmp_tpod_sled - compare tpods and sled data
% temperature sensors: 10983 10984 10986 11177
% pressure sensors: 9791 9792
% Note calib was done at 190m but Ppods only measure to 100m.
%
% this one for computing relationship between sled and tpods.

load  s5_009791 
load  s5_009792
load  s5_010983 
load  s5_010984
load  s5_010986 
load  s5_011177

% sled data from this cast
load ../sled/SAM_005_fl

% time periods to compare
tp1=[245.8560 245.8583];
tp2=[245.8639 245.8663];
tp3=[245.8740 245.8765];

% shift yearday - seems to be off a little bit in time
yearday = yearday-[1e-5]*15;

% first segment
aa=find(yearday >= tp1(1) & yearday <=tp1(2));
bb=find( ti10983 >= tp1(1) & ti10983 <=tp1(2));


ms1=mean(temp0(aa));
std_s1 = std(temp0(aa));
ns1 = length(aa);

m10983_1 = mean(te10983(bb));
m10984_1 = mean(te10984(bb));
m10986_1 = mean(te10986(bb));
m11177_1 = mean(te10986(bb));
std_m10983_1 = std(te10983(bb));
std_m10984_1 = std(te10984(bb));
std_m10986_1 = std(te10986(bb));
std_m11177_1 = std(te10986(bb));
nt1=length(bb);

d1_10983 = ms1-m10983_1;
d1_10984 = ms1-m10984_1;
d1_10986 = ms1-m10986_1;
d1_11177 = ms1-m11177_1;

%%%%%%%%%%%%
% second segment
aa=find(yearday >= tp2(1) & yearday <=tp2(2));
bb=find( ti10983 >= tp2(1) & ti10983 <=tp2(2));

ms2=mean(temp0(aa));
std_s2 = std(temp0(aa));
ns2 = length(aa);

m10983_2 = mean(te10983(bb));
m10984_2 = mean(te10984(bb));
m10986_2 = mean(te10986(bb));
m11177_2 = mean(te10986(bb));
std_m10983_2 = std(te10983(bb));
std_m10984_2 = std(te10984(bb));
std_m10986_2 = std(te10986(bb));
std_m11177_2 = std(te10986(bb));
nt2=length(bb);

d2_10983 = ms2-m10983_2;
d2_10984 = ms2-m10984_2;
d2_10986 = ms2-m10986_2;
d2_11177 = ms2-m11177_2;

%%%%%%%%%%%%
% third segment
aa=find(yearday >= tp3(1) & yearday <=tp3(2));
bb=find( ti10983 >= tp3(1) & ti10983 <=tp3(2));

ms3=mean(temp0(aa));
std_s3 = std(temp0(aa));
ns3 = length(aa);

m10983_3 = mean(te10983(bb));
m10984_3 = mean(te10984(bb));
m10986_3 = mean(te10986(bb));
m11177_3 = mean(te10986(bb));
std_m10983_3 = std(te10983(bb));
std_m10984_3 = std(te10984(bb));
std_m10986_3 = std(te10986(bb));
std_m11177_3 = std(te10986(bb));
nt3=length(bb);

d3_10983 = ms3-m10983_3;
d3_10984 = ms3-m10984_3;
d3_10986 = ms3-m10986_3;
d3_11177 = ms3-m11177_3;

% mean diffs:      1      2      3
% sled - 10983 -0.0032 -0.0027 -0.0024
% sled - 10984 -0.0044 -0.0031 -0.0027
% sled - 10986 -0.0026 -0.0013 -0.0010
% sled - 11177 -0.0026 -0.0013 -0.0010 

% ignore first flat place, take mean of second 2
% all t-pods read slightly high so
% add these values to the t-pods to get corrected values:
% cal factor for sensor 10983 = -0.0026
% cal factor for sensor 10984 = -0.0029
% cal factor for sensor 10986 = -0.0011
% cal factor for sensor 11177 = -0.0011

cal_10983 = -0.0026;
cal_10984 = -0.0029;
cal_10986 = -0.0011;
cal_11177 = -0.0011;

save cal_tpods cal_10983 cal_10984 cal_10986 cal_11177 

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


 