%extract_prof.m
clear;
dd = '2020Oct12';
sn = 'BOG2'
mpath = sprintf( '../../%s/%s/parsed',sn,dd);
fpmat = sprintf('%s/CPF%s.mat',mpath,dd);
load(fpmat);
%load(path);

j=1;
for dive=1:1:size(P,1) %for each dive
    if ~isnan(P(dive,1)) %found a prof
        
        %do ctd first
        i=1;
        while ~isnan(P(dive,i))
            pressure(j,i)=P(dive,i);
            TEMP(j,i)=T(dive,i);
            PSAL(j,i)=S(dive,i);
            CTDtime(j,i)=CPtime(dive);
            i=i+1;
        end
        
        %do Fluorometer next
        i=1;
        while ~isnan(FLd(dive,i))
            FLBBpressure(j,i)=FLd(dive,i);
            FLBB(j,i)=FL(dive,i);
            FLBBtime(j,i)=FLtime(dive,i);
            i=i+1;
        end
        
        %do O2 next
        i=1;
        while ~isnan(FLd(dive,i))
            O2pressure(j,i)=O2d(dive,i);
            O2v(j,i)=O2(dive,i);
            O2t(j,i)=O2time(dive,i);
            i=i+1;
        end 
        j=j+1;
    end
end %end for each dive

clear('O2','O2time');
O2=O2v;
O2time = O2t;

fpout = sprintf('%s/CPF%s_PROF.mat',mpath,dd);
save(fpout,'pressure','TEMP','PSAL','CTDtime',...
    'FLBBpressure','FLBB','FLBBtime',...
    'O2pressure','O2','O2time')