mocsy  2.0
Fortran 95 routines to model ocean carbonate system thermodynamics
 All Classes Namespaces Files Functions Variables Pages
The mocsy Fortran code

The fortran code for mocsy is available as a series of Fortran 95 routines: vars.f90, constants.f90, depth2press.f90, f2pCO2.f90, gasx.f90, p2fCO2.f90, p80.f90, phsolvers.f90, rho.f90, rhoinsitu.f90 , sw_adtg.f90, sw_ptmp.f90, sw_temp.f90, test_mocsy.f90, tis.f90, tpot.f90, and varsolver.f90. Most users will simply call vars.f90, which calls other routines. Extensive documentation and the code listing for each of these routines is accessible by clicking on their links above.

Download it

If git software is installed, the most recent version of the mocsy package can be downloaded using typical git commands. Go to a directory under which you want install a new subdirectory mocsy containing the code. Then type

$ git clone git://github.com/jamesorr/mocsy.git

Otherwise, just go to the main web page on github https://github.com/jamesorr/mocsy and click on the link "Download ZIP".

Compile it

Once the download is complete, compile the code in the normal fashion by issuing the following command:

$ make test_mocsy

If successful, you will have just produced an executable test_mocsy. Otherwise, if the gfortran (alias f95) compiler is not installed on your system, install it or try another one that is already installed. So far, mocsy has been tested and run successfully with two compilers: gfortran and ifort. To change the compiler name, edit the makefile and change "f95" to your Fortran 95 compiler command. Then issue the following 2 commands:

$ make clean
$ make test_mocsy

Run test program

To run the test program, simply execute it as

$ ./test_mocsy

Output

If successful, 2 tables will be printed to your screen, as below:

Table 1: Typical MODEL output
---------------------------------------------------------------------------------------------------------
                                                                               in situ         in situ
  pH     pCO2   fCO2     CO2*       HCO3-       CO32-      OmegaA OmegaC  R    Density Press  Temperature
(total) (uatm) (uatm)  (mol/m3)    (mol/m3)    (mol/m3)                        (kg/m3) (db)      (C)
---------------------------------------------------------------------------------------------------------
 8.0592  374.9  373.3  0.2234E-01  0.2086E+01  0.1061E+00   1.55   2.47  14.45 1027.97    0.0   2.000
 8.0169  652.3  423.3  0.2201E-01  0.2089E+01  0.1038E+00   1.24   1.95  14.51 1032.68 1012.2   2.062
 7.9741 1139.4  481.4  0.2172E-01  0.2091E+01  0.1015E+00   1.00   1.55  14.56 1037.30 2029.1   2.142
 7.9308 1997.5  549.1  0.2146E-01  0.2094E+01  0.9926E-01   0.81   1.24  14.61 1041.83 3050.6   2.240
 7.8872 3513.6  627.9  0.2124E-01  0.2096E+01  0.9712E-01   0.66   0.99  14.66 1046.28 4076.9   2.354
 7.8431 6199.0  720.0  0.2105E-01  0.2098E+01  0.9505E-01   0.54   0.80  14.70 1050.65 5108.0   2.483
---------------------------------------------------------------------------------------------------------
Table 2: Typical DATA output
---------------------------------------------------------------------------------------------------------
                                                                               in situ         in situ
  pH     pCO2   fCO2     CO2*       HCO3-       CO32-      OmegaA OmegaC  R    Density Press  Temperature
(total) (uatm) (uatm)  (mol/kg)    (mol/kg)     (mol/kg)                       (kg/m3) (db)      (C)
---------------------------------------------------------------------------------------------------------
 8.0546  382.8  381.1  0.2219E-04  0.2028E-02  0.1042E-03   1.57   2.49  14.38 1027.97    0.0   2.000
 8.0146  661.8  431.5  0.2182E-04  0.2030E-02  0.1021E-03   1.27   1.99  14.45 1032.63 1000.0   2.000
 7.9746 1145.7  489.3  0.2148E-04  0.2033E-02  0.9998E-04   1.03   1.59  14.51 1037.19 2000.0   2.000
 7.9345 1986.2  555.5  0.2117E-04  0.2035E-02  0.9797E-04   0.84   1.28  14.57 1041.65 3000.0   2.000
 7.8944 3448.2  631.4  0.2090E-04  0.2037E-02  0.9602E-04   0.69   1.04  14.62 1046.02 4000.0   2.000
 7.8544 5994.4  718.7  0.2066E-04  0.2039E-02  0.9414E-04   0.56   0.84  14.68 1050.29 5000.0   2.000
---------------------------------------------------------------------------------------------------------
*Table 2 differs slightly from Table 1 because input DIC, Alk, pressure, and temperature differ.
*Concentration units differ between Tables 1 and 2 because input options differ

Comparison of the 2 tables reveal in part differences due to avoiding the 3 approximations that are commonly used in model calculations of the ocean carbonate system. For details on the specific options, see the program test_mocsy.f90 as well as the documentation of routines under the "Files" tab.

Calling the main routine

In a standard Fortran 95 program, mocsy's routine that computes all carbonate system variables by calling the vars routine

call vars(ph, pco2, fco2, co2, hco3, co3, OmegaA, OmegaC, BetaD, rhoSW, p, tempis,                  &  ! OUTPUT
          temp, sal, alk, dic, sil, phos, Patm, depth, lat, N,                                      &  ! INPUT
          optCON='mol/m3', optT='Tpot', optP='m', optB='u74', optK1K2='l', optKf='dg', optGAS='Ppot')  ! INPUT OPTIONS

where arguments on the 1st line are output variables, those on the 2nd line are input variables, and those on the 3rd line are input options. Extensive documentation on the arguments, units, and options, is accessible by clicking on the "Data Types List" tab and then on "mvars" (the module that contains the vars routine). The options above would be the common choice for typical ocean models (see also test_mocsy.f90 for typical options used with observations.

Other mocsy routines are available, for example to get the entire set of equilibrium constants (constants.f90), to convert between potential and in-situ temperature (tpot.f90 and tis.f90) , to convert between depth and pressure (depth2press.f90), to compute in situ density (rhoinsitu.f90), to convert between fCO2 and pCO2 (f2pCO2.f90 and p2fCO2.f90), and to compute atmospheric pCO2 and xCO2 as well as air-sea CO2 fluxes (gasx.f90)

The mocsy Fortran 95 routines can also be called from python as described in the next section.