
% StbdEndDate=StbdSlopes(:,6);
% figure;plot(diff(datenum(StbdInsertDate), StbdEndDate);

% PortEndDate=PortSlopes(1:end-1,6);
% figure;plot(PortSlopes(1:end-1,6),(PortEndDate-datenum(PortInsertDate)));
% datetick('x','mmmyyyy','keepticks','keeplimits');

% OptodeDates=datestr(PortSlopes(1:end-1,6));

% PortInsertDepth=data;
% PortInsertDate=datenum(textdata(3:end,1));
% save('PortInsertData.mat', 'PortInsertDate','PortInsertDepth');

% StbdInsertDepth=data;
% StbdInsertDate=datenum(textdata(3:end,1));
% save('StbdInsertData.mat', 'StbdInsertDate','StbdInsertDepth');

fid = fopen('StbdTimeStamps.txt','wt');
for i=1:size(StbdSlopes,1),
fprintf(fid,'%s\t %s\n',datestr(StbdSlopes(i,5)),datestr(StbdInsertDate(i)));
end
fclose(fid);

StbdCmbrVol= 10210+StbdInsertDepth*pi*(diameter/2)^2; %in cm^3
plot(StbdSlopes(:,5),StbdCmbrVol(1:size(StbdSlopes,1))/1000,'x');
hold on; plot(StbdSlopes(:,5), 10.21*ones(size(StbdSlopes,1)),'r');
datetick('x','mmmyyyy','keepticks','keeplimits');
xlabel('Date');ylabel('Stbd Chamber Vol (Liters)');

%%%%%%%%%%%o2 consumber per chamber
%slope (umol/hr)*experiment durations (hr)/initial conc (umol)*100
StbdPrctConsumed=zeros((size(StbdSlopes,1)),1);
for i= 1: size(StbdSlopes,1),
    StbdPrctConsumed(i)=(StbdSlopes(i,1).*StbdSlopes(i,9)/StbdSlopes(i,3))*100;
end
figure;
plot(StbdSlopes(:,5),StbdPrctConsumed,'x');
xlabel('Date');ylabel('%Consumed per chamber');
datetick('x','mmmyyyy','keepticks','keeplimits');

% %%%%%%%%%O2 Consumed per meter of sea floor per hour
% %%%%% = slope (umol./hr)* area of chamber (cm^2) *10,000 cm^2/1m^2 =
% %%%%% umol/hr*m^2
% StbdConPerSqrMtr = (StbdSlopes(:,1)/(pi*(diameter/2)^2))*10000;
% %%%%%   mmol/m^2day
% StbdConPerSqrMtrPerDay = StbdConPerSqrMtr*24/1000;
% StbdOrCa = StbdConPerSqrMtrPerDay/0.0959;

figure;
plot(PortSlopes(:,5),PortSlopes(:,8),'bx');
hold on;
plot(StbdSlopes(:,5),StbdSlopes(:,8),'rx');
datetick('x','mmmyyyy','keepticks','keeplimits')
legend('Port','Stbd')
xlabel('Date');ylabel('Experiment Duration (Hrs)');
saveas(gcf,strcat('Duration_Port_Stbd','.tiff'));

figure
plot(StbdSlopes(:,5),(StbdSlopes(:,4)-StbdSlopes(:,3))/(mean(StbdSlopes(:,8))),'gx');hold on;

plot(StbdSlopes(:,5),StbdSlopes(:,1),'rx');
datetick('x','mmmyyyy','keepticks','keeplimits')
legend('Port','Stbd')
xlabel('Date');ylabel('Slope (um/hr)');


figure;
hist(StbdSlopes(:,8));
xlabel('Hour Drift Began');ylabel('Frequency');
saveas(gcf,strcat('StbdDrift_Hist','.tiff'));

figure;
plot(StbdSlopes(:,10)-StbdSlopes(:,1),'bo');

figure; plot(PortSlopes(:,1),StbdSlopes(:,1),'x')
hold on;plot([-1 0],[ -1 0],'r--');
xlabel('Port Slope (umol/hr)');ylabel('Stbd Slope (umol/hr)');
axis([-1 0 -1 0]);

%%%%%%%%%%% O2 consumed per chamber
%%%%%%%%%%% slope (umol/hr)*experiment durations (hr)/initial conc (umol)*100
StbdPrctConsumed=zeros((size(StbdSlopes,1)),1);
for i= 1: size(StbdSlopes,1),
    StbdPrctConsumed(i)=(StbdSlopes(i,1).*StbdSlopes(i,9)/StbdSlopes(i,3))*-100;
end

PortPrctConsumed=zeros((size(PortSlopes,1)),1);
for i= 1: size(PortSlopes,1),
    PortPrctConsumed(i)=(PortSlopes(i,1).*PortSlopes(i,8)/PortSlopes(i,3))*-100;
end

figure;
plot(StbdSlopes(:,5),StbdPrctConsumed,'rx');
hold on;
plot(PortSlopes(:,5),PortPrctConsumed,'bx');
legend('Stbd','Port');
xlabel('Date');ylabel('%Consumed per chamber');
datetick('x','mmmyyyy','keepticks','keeplimits');
saveas(gcf,strcat('PercentConsumed','.tiff'));

% PortSlopes=ones(size(l,1)-1,8);
% StbdSlopes=ones(size(l,1)-1,8);
% for i=1:size(l,1)-1
%     load(l(i+1).name);
%     PortSlopes(i,:)=PortLinFit;
%    
%     
% end
% 
% for i=1:size(l,1)-1
%     load(l(i+1).name);
%     StbdSlopes(i,:)=StbdLinFit;
%     
% end
StbdConPerSqrMtr = (StbdSlopes(:,1)/(pi*(diameter/2)^2))/10000;

% convert from umol to mmol -> divide by 1000
% convert from hour to day -> multiply by 24
%%%%%   mmol/m^2day
StbdConPerSqrMtrPerDay = StbdConPerSqrMtr*24/1000;

%%%%%%%% mgC/m^2day

StbdOrCa = StbdConPerSqrMtrPerDay/0.0959;


PortConPerSqrMtr = (PortSlopes(:,1)/(pi*(diameter/2)^2))/10000;

% convert from umol to mmol -> divide by 1000
% convert from hour to day -> multiply by 24
%%%%%   mmol/m^2day

PortConPerSqrMtrPerDay = PortConPerSqrMtr*24/1000;

%%%%%%%% mgC/m^2day
PortOrCa = PortConPerSqrMtrPerDay/0.0959;



%   csvwrite('PortSlopes.csv',PortSlopes)