Skip to content

Visual Basic

MATLAB Scripts

Visual Basic for oceanographic calculations

 

Please note: These files are in text format. To use with Excel® you will need to change the filename extension from txt to bas. Then they can be loaded as modules in the Visual Basic Editor. Use the ALT-F11 key to start the Visual Basic Editor followed by CTRL-M to import the file into the worksheet.

 

VB-scripts adapted from the MATLAB® scripts that I have written:

FUNCTION NAMETEXT FILENAMECALCULATION
AOUAOU.txtAOU from observed O2 conc vs the expected O2 conc from Weiss (1970)
DENSATPSTP2Dens.txtCalculate the in situ density of seawater as a function of S, T & P (Millero & Poisson, 1981)
DENSITYSwDensity.txtCalculate the density of seawater as a function of S & T at Pabs = 1 atm (Millero & Poisson, 1981)
N2SATN2sat_v1.txtN2 saturation as a function of S, & T from Weiss (1970)
N2SAT_V2N2sat_v2.txtN2 saturation as a function of S, & T from Hamme & Emerson (2004)
O2SAT_V2AO2sat_v2a.txtO2 saturation as a function of S, & T according to Garcia & Gordon (1992) in units of ml O2/L of seawater
O2SAT_V2BO2sat_v2b.txtO2 saturation as a function of S, & T according to Garcia & Gordon (1992) in units of umol O2/kg of seawater
SALCond2Sal.txtCalculate Salinity (pss-78) of seawater from Conductivity (S/m), T & P (UNESCO, 1983)
SBESbeC2Sal.txtCalculate Salinity (pss-78) of seawater from Conductivity (mS/cm), T & P (UNESCO, 1983)
VapPressVapPress.txtCalculate the fugacity coefficient of CO2 in seawater (Weiss & Price, 1980)
 

 

VB-scripts adapted from the MATLAB® scripts that I have collected and modified/optimized for use on a PC:  (see note #1 below)

FUNCTION NAMETEXT FILENAMECALCULATION
ADIABATAdiabat.txtComputes the adiabatic temperature gradient.
DEPTHPLat2Dep.txtDepth given the pressure at some latitude.
POTENTMPPotentmp.txtPotential temperature from in-situ measurements. Requires adiabat.
PRESSDLat2Prs.txtPressure given the depth at some latitude.
SndspdSndspd.txtVelocity of sound in seawater according to Mackenzie (1981).
SW_svelSW_svel.txtVelocity of sound in seawater according to UNESCO (1983).

 

VB-scripts for CO2 systems: (see note #2 below)

FUNCTION NAMETEXT FILENAMECALCULATION
CO2Ast_TCO2Ast_total.txtCalculate CO2(aq) + H2CO3 as a function of S, T, P, TP, TSi, TAlk & TCO2.
CO3_TCO3_total.txtCalculate CO3= as a function of S, T, P, TP, TSi, TAlk & TCO2.
fCO2_TfCO2_total.txtCalculate fCO2 as a function of S, T, P, TP, TSi, TAlk & TCO2.
HCO3_THCO3_total.txtCalculate HCO3– as a function of S, T, P, TP, TSi, TAlk & TCO2.
pH_nbs2swspH_nbs2sws.txtConvert pH on the NBS scale to pH on the Seawater scale
pH_nbs2totalpH_nbs2total.txtConvert pH on the NBS scale to pH on the Total scale
pH_TpH_total.txtCalculate pH on the Total scale as a function of S, T, P, TP, TSi, TAlk & TCO2.
pH_total2nbspH_total2nbs.txtConvert pH on the Total scale to pH on the NBS scale
pH_nbs2swspH_nbs2sws.txtConvert pH on the Total scale to pH on the Seawater scale
phi_CO2phi_CO2.txtCalculate the fugacity coefficient of CO2 in seawater according to Kortzinger (1999)

 

Notes:

  1. These algorithms were originally part of the oceanography toolbox [v1.4] compiled by R. Pawlowicz @ WHOI.
  2. This code was adapted from the work of others: CO2SYS.exe was originally written by Ernie Lewis and Doug Wallace. It was converted to Matlab by Richard E. Zeebe & Dieter A. Wolf-Gladrow. Parts were then extracted and modified by Rachel M. Dunk. I am indebted to all of them for their initial development of this code.