%bellows position summary bellows.m
clear;
fp = '2026MAY04';
sn = 'BOG3'
path = sprintf( '../%s/%s/parsed/CPF%s_ENG.mat',sn,fp,fp);
load(path,'BP','P','DATETIMENUM','BATTI','SEDTRAP','NUMSBDIX',...
    'BATTV','STATE');
%load(path);

numprofiles = size(P,1);
figure;hold on;
figure; hold on;
j=1;
k=1;
l=1;
%m=1;
n=1;
sampleno=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 
       if(~isnan(BATTV(prof,i)))
           battv(n) = BATTV(prof,i);
           battvt(n) = DATETIMENUM(prof,i);
           %fprintf('BATTV(%d,%d)=%f; DT(%d,%d) = %d battvt(%d)=%f\n',prof,i,...
           %    BATTV(prof,i),prof,i,DATETIMENUM(prof,i),n,battvt(n));
           n=n+1;
       end
    end
    j=1;
    k=1;
    l=1;
    n=1;
    figure(1);
    subplot(3,1,1);hold on;
    if (exist('pt'))
        figure(1);
        s = plot( pt,p);
        figure(3); hold on;
        plot( pt,p);
    end
    
    if (exist('SEDTRAP'))
        if(exist('SEDTRAP.homep'))
            figure(1);
            for m = 1:1:size(SEDTRAP(prof).sedhome,2)
                plot(SEDTRAP(prof).sedhome(m),SEDTRAP(prof).homep(m),'gx');
            end
            figure(3);
            for m = 1:1:size(SEDTRAP(prof).sedhome,2)
                plot(SEDTRAP(prof).sedhome(m),SEDTRAP(prof).homep(m),'gx');
            end
        end
        %if(exist('SEDTRAP.sedadv'))
            figure(1);
            for m = 1:1:size(SEDTRAP(prof).sedadv,2)
                if (~isnan(SEDTRAP(prof).sedadv(m)))
                    plot(SEDTRAP(prof).sedadv(m),SEDTRAP(prof).advp(m),'o',...
                      'MarkerEdgeColor','k','MarkerFaceColor','y',...
                      'MarkerSize',10);
                    if( isfield(SEDTRAP,'sedno'))
                        outstr = sprintf('%d',SEDTRAP(prof).sedno(m)-34);
                    end
                    outstr = sprintf('%d',m);
                    %sampleno = sampleno + 1;
                    %text(SEDTRAP(prof).sedadv(m),SEDTRAP(prof).advp(m)-5,outstr);
                    
                end
            end 
            figure(3);
            for m = 1:1:size(SEDTRAP(prof).sedadv,2)
                if (~isnan(SEDTRAP(prof).sedadv(m)))
                    plot(SEDTRAP(prof).sedadv(m),SEDTRAP(prof).advp(m),'o',...
                      'MarkerEdgeColor','k','MarkerFaceColor','y',...
                      'MarkerSize',10);
                    outstr = sprintf('%d',sampleno);
                    sampleno = sampleno + 1;
                    %text(SEDTRAP(prof).sedadv(m),SEDTRAP(prof).advp(m)-5,outstr);
                end
            end 
        %end
        
        figure(1);
        subplot(3,1,2);hold on;
        if(exist('bpt'))
            plot( bpt,bp,'Color',get(s,'Color'));
        end
        
        if(exist('battit'))
            subplot(3,1,3);hold on;
            plot( battit,batti,'Color',get(s,'Color'));
        end
    
    end
 
    
%     figure(2);
%     subplot(2,1,1);hold on;
%     if (exist('pt'))
%         s = plot( pt,p);
%     end
   
    
    
    figure(2);
    subplot(2,1,1);hold on;
    if (exist('pt'))
        s = plot( pt,p);
    end
    
    if (exist('battvt'))
        subplot(2,1,2);hold on;
        plot( battvt,battv,'Color',get(s,'Color'));
    end
    
    %disp(battvt);
    
    
    clear('bpt','bp','pt','p','batti','battit','battvt','battv');
    %pause;
end

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

figure(2)
subplot(2,1,1)
title(fp);
datetick
grid on;
ylabel('dbar')
subplot(2,1,2)
datetick;
grid on;
ylabel('Batt V (volts)')

figure(3)
title(fp);
datetick
grid on;
ylabel('dbar');
xlabel('Time');

