BOG = loadBOG;

%

BOG = BOG(BOG.DATE_TIME.Year > 2019,:);

%

BOG.sdn = datenum(BOG.DATE_TIME);

%

% calcualte carboante parameters based on CANYONB for spray gliders.

sdn = ones(size(BOG.pres,1),1) * BOG.sdn';
lon = ones(size(BOG.pres,1),1) * BOG.DEC_LONG';
lat = ones(size(BOG.pres,1),1) * BOG.DEC_LAT';


for i = 1:height(BOG)
    % use CANYONB to estimate TA, PO4, and SiOH4
    canb = CANYONB(BOG.sdn(i), BOG.DEC_LAT(i), BOG.DEC_LONG(i), BOG.pres(i), BOG.tc(i), BOG.psal(i), BOG.doxy(i), {'pH'});    
    % save canyon parameters into s
    BOG.pHin_canb(i) = canb.pH + (canb.pH*0.0404 - 0.3168); % additional correction to make it consistent to 'spec pH'
end

%

deltapH_BOG_CanB = BOG.pHin - BOG.pHin_canb;

%

clf
fig = figure;
tiledlayout(1,2)
nexttile
scatter(deltapH_BOG_CanB,BOG.DEPTH,'.')
set(gca,'YDir','reverse')
title('pHin (BOG - CanB)')
xlabel('\DeltapHin')
ylabel('depth (m)')
xline(0,'--')
grid on
nexttile
scatter(deltapH_BOG_CanB,BOG.DEPTH,'.')
set(gca,'YDir','reverse')
title('pHin (BOG - CanB)')
xlabel('\DeltapHin')
ylabel('depth (m)')
xline(0,'--')
ylim([0 300])
grid on

saveas(fig,'BOGvsCanb.png')