%% Inputs
TempAircal = NaN; % CTD temperature reading
RelHumidity = NaN; % Relative humidity of air during calibration. 
% Assumed to be 100% or 1 during our calibration, because this instrument 
% makes accurate pressure and temperature measurements in an atmosphere 
% fully saturated with water (Bushinsky and Emerson 2013). 
O2_mL_L_aircal = NaN; % Raw SBE63 doxy sensor output
Atmpressure = NaN; % Barometer reading during calibration

%% Outputs
pH2O_100_hum = exp(52.57 - (6690.9 / (TempAircal + 273.15)) - 4.681 * log(TempAircal + 273.15));
pH2O_real = pH2O_100_hum * RelHumidity;
T_O2soly = log((298.15 - TempAircal) / (273.15 + TempAircal));
O2_soly_umol_kg = exp(5.80818 + 3.20684 * T_O2soly + 4.1189 * T_O2soly^2 + 4.93845 * T_O2soly^3 + 1.01567 * T_O2soly^4 + 1.41575 * T_O2soly^5);
Density_waterkg_L = (999.84847 + 0.06337563 * TempAircal - 0.008523829 * TempAircal^2 + 0.00006943248 * TempAircal^3 - 0.0000003821216 * TempAircal^4) / 1000;
O2_soly_uM = O2_soly_umol_kg * Density_waterkg_L;
O2raw_air_uM = O2_mL_L_aircal * 44.6596;
Gain = (O2_soly_uM * (Atmpressure - pH2O_real)) / (1013.25 - pH2O_100_hum) / O2raw_air_uM;






%% O2 gain correction
doxy = moxy ./ (s.pdens./1000) .* O2gain; % umol/kg
