

% test code

testdir = [cd,'/../matfiles/paragontests/2021-9-16T16-33-30/'];


matflist = dir([testdir,'*.mat']);
    matflist = {matflist(:).name};
    
    
figure_2panel();

ax(1) = nexttile;
    hold on; box on;
ax(2) = nexttile;
    hold on; box on;

% hold on; box on;

for i = 1:length(matflist)


    load([testdir,matflist{i}],'HR','LR');
    
    % calculate time elapsed 

    HR.SECS = cumsum(HR.NBIN_CTD, 'reverse');


    % interpolate time elapsed to pressure
    LR.SECS = interp1(HR.PRES, HR.SECS, LR.PRES);
        LR.SECS = LR.SECS - LR.SECS(1);% make start 0

    % LR.DOXY(1:3) = LR.DOXY(2);


    % assume bototm point is correct
    doxy = vertcat(LR.DOXY(1), LR.DOXY(1), LR.DOXY);
    tc   = vertcat(LR.TEMP(1), LR.TEMP(1), LR.TEMP);
    secs = vertcat(0, 1000, LR.SECS+2000);



    LR.DOXYcorr_100 = flipud(timecorr_optode_B14(flipud(LR.DOXY), flipud(LR.TEMP), flipud(LR.SECS), 'Aand', 100));
    LR.DOXYcorr_90 = flipud(timecorr_optode_B14(flipud(LR.DOXY), flipud(LR.TEMP), flipud(LR.SECS), 'Aand', 90));
    LR.DOXYcorr_80 = flipud(timecorr_optode_B14(flipud(LR.DOXY), flipud(LR.TEMP), flipud(LR.SECS), 'Aand', 80));
    %     
    % LR.DOXYcorr_100 = flipud(timecorr_optode_B14(flipud(doxy), flipud(tc), flipud(secs), 'Aand', 100));
    % LR.DOXYcorr_90 = flipud(timecorr_optode_B14(flipud(doxy), flipud(tc), flipud(secs), 'Aand', 90));
    % LR.DOXYcorr_80 = flipud(timecorr_optode_B14(flipud(doxy), flipud(tc), flipud(secs), 'Aand', 80));
    % 
    % LR.DOXYcorr_100 = LR.DOXYcorr_100(3:end);
    % LR.DOXYcorr_90 = LR.DOXYcorr_90(3:end);
    % LR.DOXYcorr_80 = LR.DOXYcorr_80(3:end);

%     set(ax(1));
    hold on; box on;
    % add to plot
    plot(LR.DOXY, LR.PRES, 'k.-', 'parent', ax(1));
    plot(LR.DOXYcorr_100, LR.PRES, 'r.-', 'parent', ax(1));
    dprof();
    
%     set(ax(2));
    hold on; box on;
    plot(LR.TEMP, LR.DOXY, 'ko', 'markerfacecolor', 'k', 'parent', ax(2));
    plot(LR.TEMP, LR.DOXYcorr_100, 'ko', 'markerfacecolor', 'r', 'parent', ax(2));
    
    
    
    
    clear HR LR
    
end


% % figure settings
% dprof();
% xlabel('DOXY');
% ylabel('depth');



% 
% 
% 
% figure
% hold on; box on;
% plot(LR.DOXY, LR.PRES, 'k');
% plot(LR.DOXYcorr_100, LR.PRES, 'b');
% plot(LR.DOXYcorr_90, LR.PRES, 'r');
% plot(LR.DOXYcorr_80, LR.PRES, 'g');
% dprof();
% legend('Uncorr', '100um', '90um', '80um', 'location', 'southeast');
% xlabel('DOXY');
% ylabel('PRES');



















