Thursday, January 1, 2015

Seawater Oxygen saturation function for Microsoft excel

Hi all
For some time now I searched for a Microsoft oxygen saturation function with no success so I had to write one.
If you are interested, you can download the code here and paste it in a VBA Module in your workbook. Or you can just download the sample spreadsheet here:

The code:

Public Function O2Sat(ByVal T As Single, ByVal S As Single) As Single


' SW_SATO2   Satuaration of O2 in sea water
'=========================================================================
' sw_satO2 $30/12/2014 By yair Suari, Ruppin Academic Center$
'
'
' to use, Formulas>Insert Function =O2Sat(S,T,P)
'
' More:
'    Solubility of Oxygen as O2 in sea water
'
'
'   S = salinity    [psu      (PSS-78)]
'   T = temperature [degree C (IPTS-68)]
'
' Output Units:
'   O2  [µMol/l]
' After:
'    Weiss, R. F. 1970
'    "The solubility of nitrogen, oxygen and argon in water and seawater."
'    Deap-Sea Research., 1970, Vol 17, pp721-735
.
' convert to Kelvin
T = 273.15 + T

'constants for Eqn (4) of Weiss 1970

a1 = -173.4292
a2 = 249.6339
a3 = 143.3483
a4 = -21.8492
B1 = -0.033096
b2 = 0.014259
b3 = -0.0017

'Eqn (4) of Weiss 1970

lnC = A1 + a2 * (100 / T) + a3 * Log(T / 100) + a4 * (T / 100) + S * (B1 + b2 * (T/ 100) + b3 * ((T / 100) ^ 2))

c = Exp(lnC)
O2Sat = c / 22.414 * 1000

End Function



Happy new 2015
Yair

No comments:

Post a Comment