%Plot IB03-096

close all;
clear all;

[mode,date,hr,min,sec,depth,temp,sal,u]=textread('SOLODepth.txt','%c\t %8c\t %2c%2c%2c\t %f\t %f\t %f\t %f');
SOLOdatetime=strcat(date,',',strcat(hr,':',min,':',sec));
SOLOElapsedTime=datenum(SOLOdatetime)-datenum(SOLOdatetime(1,:));

%works for IB03-096
[Datadate,time,freq,j,returntime,ms,d,l,level]=textread('LST3Databridge_9KHz.txt','%s\t%s\t%f\t%s\t%f\t%s\t%s\t%s\t%d');
clear j d ms l v freq

datetime=strcat(Datadate,',',time);
%speed of sound calculated based on 0.44 deg C, 600m depth and salinity of
%34.668- yeilds 1460m/sec *(return time in msec)*(1sec/1000msec)/2 (because
%time is round trip)
dist=(1460.457/2000)*returntime;

%just look at max returns within the depth of the vehicle
i=find((level>=128)&(abs(dist)<650));
Dist=zeros(size(i));
Date=zeros(size(i));
Level=zeros(size(i));
for b=1:size(i,1),
     Date(b,1)=datenum(datetime(i(b,1),:));
     Dist(b,1)=dist(i(b,1));
     Level(b,1)=level(i(b,1));
end

MET=Date-Date(1);


figure;
subplot(2,2,3)
scatter(MET+0.125,Dist,Level);
ylabel('Depth (m)');
xlabel('Elapsed Time (days)');

%adjust for different time zones used in data files

subplot(2,2,4)
plotyy(MET+0.125,Dist,SOLOElapsedTime,depth.*-1);
xlabel('Elapsed Time (days)');

[Datadate,time,freq,j,returntime,ms,d,l,level]=textread('LST1_Databridge_9KHz.txt','%s\t%s\t%f\t%s\t%f\t%s\t%s\t%s\t%d');



CTD=[34.58799048,	88.433746,-0.366161905;

34.63422857,	89.584257,0.119438095;

34.75291905,	91.805085,0.422971429
];

CTDdate=datevec(CTD(:,2));
CTDdate(:,1)=[2009;2009;2009];
plot(datenum(CTDdate),CTD(:,2),'x')



% diff between
% max(abs(sal(202:end)-CTD(1)))
% 
% ans =
% 
%     0.0890
% 
% max(abs(sal(202:end)-CTD(3)))
% 
% ans =
% 
%     0.0869
