%JoulesUsedOverlay.m

clear;

load CPF29MAR16_ENG.mat

numprofiles = size(P,1);
j=2;

for prof = 2:numprofiles
    
%integrate
joules(1)=0;
joules_no_hotel(1)=0;
abst(1)=DATETIMENUM(1,1);
running_P(1)=0;

for i=2:size(P,2)
    if(~isnan(P(prof,i)))
    %seconds
    deltat=3600*(DATETIMENUM(prof,i)-DATETIMENUM(prof,(i-1)))*24;
    joules(j) = joules(j-1) + deltat*BATTV(prof,i)*BATTI(prof,i);
    joules_no_hotel(j) = joules_no_hotel(j-1) + deltat*BATTV(prof,i)*(BATTI(prof,i)-.2);
    abst(j)=DATETIMENUM(prof,i);
    running_P(j)=P(prof,i);
    j=j+1;
    end
end



end

subplot(2,1,1);
plot(abst,joules);
hold on
plot(abst,joules_no_hotel);
%axis([736418.708337 736418.735 0 37200]);
grid on;axis tight;
title('CPF deployment 29MAR16');
xlabel('time');ylabel('Joules');

subplot(2,1,2);
plot(abst,running_P);
%axis([736418.708337 736418.735 -70 0]);
xlabel('time');ylabel('dBar');axis tight;