%JoulesUsedOverlay.m

clear;

parsed = '2017Oct11';
infile = sprintf('../%s/parsed/CPF%s_ENG.mat',parsed,parsed);


load(infile);

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

for prof = 1: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);
    running_V(j)=BATTV(prof,i);
    running_I(j)=BATTI(prof,i);
    j=j+1;
    end
end



end

subplot(3,1,1);hold on;
plot(abst,joules);
%plot(abst,joules_no_hotel);
hold on
grid on;axis tight;
outstr = sprintf('CPF Joules used %s',parsed);
title(outstr);
xlabel('time');ylabel('Joules');
datetick;

subplot(3,1,2);
plot(abst,running_I);
%axis([736418.708337 736418.735 -70 0]);
xlabel('time');ylabel('Batt I');axis tight;
datetick;grid on;
%ylim ([24 33]);


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