%% Carbon Wave Glider - Preliminary Sensitivity Calculations

%Date: 3/13/2018
%Author: A. Fassbender

%Notes: Consideration of sample volume and LICOR pCO2 range to provide some 
%design constraints

clear;close all;clc
bpath = cd('/Users/fassbender/Documents/OneDrive_MBARIalias/MATLAB/MBARI_CWG');

%% Volumes and Concentrations

%Known Quantities

%LICOR optical chamber volume: 14.5 mL
%Tubing internal diameter: 1/16 in
%DIC range: 1800-2300 (open ocean); 1600 - 2300 (coastal/estuarine) umol/kg

%sample concentration range
DIC = 1600:10:2300;%umol/kg
%sample volume range
Vs = 1:.5:10;%mL
%average seawater density
rho = .001027;%0.001027 kg/cm3
%internal volume of system that moles will be diluted into
Vol = 14.5 + 125 + ((20.*(pi.*(1/32)^2)).*16.3871);%Licor + chamber + dryer + tubing (16.3871 cubic cm/ cubic in)
%Ideal gas constant
R = 0.082057*1000;%L atm mol-1K-1 = mL atm mol-1K-1
%Assumed Sample Temp
T = 15 + 273.15;% K

figure(3);clf
col = colormap(jet(length(DIC)));
clear C_mol
for i =1:length(DIC)
    for j = 1:length(Vs)
        C_mol(i,j) = DIC(i).*(Vs(j).*rho).*10^-6;%mol
        pCO2(i,j) = ((C_mol(i,j).*R.*T)./Vol).*10^6;%uatm
    end
    figure(3);hold on
    plot(Vs,pCO2(i,:),'color',col(i,:),'linewidth',2)
    xlabel('Sample Volume mL')
    ylabel('\itp\rmCO_2 \muatm')
end
text(2,3750,'DIC range of 1600-2300 \mumol kg^{-1}')
text(2,3500,'Internal volume of ~140 mL')
text(2,3250,'Sample tempreature of 15\circC')
text(2,3000,'Seawater density of 1027 kg m^{-3}')
hc = colorbar;
set(hc,'yticklabel',1600:70:2300)
plot([1 10],[2000 2000],'-k','linewidth',2)
plot([5 5],[0 2000],'-k','linewidth',2)
box on

%Note - the gas will be dispersed in the tubing, but perhaps not evenly, so
%this may underestimate the pCO2. 

fig=gcf;
set(findall(fig,'-property','Fontname'),'Fontname','Times','fontsize',14)

set(gcf,'Units','Inches');
pos = get(gcf,'Position');
set(gcf, 'PaperPositionMode', 'auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(gcf,[bpath '/Vol_pCO2_3'],'-dpng','-r400')

%% What does this mean for stripping chamber?

%Assume all 140 mL needs to come from stripping chamber (though pumps,
%drying tube, etc. will contribute in reality). 

%Diameter = 1 in

a = pi.*(.5^2).*11*16.3871 %mL

%So, using a 1 inch diamter stripping chamber that's 11 inches long





