%bellows position summary bellows.m
clear;
fp = '2016Sep23';
path = sprintf( '../%s/parsed/CPF%s_ENG.mat',fp,fp);
load(path,'BP','P','DATETIMENUM','BATTI','SEDTRAP');

numprofiles = size(P,1);
figure(1);hold on;
figure(2); hold on;
j=1;
k=1;
l=1;

for prof = 1:numprofiles
    
    for i = 1:1:size(BP,2)
       if(~isnan(BP(prof,i)))
           bp(j) = BP(prof,i);
           bpt(j) = DATETIMENUM(prof,i);
           j=j+1;
       end
       if(~isnan(P(prof,i)))
           p(k) = P(prof,i);
           pt(k) = DATETIMENUM(prof,i);
           k=k+1;
       end   
       if(~isnan(BATTI(prof,i)))
           batti(l) = BATTI(prof,i);
           battit(l) = DATETIMENUM(prof,i);
           l=l+1;
       end 
    end
    j=1;
    k=1;
    l=1;
    figure(1);
    subplot(2,1,1);hold on;
    if (exist('pt'))
        s = plot( pt,p);
    end
    
    if (exist('SEDTRAP'))
        for m = 1:1:size(SEDTRAP(prof).sedhome,2)
            plot(SEDTRAP(prof).sedhome(m),SEDTRAP(prof).homep(m),'gx');
        end
    
        for m = 1:1:size(SEDTRAP(prof).sedadv,2)
            plot(SEDTRAP(prof).sedadv(m),SEDTRAP(prof).advp(m),'o',...
                'MarkerEdgeColor','k','MarkerFaceColor','y',...
                'MarkerSize',10);
        end 
      
        subplot(2,1,2);hold on;
        plot( bpt,bp,'Color',get(s,'Color'));
    
    end
 
    
    figure(2);
    subplot(2,1,1);hold on;
    if (exist('pt'))
        s = plot( pt,p);
    end
    subplot(2,1,2);hold on;
    plot( battit,batti,'Color',get(s,'Color'));   
    clear('bpt','bp','pt','p','batti','battit');
end

figure(1)
subplot(2,1,1)
title(fp);
datetick
grid on;
ylabel('dbar')
subplot(2,1,2)
datetick;
grid on;
ylabel('Bellows position (mm)');


figure(2)
subplot(2,1,1)
title(fp);
datetick
grid on;
ylabel('dbar')
subplot(2,1,2)
datetick;
grid on;
ylabel('Batt bus current (amps)')

% x = [2539 2539];
% y = [-300 60];
% 
% plot(x,y,'--');
% 
% x = [2637 2637]
% plot(x,y,'--');
% 
% axis([1500 2750 -255 60]);
