Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/1_cfc1112.atm
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/1_cfc1112.atm	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/1_cfc1112.atm	(revision 7693)
@@ -0,0 +1,84 @@
+ % Atmospheric lifetimes are  44.0 for CFC-11 
+ %                       and 125.0 for CFC-12 
+ % rel=  0 
+ %        <-Northern Data-> <-Southern Data->
+ % Year    CFC-11  CFC-12    CFC-11  CFC-12 
+ %         (ppt)   (ppt)      (ppt)   (ppt)
+ 1931.50    0.00    0.00       0.00    0.00   
+ 1932.50    0.00    0.01       0.00    0.01   
+ 1933.50    0.00    0.02       0.00    0.01   
+ 1934.50    0.00    0.03       0.00    0.02   
+ 1935.50    0.00    0.04       0.00    0.03   
+ 1936.50    0.00    0.07       0.00    0.04   
+ 1937.50    0.00    0.11       0.00    0.07   
+ 1938.50    0.00    0.17       0.00    0.11   
+ 1939.50    0.01    0.25       0.00    0.17   
+ 1940.50    0.01    0.37       0.01    0.25   
+ 1941.50    0.02    0.53       0.01    0.36   
+ 1942.50    0.02    0.72       0.02    0.51   
+ 1943.50    0.03    0.94       0.02    0.69   
+ 1944.50    0.04    1.25       0.03    0.91   
+ 1945.50    0.05    1.65       0.04    1.21   
+ 1946.50    0.08    2.33       0.05    1.64   
+ 1947.50    0.14    3.42       0.08    2.33   
+ 1948.50    0.24    4.73       0.14    3.32   
+ 1949.50    0.42    6.10       0.25    4.48   
+ 1950.50    0.67    7.58       0.42    5.77   
+ 1951.50    1.02    9.23       0.66    7.19   
+ 1952.50    1.53   10.94       1.01    8.72   
+ 1953.50    2.21   12.82       1.49   10.37   
+ 1954.50    3.07   14.97       2.13   12.20   
+ 1955.50    4.11   17.40       2.93   14.25   
+ 1956.50    5.39   20.22       3.92   16.59   
+ 1957.50    6.84   23.45       5.11   19.28   
+ 1958.50    8.19   26.86       6.39   22.28   
+ 1959.50    9.47   30.58       7.63   25.52   
+ 1960.50   11.13   35.03       8.96   29.18   
+ 1961.50   13.38   40.12      10.63   33.42   
+ 1962.50   16.23   45.89      12.78   38.25   
+ 1963.50   19.72   52.66      15.47   43.80   
+ 1964.50   23.87   60.57      18.75   50.28   
+ 1965.50   28.57   69.53      22.61   57.76   
+ 1966.50   33.78   79.46      26.99   66.21   
+ 1967.50   39.63   90.60      31.91   75.67   
+ 1968.50   46.27  103.16      37.46   86.31   
+ 1969.50   53.96  117.17      43.80   98.25   
+ 1970.50   62.75  132.52      51.07  111.52   
+ 1971.50   72.36  149.00      59.27  126.02   
+ 1972.50   83.04  166.85      68.34  141.70   
+ 1973.50   95.27  186.59      78.54  158.82   
+ 1974.50  108.81  208.14      90.04  177.62   
+ 1975.50  121.86  229.37     102.29  197.54   
+ 1976.50  134.47  249.51     114.40  217.31   
+ 1977.50  146.47  268.67     126.28  236.49   
+ 1978.50  157.18  286.35     137.45  254.72   
+ 1979.50  166.67  303.74     147.60  272.00   
+ 1980.50  175.11  320.96     158.08  290.34   
+ 1981.50  182.81  337.33     166.54  306.90   
+ 1982.50  189.88  352.01     174.69  323.74   
+ 1983.50  197.72  367.69     183.03  341.15   
+ 1984.50  206.34  383.86     190.95  357.80   
+ 1985.50  216.12  401.25     200.50  376.45   
+ 1986.50  227.48  420.96     209.82  394.00   
+ 1987.50  239.67  441.49     220.60  412.82   
+ 1988.50  251.05  463.22     231.46  433.46   
+ 1989.50  257.28  481.80     240.38  452.97   
+ 1990.50  263.65  493.96     249.23  470.55   
+ 1991.50  266.33  504.64     254.53  484.07   
+ 1992.50  266.00  512.87     258.80  495.65   
+ 1993.50  267.58  520.12     260.56  504.49   
+ 1994.50  267.24  526.58     261.73  512.31   
+ 1995.50  266.38  531.59     261.29  518.39   
+ 1996.50  265.25  534.81     261.08  523.50   
+ 1997.50  263.84  537.67     260.16  528.18   
+ 1998.50  262.24  999.99     258.96  999.99   
+ 1999.50  260.72  999.99     257.75  999.99   
+ 2000.50  259.34  999.99     255.69  999.99   
+ 2001.50  257.13  999.99     253.54  999.99   
+ 2002.50  254.89  999.99     252.93  999.99   
+ 2003.50  251.89  999.99     250.62  999.99   
+ 2004.50  250.67  999.99     249.52  999.99   
+ 2005.50  249.49  999.99     247.45  999.99   
+ 2006.50  248.31  999.99     245.38  999.99
+ 2007.50  247.13  999.99     243.31  999.99
+ 2008.50  245.95  999.99     241.24  999.99
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/field_def_bgc.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/field_def_bgc.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/field_def_bgc.xml	(revision 7693)
@@ -0,0 +1,809 @@
+<!--
+<?xml version="1.0"?>
+       -->
+ 
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+   <field_definition level="1" prec="8" operation="average" enabled=".TRUE." default_value="1.e20" > <!-- time step automaticaly defined -->
+
+    <!-- 
+============================================================================================================
+                                     Biogeochemistry model variables
+============================================================================================================
+    -->
+
+      <!-- ptrc on T grid -->
+
+     <field_group id="ptrc_T" grid_ref="grid_T_3D">
+       <field id="DIC"          long_name="Dissolved inorganic Concentration"        unit="mmol/m3" />
+       <field id="DIC_E3T"      long_name="DIC * E3T"                                unit="mmol/m2" > DIC * e3t </field >
+       <field id="Alkalini"     long_name="Total Alkalinity Concentration"           unit="mmol/m3" />
+       <field id="Alkalini_E3T" long_name="Alkalini * E3T"                           unit="mmol/m2"  > Alkalini * e3t </field >
+       <field id="O2"           long_name="Oxygen Concentration"                     unit="mmol/m3" />
+       <field id="O2_E3T"       long_name="O2 * E3T"                                 unit="mmol/m2"  > O2 * e3t </field >
+       <field id="CaCO3"        long_name="Calcite Concentration"                    unit="mmol/m3" />
+       <field id="CaCO3_E3T"    long_name="CaCO3 * E3T"                              unit="mmol/m2"  > CaCO3 * e3t </field >
+       <field id="PO4"          long_name="Phosphate Concentration"                  unit="mmol/m3" />
+       <field id="PO4_E3T"      long_name="PO4 * E3T"                                unit="mmol/m2"  > PO4 * e3t </field >
+       <field id="POC"          long_name="Small organic carbon Concentration"       unit="mmol/m3" />
+       <field id="POC_E3T"      long_name="POC * E3T"                                unit="mmol/m2"  > POC * e3t </field >
+       <field id="Si"           long_name="Silicate Concentration"                   unit="mmol/m3" />
+       <field id="Si_E3T"       long_name="Si * E3T"                                 unit="mmol/m2"  > Si * e3t </field >
+       <field id="PHY"          long_name="(Nano)Phytoplankton Concentration"        unit="mmol/m3" />
+       <field id="PHY_E3T"      long_name="PHY * E3T"                                unit="mmol/m2"  > PHY * e3t </field >
+       <field id="ZOO"          long_name="(Micro)Zooplankton Concentration"         unit="mmol/m3" />
+       <field id="ZOO_E3T"      long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO * e3t </field >
+       <field id="DOC"          long_name="Dissolved organic Concentration"          unit="mmol/m3" />
+       <field id="DOC_E3T"      long_name="DOC * E3T"                                unit="mmol/m2"  > DOC * e3t </field >
+       <field id="PHY2"         long_name="Diatoms Concentration"                    unit="mmol/m3" />
+       <field id="PHY2_E3T"     long_name="PHY2 * E3T"                               unit="mmol/m2"  > PHY2 * e3t </field >
+       <field id="ZOO2"         long_name="Mesozooplankton Concentration"            unit="mmol/m3" />
+       <field id="ZOO2_E3T"     long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO2 * e3t </field >
+       <field id="DSi"          long_name="Diatoms Silicate Concentration"           unit="mmol/m3" />
+       <field id="DSi_E3T"      long_name="Dsi * E3T"                                unit="mmol/m2"  > DSi * e3t </field >
+       <field id="Fer"          long_name="Dissolved Iron Concentration"             unit="mmol/m3" />
+       <field id="Fer_E3T"      long_name="Fer * E3T"                                unit="mmol/m2"  > Fer * e3t </field >
+       <field id="BFe"          long_name="Big iron particles Concentration"         unit="mmol/m3" />
+       <field id="BFe_E3T"      long_name="BFe * E3T"                                unit="mmol/m2"  > BFe * e3t </field >
+       <field id="GOC"          long_name="Big organic carbon Concentration"         unit="mmol/m3" />
+       <field id="GOC_E3T"      long_name="GOC * E3T"                                unit="mmol/m2"  > GOC * e3t </field >
+       <field id="SFe"          long_name="Small iron particles Concentration"       unit="mmol/m3" />
+       <field id="SFe_E3T"      long_name="SFe * E3T"                                unit="mmol/m2"  > SFe * e3t </field >
+       <field id="DFe"          long_name="Diatoms iron  Concentration"              unit="mmol/m3" />
+       <field id="DFe_E3T"      long_name="DFe * E3T"                                unit="mmol/m2"  > DFe * e3t </field >
+       <field id="GSi"          long_name="Sinking biogenic Silicate Concentration"  unit="mmol/m3" />
+       <field id="GSi_E3T"      long_name="GSi * E3T"                                unit="mmol/m2"  > GSi * e3t </field >
+       <field id="NFe"          long_name="Nano iron Concentration"                  unit="mmol/m3" />
+       <field id="NFe_E3T"      long_name="NFe * E3T"                                unit="mmol/m2"  > NFe * e3t </field >
+       <field id="NCHL"         long_name="Nano chlorophyl Concentration"            unit="mg/m3"   />
+       <field id="NCHL_E3T"     long_name="NCHL * E3T"                               unit="mmol/m2"  > NCHL * e3t </field >
+       <field id="DCHL"         long_name="Diatoms chlorophyl Concentration"         unit="mg/m3"   />
+       <field id="DCHL_E3T"     long_name="DCHL * E3T"                               unit="mmol/m2"  > DCHL * e3t </field >
+       <field id="NO3"          long_name="Nitrate Concentration"                    unit="mmol/m3" />
+       <field id="NO3_E3T"      long_name="NO3 * E3T"                                unit="mmol/m2"  > NO3 * e3t </field >
+       <field id="NH4"          long_name="Ammonium Concentration"                   unit="mmol/m3" />
+       <field id="NH4_E3T"      long_name="NH4 * E3T"                                unit="mmol/m2"  > NH4 * e3t </field >
+
+      <!-- MEDUSA : variables available with key_medusa -->
+       <field id="CHN"      long_name="Chl-a concentration in non-diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="CHD"      long_name="Chl-a concentration in     diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="PHN"      long_name="non-diatom phytoplankton"                          unit="mmol-N/m3" />
+       <field id="PHD"      long_name="diatom     phytoplankton"                          unit="mmol-N/m3" />
+       <field id="ZMI"      long_name="micro zooplankton"                                 unit="mmol-N/m3" />
+       <field id="ZME"      long_name="meso  zooplankton"                                 unit="mmol-N/m3" />
+       <field id="DIN"      long_name="dissolved inorganic nitrogen"                      unit="mmol-N/m3" />
+       <field id="SIL"      long_name="dissolved silicic acid"                            unit="mmolSi/m3" />
+       <field id="FER"      long_name="dissolved iron"                                    unit="mmolFe/m3" />
+       <field id="DET"      long_name="detrital nitrogen"                                 unit="mmol-N/m3" />
+       <field id="PDS"      long_name="biogenic silicon in diatom phytoplankton"          unit="mmolSi/m3" />
+       <field id="DTC"      long_name="detrital carbon"                                   unit="mmol-C/m3" />
+       <field id="DiC"      long_name="dissolved inorganic carbon"                        unit="mmol-C/m3" />
+       <field id="ALK"      long_name="alkalinity"                                        unit="meq/m3"    />
+       <field id="OXY"      long_name="dissolved oxygen"                                  unit="mmolO2/m3" />
+
+      <!-- Ideal traceurs : variables available with key_idtra -->
+       <field id="IDTRA"    long_name="Ideal traceur concentration "                      unit="mmol/m3"    />
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="Num"         long_name="Number of organic particles"              unit="1" />
+       <field id="Num_E3T"     long_name="Num * E3T"                                unit="m"  > Num * e3t </field >
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="DET"         long_name="Detritus"                                 unit="mmol-N/m3" />
+       <field id="DET_E3T"     long_name="DET * E3T"                                unit="mmol-N/m2"  > DET * e3t </field >
+       <field id="DOM"         long_name="Dissolved Organic Matter"                 unit="mmol-N/m3" />
+       <field id="DOM_E3T"     long_name="DOM * E3T"                                unit="mmol-N/m2"  > DOM * e3t </field >
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="CFC11"       long_name="CFC-11 Concentration"                     unit="umol/m3" />
+       <field id="CFC11_E3T"   long_name="CFC11 * E3T"                              unit="umol/m2"  > CFC11 * e3t </field >
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="C14B"        long_name="Bomb C14 Concentration"                   unit="1"         />
+       <field id="C14B_E3T"    long_name="C14B * E3T"                               unit="m"  > C14B * e3t </field >
+       <!-- AGE : variables available with key_age -->
+       <field id="Age"        long_name="Sea Water Age Since Surface contact" standard_name="sea_water_age_since_surface_contact"  unit="yr"         />
+       <field id="Age_e3t"    long_name="Age * e3t"                                 unit="yr * m"  > Age * e3t </field >
+     </field_group>
+
+     <!-- PISCES additional diagnostics on T grid  -->
+
+     <field_group id="diad_T" grid_ref="grid_T_2D">
+       <field id="PH"          long_name="PH"                                      unit="1"          grid_ref="grid_T_3D" />
+       <field id="CO3"         long_name="Bicarbonates"                            unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="CO3sat"      long_name="CO3 saturation"                          unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="PAR"         long_name="Photosynthetically Available Radiation"  unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PARDM"       long_name="Daily mean PAR"                          unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PPPHY"       long_name="Primary production of nanophyto"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPPHY2"      long_name="Primary production of diatoms"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWN"      long_name="New Primary production of nanophyto"     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWD"      long_name="New Primary production of diatoms"       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PBSi"        long_name="Primary production of Si diatoms"        unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeN"        long_name="Primary production of nano iron"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeD"        long_name="Primary production of diatoms iron"      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="xfracal"     long_name="Calcifying fraction"                     unit="1"          grid_ref="grid_T_3D" />
+       <field id="PCAL"        long_name="Calcite production"                      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DCAL"        long_name="Calcite dissolution"                     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ1"       long_name="Grazing by microzooplankton"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ2"       long_name="Grazing by mesozooplankton"              unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="REMIN"       long_name="Oxic remineralization of OM"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DENIT"       long_name="Anoxic remineralization of OM"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Nfix"        long_name="Nitrogen fixation"                       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Mumax"       long_name="Maximum growth rate"                     unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuN"         long_name="Realized growth rate for nanophyto"      unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuD"         long_name="Realized growth rate for diatomes"       unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="LNnut"       long_name="Nutrient limitation term in Nanophyto"   unit=""           grid_ref="grid_T_3D" />
+       <field id="LDnut"       long_name="Nutrient limitation term in Diatoms"     unit=""           grid_ref="grid_T_3D" />
+       <field id="LNFe"        long_name="Iron limitation term in Nanophyto"       unit=""           grid_ref="grid_T_3D" />
+       <field id="LDFe"        long_name="Iron limitation term in Diatoms"         unit=""           grid_ref="grid_T_3D" />
+       <field id="LNlight"     long_name="Light limitation term in Nanophyto"      unit=""           grid_ref="grid_T_3D" />
+       <field id="LDlight"     long_name="Light limitation term in Diatoms"        unit=""           grid_ref="grid_T_3D" />
+       <field id="Fe2"         long_name="Iron II concentration"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Fe3"         long_name="Iron III concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL1"        long_name="Complexed Iron concentration with L1"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL2"        long_name="Complexed Iron concentration with L2"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeP"         long_name="Precipitated Iron III"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL1"         long_name="Total L1 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL2"         long_name="Total L2 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="pdust"       long_name="dust concentration"                      unit="g/m3"                            />
+       <field id="Totlig"      long_name="Total ligand concentation"               unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Biron"       long_name="Bioavailable iron"                       unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Sdenit"      long_name="Nitrate reduction in the sediments"      unit="mol/m2/s"                        />
+       <field id="Ironice"     long_name="Iron input/uptake due to sea ice"        unit="mol/m2/s"                        />
+       <field id="HYDR"        long_name="Iron input from hydrothemal vents"       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EPC100"      long_name="Export of carbon particles at 100 m"     unit="mol/m2/s"                        />
+       <field id="EPFE100"     long_name="Export of biogenic iron at 100 m"        unit="mol/m2/s"                        />
+       <field id="EPSI100"     long_name="Export of Silicate at 100 m"             unit="mol/m2/s"                        />
+       <field id="EPCAL100"    long_name="Export of Calcite at 100 m"              unit="mol/m2/s"                        />
+       <field id="EXPC"        long_name="Export of carbon"                        unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPFE"       long_name="Export of biogenic iron"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPSI"       long_name="Export of Silicate"                      unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPCAL"      long_name="Export of Calcite"                       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="Cflx"        long_name="DIC flux"                                unit="mol/m2/s"                        />
+       <field id="Oflx"        long_name="Oxygen flux"                             unit="mol/m2/s"                        />
+       <field id="Kg"          long_name="Gas transfer"                            unit="mol/m2/s/uatm"                   />
+       <field id="Dpco2"       long_name="Delta CO2"                               unit="uatm"                            />
+       <field id="Dpo2"        long_name="Delta O2"                                unit="uatm"                            />
+       <field id="Heup"        long_name="Euphotic layer depth"                    unit="m"                               />
+       <field id="Irondep"     long_name="Iron deposition from dust"               unit="mol/m2/s"                        />
+       <field id="Ironsed"     long_name="Iron deposition from sediment"           unit="mol/m2/s"   grid_ref="grid_T_3D" />
+
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="EPN100"      long_name="Particulate number flux at 100 m"        unit="mol/m2/s"                        />
+       <field id="EXPN"        long_name="Particulate number flux"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="XNUM"        long_name="Number of particles in aggregats"        unit="1"          grid_ref="grid_T_3D" />
+       <field id="WSC"         long_name="sinking speed of mass flux"              unit="m2/s"       grid_ref="grid_T_3D" />
+       <field id="WSN"         long_name="sinking speed of number flux"            unit="m2/s"       grid_ref="grid_T_3D" />
+
+       <!-- dbio_T on T grid : variables available with key_diaar5 -->
+       <field id="TPP"         long_name="Total Primary production of phyto"                   unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPNEW"       long_name="New Primary production of phyto"                     unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPBFE"       long_name="Total biogenic iron production"                      unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="INTDIC"      long_name="DIC content"                                         unit="kg/m2"                          />
+       <field id="O2MIN"       long_name="Oxygen minimum concentration"                        unit="mol/m3"                          />
+       <field id="ZO2MIN"      long_name="Depth of oxygen minimum concentration"               unit="m"                              />
+       <field id="INTNFIX"     long_name="Nitrogen fixation rate : vert. integrated"           unit="mol/m2/s"                       />
+       <field id="INTPPPHY"    long_name="Vertically integrated primary production by nanophy" unit="mol/m2/s"                       />
+       <field id="INTPPPHY2"   long_name="Vertically integrated primary production by diatom"  unit="mol/m2/s"                       />
+       <field id="INTPP"       long_name="Vertically integrated primary production by phyto"   unit="mol/m2/s"                       />
+       <field id="INTPNEW"     long_name="Vertically integrated new primary production"        unit="mol/m2/s"                       />
+       <field id="INTPBFE"     long_name="Vertically integrated of biogenic iron production"   unit="mol/m2/s"                       />
+       <field id="INTPBSI"     long_name="Vertically integrated of biogenic Si production"     unit="mol/m2/s"                       />
+       <field id="INTPCAL"     long_name="Vertically integrated of calcite production"         unit="mol/m2/s"                       />
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="FNO3PHY"     long_name="FNO3PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4PHY"     long_name="FNH4PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4NO3"     long_name="FNH4NO3"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="TNO3PHY"     long_name="TNO3PHY"                                 unit=""  /> 
+       <field id="TNH4PHY"     long_name="TNH4PHY"                                 unit=""  /> 
+       <field id="TPHYDOM"     long_name="TPHYDOM"                                 unit=""  /> 
+       <field id="TPHYNH4"     long_name="TPHYNH4"                                 unit=""  /> 
+       <field id="TPHYZOO"     long_name="TPHYZOO"                                 unit=""  /> 
+       <field id="TPHYDET"     long_name="TPHYDET"                                 unit=""  /> 
+       <field id="TDETZOO"     long_name="TDETZOO"                                 unit=""  /> 
+       <field id="TZOODET"     long_name="TZOODET"                                 unit=""  /> 
+       <field id="TZOOBOD"     long_name="TZOOBOD"                                 unit=""  /> 
+       <field id="TZOONH4"     long_name="TZOONH4"                                 unit=""  /> 
+       <field id="TZOODOM"     long_name="TZOODOM"                                 unit=""  /> 
+       <field id="TNH4NO3"     long_name="TNH4NO3"                                 unit=""  /> 
+       <field id="TDOMNH4"     long_name="TDOMNH4"                                 unit=""  /> 
+       <field id="TDETNH4"     long_name="TDETNH4"                                 unit=""  /> 
+       <field id="TPHYTOT"     long_name="TPHYTOT"                                 unit=""  /> 
+       <field id="TZOOTOT"     long_name="TZOOTOT"                                 unit=""  /> 
+       <field id="SEDPOC"      long_name="SEDPOC"                                  unit=""  /> 
+       <field id="TDETSED"     long_name="TDETSED"                                 unit=""  /> 
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="qtrCFC11"    long_name="Air-sea flux of CFC-11"                  unit="mol/m2/s"   />
+       <field id="qintCFC11"   long_name="Cumulative air-sea flux of CFC-11"       unit="mol/m2"     />
+
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="qtrC14b"     long_name="Air-sea flux of Bomb C14"                unit="mol/m2/s"   />
+       <field id="qintC14b"    long_name="Cumulative air-sea flux of Bomb C14"     unit="mol/m2"     />
+       <field id="fdecay"      long_name="Radiactive decay of Bomb C14"            unit="mol/m3"  grid_ref="grid_T_3D"  />
+
+       <!-- IDTRA : variables available with key_idtra -->
+       <field id="qtrIDTRA"    long_name="Air-sea flux of Ideal Tracer"             unit="mol/m2/s"   />
+       <field id="qintIDTRA"   long_name="Cumulative air-sea flux of Ideal Tracer"  unit="mol/m2"     />
+       <field id="invIDTRA"    long_name="Vertical inventory"                       unit="mol/m2"     />
+
+       <!-- MEDUSA additional diagnostics on T grid  -->
+       <field id= "INVTN"      long_name="Column N inventory"                        unit="mmolN/m2"    />
+       <field id= "INVTSI"     long_name="Column Si inventory"                       unit="mmolSi/m2"   />
+       <field id= "INVTFE"     long_name="Column Fe inventory"                       unit="mmolFe/m2"   />
+       <field id= "PRN"        long_name="Non-diatom primary production"             unit="mmolN/m2/d"  />
+       <field id= "MPN"        long_name="Non-diatom non-grazing losses"             unit="mmolN/m2/d"  />
+       <field id= "PRD"        long_name="Diatom primary production"                 unit="mmolN/m2/d"  />
+       <field id= "MPD"        long_name="Diatom non-grazing losses"                 unit="mmolN/m2/d"  />
+       <field id= "DSED"       long_name="Gravitational sinking of Detritus"         unit="mmolN/m2/d"  />
+       <field id= "OPAL"       long_name="Diatom biogenic opal production"           unit="mmolSi/m2/d" />
+       <field id= "OPALDISS"   long_name="Diatom biogenic opal dissolution"          unit="mmolSi/m2/d" />
+       <field id= "GMIPn"      long_name="Microzoo grazing on non-diatoms"           unit="mmolN/m2/d"  />
+       <field id= "GMID"       long_name="Microzoo grazing on detritus"              unit="mmolN/m2/d"  />
+       <field id= "MZMI"       long_name="Microzoo non-grazing losses"               unit="mmolN/m2/d"  />
+       <field id= "GMEPN"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEPD"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEZMI"     long_name="Mesozoo grazing on microzoo"               unit="mmolN/m2/d"  />
+       <field id= "GMED"       long_name="Mesozoo grazing on detritus"               unit="mmolN/m2/d"  />
+       <field id= "MZME"       long_name="Mesozoo non-grazing losses"                unit="mmolN/m2/d"  />
+       <field id= "DEXP"       long_name="Detritus export"                           unit="mmolN/m2/d"  />
+       <field id= "DETN"       long_name="Slow detritus creation"                    unit="mmolN/m2/d"  />
+       <field id= "MDET"       long_name="Detritus non-grazing losses"               unit="MmolN/m2/d"  />
+       <field id= "AEOLIAN"    long_name="Aeolian deposition of iron"                unit="mmolFe/m2/d" />
+       <field id= "BENTHIC"    long_name="Benthic supply of iron"                    unit="mmolFe/m2/d" />
+       <field id= "SCAVENGE"   long_name="Scavenged iron"                            unit="mmolFe/m2/d" />
+       <field id= "PN_JLIM"    long_name="Non-diatom light limitation"               unit="-"           />
+       <field id= "PN_NLIM"    long_name="Non-diatom N limitation"                   unit="-"           />
+       <field id= "PN_FELIM"   long_name="Non-diatom Fe limitation"                  unit="-"           />
+       <field id= "PD_JLIM"    long_name="Diatom light limitation"                   unit="-"           />
+       <field id= "PD_NLIM"    long_name="Diatom N limitation"                       unit="-"           />
+       <field id= "PD_FELIM"   long_name="Diatom Fe limitation"                      unit="-"           />
+       <field id= "PD_SILIM"   long_name="Diatom Si limitation"                      unit="-"           />
+       <field id= "PDSILIM2"   long_name="Diatom Si uptake limitation"               unit="-"           />
+       <field id= "SDT__100"   long_name="Slow detrital flux at  100 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__200"   long_name="Slow detrital flux at  200 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__500"   long_name="Slow detrital flux at  500 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT_1000"   long_name="Slow detrital flux at 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "TOTREG_N"   long_name="Full column regenerated N"                 unit="mmolN/m2/d"  />
+       <field id= "TOTRG_SI"   long_name="Full column regenerated Si"                unit="mmolSi/m2/d" />
+       <field id= "REG__100"   long_name="Regenerated N to  100 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__200"   long_name="Regenerated N to  200 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__500"   long_name="Regenerated N to  500 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG_1000"   long_name="Regenerated N to 1000 m"                   unit="mmolN/m2/d"  />
+       <field id= "FASTN"      long_name="Fast-sinking flux N"                       unit="mmolN/m2/d"  />
+       <field id= "FASTSI"     long_name="Fast-sinking flux Si"                      unit="mmolSi/m2/d" />
+       <field id= "FASTFE"     long_name="Fast-sinking flux Fe"                      unit="mmolFe/m2/d" />
+       <field id= "FASTC"      long_name="Fast-sinking flux C"                       unit="mmolC/m2/d"  />
+       <field id= "FASTCA"     long_name="Fast-sinking flux CaCO3"                   unit="mmolC/m2/d"  />
+       <field id= "FDT__100"   long_name="Fast detrital N flux at  100 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__200"   long_name="Fast detrital N flux at  200 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__500"   long_name="Fast detrital N flux at  500 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT_1000"   long_name="Fast detrital N flux at 1000 m"            unit="mmolN/m2/d"  />
+       <field id= "RG__100F"   long_name="Regenerated fast N to  100 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__200F"   long_name="Regenerated fast N to  200 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__500F"   long_name="Regenerated fast N to  500 m"              unit="mmolN/m2/d"  />
+       <field id= "RG_1000F"   long_name="Regenerated fast N to 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "FDS__100"   long_name="Fast detrital Si flux at  100 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__200"   long_name="Fast detrital Si flux at  200 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__500"   long_name="Fast detrital Si flux at  500 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS_1000"   long_name="Fast detrital Si flux at 1000 m"           unit="mmolSi/m2/d" />
+       <field id= "RGS_100F"   long_name="Regenerated fast Si to  100 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_200F"   long_name="Regenerated fast Si to  200 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_500F"   long_name="Regenerated fast Si to  500 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS1000F"   long_name="Regenerated fast Si to 1000 m"             unit="mmolSi/m2/d" />
+       <field id= "REMINN"     long_name="Fast-sinking remin flux N"                 unit="mmolN/m2/d"  />
+       <field id= "REMINSI"    long_name="Fast-sinking remin flux Si"                unit="mmolSi/m2/d" />
+       <field id= "REMINFE"    long_name="Fast-sinking remin flux Fe"                unit="mmolFe/m2/d" />
+       <field id= "REMINC"     long_name="Fast-sinking remin flux C"                 unit="mmolC/m2/d"  />
+       <field id= "REMINCA"    long_name="Fast-sinking remin flux CaCO3"             unit="mmolC/m2/d"  />
+       <field id= "SEAFLRN"    long_name="Seafloor flux of N"                        unit="mmolN/m2/d"  />
+       <field id= "SEAFLRSI"   long_name="Seafloor flux of Si"                       unit="mmolSi/m2/d" />
+       <field id= "SEAFLRFE"   long_name="Seafloor flux of Fe"                       unit="mmolFe/m2/d" />
+       <field id= "SEAFLRC"    long_name="Seafloor flux of C"                        unit="mmolC/m2/d"  />
+       <field id= "SEAFLRCA"   long_name="Seafloor flux of CaCO3"                    unit="mmolC/m2/d"  />
+       <field id= "MED_QSR"    long_name="Sea surface radiation"                     unit="W/m2"        />
+       <field id= "MED_XPAR"   long_name="Top level radiation"                       unit="W/m2"        />
+       <field id= "INTFLX_N"   long_name="Integrated N  cycle fluxes"                unit="mmolN/m2/d"  />
+       <field id= "INTFLX_SI"  long_name="Integrated Si cycle fluxes"                unit="mmolSi/m2/d" />
+       <field id= "INTFLX_FE"  long_name="Integrated Fe cycle fluxes"                unit="mmolFe/m2/d" />
+       <field id= "INT_PN"     long_name="Vertically integrated Pn"                  unit="mmolN/m2"    />
+       <field id= "INT_PD"     long_name="Vertically integrated Pd"                  unit="mmolN/m2"    />
+       <field id= "ML_PRN"     long_name="Non-diatom mixed layer PP"                 unit="mmolN/m2/d"  />
+       <field id= "ML_PRD"     long_name="Diatom mixed layer PP"                     unit="mmolN/m2/d"  />
+       <field id= "OCAL_CCD"   long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "OCAL_LVL"   long_name="Calcite CCD level"                         unit="-"           />
+       <field id= "FE_0000"    long_name="Free iron at    0m"                        unit="-"           />
+       <field id= "FE_0100"    long_name="Free iron at  100m"                        unit="-"           />
+       <field id= "FE_0200"    long_name="Free iron at  200m"                        unit="-"           />
+       <field id= "FE_0500"    long_name="Free iron at  500m"                        unit="-"           />
+       <field id= "FE_1000"    long_name="Free iron at 1000m"                        unit="-"           />
+       <field id= "MED_XZE"    long_name="Euphotic depth"                            unit="m"           />
+       <field id= "WIND"       long_name="Surface scalar wind"                       unit="m/s"         />
+       <field id= "ATM_PCO2"   long_name="Atmospheric pCO2"                          unit="uatm"        />
+       <field id= "OCN_PH"     long_name="Surface ocean pH"                          unit="-"           />
+       <field id= "OCN_PCO2"   long_name="Surface ocean pCO2"                        unit="uatm"        />
+       <field id= "OCNH2CO3"   long_name="Surface ocean H2CO3 conc"                  unit="mmolC/m3"    />
+       <field id= "OCN_HCO3"   long_name="Surface ocean HCO3 conc"                   unit="mmolC/m3"    />
+       <field id= "OCN_CO3"    long_name="Surface ocean CO3 conc"                    unit="mmolC/m3"    />
+       <field id= "CO2FLUX"    long_name="Air-sea CO2 flux"                          unit="mmolC/m2/d"  />
+       <field id= "FGCO2"      long_name="Surface Downward CO2 Flux"                 unit="kg-CO2/m2/s" />
+       <field id= "OM_CAL"     long_name="Omega calcite"                             unit="-"           />
+       <field id= "OM_ARG"     long_name="Omega aragonite"                           unit="-"           />
+       <field id= "TCO2"       long_name="Total CO2"                                 unit="umol/kg"     />
+       <field id= "TALK"       long_name="Total alkalinity"                          unit="ueq/kg"      />
+       <field id= "KW660"      long_name="Piston velocity"                           unit="m/s"         />
+       <field id= "ATM_PP0"    long_name="Atmospheric pressure"                      unit="atm"         />
+       <field id= "O2FLUX"     long_name="Air-sea O2 flux"                           unit="mmolO2/m2/d" />
+       <field id= "O2SAT"      long_name="Surface ocean O2 saturation"               unit="mmolO2/m3"   />
+       <field id= "CAL_CCD"    long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "ARG_CCD"    long_name="Aragonite CCD depth"                       unit="m"           />
+       <field id= "SFR_OCAL"   long_name="Seafloor omega calcite"                    unit="-"           />
+       <field id= "SFR_OARG"   long_name="Seafloor omega aragonite"                  unit="-"           />
+       <field id= "N_PROD"     long_name="Nitrogen production"                       unit="mmolN/m2/d"  />
+       <field id= "N_CONS"     long_name="Nitrogen consumption"                      unit="mmolN/m2/d"  />
+       <field id= "C_PROD"     long_name="Carbon production"                         unit="mmolC/m2/d"  />
+       <field id= "C_CONS"     long_name="Carbon consumption"                        unit="mmolC/m2/d"  />
+       <field id= "O2_PROD"    long_name="Oxygen production"                         unit="mmolO2/m2/d" />
+       <field id= "O2_CONS"    long_name="Oxygen consumption"                        unit="mmolO2/m2/d" />
+       <field id= "O2_ANOX"    long_name="Unrealised oxygen consumption"             unit="mmolO2/m2/d" />
+       <field id= "RR_0100"    long_name="Rain ratio at  100m"                       unit="molC/molC"   />
+       <field id= "RR_0500"    long_name="Rain ratio at  500m"                       unit="molC/molC"   />
+       <field id= "RR_1000"    long_name="Rain ratio at 1000m"                       unit="molC/molC"   />
+       <field id= "IBEN_N"     long_name="Benthic input nitrogen"                    unit="mmolN/m2/d"  />
+       <field id= "IBEN_FE"    long_name="Benthic input iron"                        unit="mmolFe/m2/d" />
+       <field id= "IBEN_C"     long_name="Benthic input carbon"                      unit="mmolC/m2/d"  />
+       <field id= "IBEN_SI"    long_name="Benthic input silicon"                     unit="mmolSi/m2/d" />
+       <field id= "IBEN_CA"    long_name="Benthic input CaCO3"                       unit="mmolC/m2/d"  />
+       <field id= "OBEN_N"     long_name="Benthic output nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "OBEN_FE"    long_name="Benthic output iron"                       unit="mmolFe/m2/d" />
+       <field id= "OBEN_C"     long_name="Benthic output carbon"                     unit="mmolC/m2/d"  />
+       <field id= "OBEN_SI"    long_name="Benthic output silicon"                    unit="mmolSi/m2/d" />
+       <field id= "OBEN_CA"    long_name="Benthic output CaCO3"                      unit="mmolC/m2/d"  />
+       <field id= "BEN_N"      long_name="Benthic nitrogen"                          unit="mmolN/m2"    />
+       <field id= "BEN_FE"     long_name="Benthic iron"                              unit="mmolFe/m2"   />
+       <field id= "BEN_C"      long_name="Benthic carbon"                            unit="mmolC/m2"    />
+       <field id= "BEN_SI"     long_name="Benthic silicon"                           unit="mmolSi/m2"   />
+       <field id= "BEN_CA"     long_name="Benthic CaCO3"                             unit="mmolC/m2"    />
+       <field id= "RUNOFF"     long_name="River runoff"                              unit="m/d"         />
+       <field id= "RIV_N"      long_name="Riverine input nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "RIV_SI"     long_name="Riverine input silicon"                    unit="mmolSi/m2/d" />
+       <field id= "RIV_C"      long_name="Riverine input carbon"                     unit="mmolSi/m2/d" />
+       <field id= "RIV_ALK"    long_name="Riverine input alkalinity"                 unit="meq/m2/d"    />
+       <field id= "DETC"       long_name="Slow detritus C creation"                  unit="mmolC/m2/d"  />
+       <field id= "SDC__100"   long_name="Slow detrital C flux at  100 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__200"   long_name="Slow detrital C flux at  200 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__500"   long_name="Slow detrital C flux at  500 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC_1000"   long_name="Slow detrital C flux at 1000 m"            unit="mmolC/m2/d"  />
+       <field id= "INVTC"      long_name="Column C inventory"                        unit="mmolC/m2"    />
+       <field id= "INVTALK"    long_name="Column alkalinity inventory"               unit="meq/m2"      />
+       <field id= "INVTO2"     long_name="Column O2 inventory"                       unit="mmolO2/m2"   />
+       <field id= "LYSO_CA"    long_name="Incorrect benthic output CaCO3"            unit="mmolC/m2/d"  />
+       <field id= "COM_RESP"   long_name="Community respiration"                     unit="mmolC/m2/d"  />
+       <field id= "PN_LLOSS"   long_name="Non-diatom linear losses"                  unit="mmolN/m2/d"  />
+       <field id= "PD_LLOSS"   long_name="Diatom linear losses"                      unit="mmolN/m2/d"  />
+       <field id= "ZI_LLOSS"   long_name="Microzooplankton linear losses"            unit="mmolN/m2/d"  />
+       <field id= "ZE_LLOSS"   long_name="Mesozooplankton linear losses"             unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_N"   long_name="Microzoo messy feeding loss to N"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_D"   long_name="Microzoo messy feeding loss to D"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_C"   long_name="Microzoo messy feeding loss to C"          unit="mmolC/m2/d"  />
+       <field id= "ZI_MESDC"   long_name="Microzoo messy feeding loss to Dc"         unit="mmolC/m2/d"  />
+       <field id= "ZI_EXCR"    long_name="Microzoo excretion"                        unit="mmolN/m2/d"  />
+       <field id= "ZI_RESP"    long_name="Microzoo respiration"                      unit="mmolC/m2/d"  />
+       <field id= "ZI_GROW"    long_name="Microzoo growth"                           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_N"   long_name="Mesozoo messy feeding loss to N"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_D"   long_name="Mesozoo messy feeding loss to D"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_C"   long_name="Mesozoo messy feeding loss to C"           unit="mmolC/m2/d"  />
+       <field id= "ZE_MESDC"   long_name="Mesozoo messy feeding loss to Dc"          unit="mmolC/m2/d"  />
+       <field id= "ZE_EXCR"    long_name="Mesozoo excretion"                         unit="mmolN/m2/d"  />
+       <field id= "ZE_RESP"    long_name="Mesozoo respiration"                       unit="mmolC/m2/d"  />
+       <field id= "ZE_GROW"    long_name="Mesozoo growth"                            unit="mmolN/m2/d"  />
+       <field id= "MDETC"      long_name="Detritus non-grazing losses, carbon"       unit="mmolC/m2/d"  />
+       <field id= "GMIDC"      long_name="Microzoo grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "GMEDC"      long_name="Mesozoo  grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "INT_ZMI"    long_name="Vertically integrated Zmi"                 unit="mmolN/m2"    />
+       <field id= "INT_ZME"    long_name="Vertically integrated Zme"                 unit="mmolN/m2"    />
+       <field id= "INT_DET"    long_name="Vertically integrated Det"                 unit="mmolN/m2"    />
+       <field id= "INT_DTC"    long_name="Vertically integrated Dtc"                 unit="mmolC/m2"    />
+       <field id= "DMS_SURF"   long_name="DMS Surface Concentration"                 unit="nmol/L"      />
+       <field id= "DMS_ANDR"   long_name="DMS Surface Concentration, Anderson"       unit="nmol/L"      />
+       <field id= "DMS_SIMO"   long_name="DMS Surface Concentration, SimoDach"       unit="nmol/L"      />
+       <field id= "DMS_ARAN"   long_name="DMS Surface Concentration, AranamiT"       unit="nmol/L"      />
+       <field id= "DMS_HALL"   long_name="DMS Surface Concentration, Halloran"       unit="nmol/L"      />
+       <field id= "ATM_XCO2"   long_name="Atmospheric xCO2"                          unit="ppm"         />
+       <field id= "OCN_FCO2"   long_name="Surface ocean fCO2"                        unit="uatm"        />
+       <field id= "ATM_FCO2"   long_name="Atmospheric fCO2"                          unit="uatm"        />
+       <field id= "OCN_RHOSW"  long_name="MOCSY rhoSW"                               unit="kg/m3"       />
+       <field id= "OCN_SCHCO2" long_name="MOCSY Schmidt CO2"                         unit="-"           />
+       <field id= "OCN_KWCO2"  long_name="MOCSY kw CO2"                              unit="m/s"         />
+       <field id= "OCN_K0"     long_name="MOCSY k0"                                  unit="(mol/kg)/atm" />
+       <field id= "CO2STARAIR" long_name="MOCSY CO2star air"                         unit="mmol/m3"     />
+       <field id= "OCN_DPCO2"  long_name="MOCSY delta pCO2"                          unit="uatm"        />
+       
+
+       <!-- AXY (08/11/16): add new 2D CMIP6 diagnostics -->
+       <field id= "epC100"     long_name="Downward Flux of Particle Organic Carbon"  unit="mmolC/m2/d"  />
+       <field id= "epCALC100"  long_name="Downward Flux of Calcite"                  unit="mmolC/m2/d"  />
+       <field id= "epN100"     long_name="Downward Flux of Particulate Nitrogen"     unit="mmolN/m2/d"  />
+       <field id= "epSI100"    long_name="Downward Flux of Particulate Silica"       unit="mmolSi/m2/d" />
+       <field id= "INTDISSIC"  long_name="Dissolved Inorganic Carbon Content"        unit="mmolC/m2"    />
+       <field id= "INTDISSIN"  long_name="Dissolved Inorganic Nitrogen Content"      unit="mmolN/m2"    />
+       <field id= "INTDISSISI" long_name="Dissolved Inorganic Silicon Content"       unit="mmolSi/m2"   />
+       <field id= "INTTALK"    long_name="Dissolved Alkalinity Content"              unit="meq/m2"      />
+       <field id= "O2min"      long_name="Oxygen Minimum Concentration"              unit="mmolO2/m3"   />
+       <field id= "ZO2min"     long_name="Depth of Oxygen Minimum Concentration"     unit="m"           />
+       <field id= "FBDDTALK"   long_name="Int. change of Alkalinity due to Biology"  unit="meq/m2/d"    />
+       <field id= "FBDDTDIC"   long_name="Int. change of DI Carbon due to Biology"   unit="mmolC/m2/d"  />
+       <field id= "FBDDTDIFE"  long_name="Int. change of DI Iron due to Biology"     unit="mmolFe/m2/d" />
+       <field id= "FBDDTDIN"   long_name="Int. change of DI Nitrogen due to Biology" unit="mmolN/m2/d"  />
+       <field id= "FBDDTDISI"  long_name="Int. change of DI Silicon due to Biology"  unit="mmolSi/m2/d" />
+       
+
+       <!-- MEDUSA 3D diagnostics -->
+       <field id= "TPP3"       long_name="Total primary production 3D"               unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "DETFLUX3"   long_name="Total detrital flux 3D"                    unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMIN3N"    long_name="Total remin flux N 3D"                     unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PH3"        long_name="Ocean pH 3D"                               unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "OM_CAL3"    long_name="Omega calcite 3D"                          unit="-"             grid_ref="grid_T_3D"  />
+
+       <!-- AXY (08/11/16): add new 3D CMIP6 diagnostics -->
+       <field id= "TPPD3"      long_name="Diatom primary production 3D"              unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTALK3"   long_name="Change of Alkalinity due to Biology"       unit="meq/m3/d"      grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIC3"   long_name="Change of DI Carbon due to Biology"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIFE3"  long_name="Change of DI Iron due to Biology"          unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIN3"   long_name="Change of DI Nitrogen due to Biology"      unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTDISI3"  long_name="Change of DI Silicon due to Biology"       unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_NIT3"    long_name="Fast sinking detrital nitrogen"            unit="mmolN/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_SIL3"    long_name="Fast sinking detrital silicon"             unit="mmolSi/m2/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_CAR3"    long_name="Fast sinking detrital carbon"              unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_CAL3"    long_name="Fast sinking detrital calcium carbonate"   unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "CO33"       long_name="Carbonate ion concentration"               unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATARAG3" long_name="Carbonate aragonite saturation conc"      unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATCALC3" long_name="Carbonate calcite saturation conc"        unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "DCALC3"     long_name="Calcite dissolution"                       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPC3"      long_name="Downward Flux of Particulate Org Carbon"   unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPN3"      long_name="Downward Flux of Particulate Org Nitrogen" unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "FEDISS3"    long_name="Particle Source of Dissolved Iron"         unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FESCAV3"    long_name="Nonbiogenic Iron Scavenging"               unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZP3"   long_name="Microzooplankton grazing on phytoplankton" unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZD3"   long_name="Microzooplankton grazing on detritus"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZP3"   long_name="Mesozooplankton grazing on phytoplankton"  unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZD3"   long_name="Mesozooplankton grazing on detritus"       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZZ3"   long_name="Mesozooplankton grazing on microzoop"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "O2SAT3"     long_name="Dissolved Oxygen Saturation Concentration" unit="mmolO2/m3"     grid_ref="grid_T_3D"  />
+       <field id= "PBSI3"      long_name="Biogenic Silica Production"                unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "PCAL3"      long_name="Biogenic Calcite Production"               unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMOC3"     long_name="Remineralization of Organic Carbon"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PNLIMJ3"    long_name="Irradiance limitation of non-diatoms"      unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMN3"    long_name="Nitrogen limitation of non-diatoms"        unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMFE3"   long_name="Iron limitation of non-diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMJ3"    long_name="Irradiance limitation of diatoms"          unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMN3"    long_name="Nitrogen limitation of diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMFE3"   long_name="Iron limitation of diatoms"                unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMSI3"   long_name="Silicon limitation of diatoms"             unit="-"             grid_ref="grid_T_3D"  />
+
+     </field_group>
+
+     <field_group id="PISCES_scalar"  domain_ref="1point" >
+       <field id="pno3tot"         long_name="global mean nitrate concentration"                  unit="mol/m3"   />
+       <field id="ppo4tot"         long_name="global mean phosphorus concentration"               unit="mol/m3"   />
+       <field id="psiltot"         long_name="global mean silicate concentration"                 unit="mol/m3"   />
+       <field id="palktot"         long_name="global mean alkalinity concentration"               unit="mol/m3"   />
+       <field id="pfertot"         long_name="global mean iron concentration"                     unit="mol/m3"   />
+       <field id="tcflx"           long_name="total Flux of Carbon out of the ocean"              unit="mol/s"   />
+       <field id="tcflxcum"        long_name="cumulative total Flux of Carbon out of the ocean"   unit="mol/s"   />
+       <field id="tcexp"           long_name="total Carbon export at 100m"                        unit="mol/s"   />
+       <field id="tintpp"          long_name="global total integrated primary production"         unit="mol/s"   />
+       <field id="tnfix"           long_name="global total nitrogen fixation"                     unit="mol/s"   />
+       <field id="tdenit"          long_name="Total denitrification"                              unit="mol/s"   />
+     </field_group>
+
+    <!-- 
+============================================================================================================
+                                        Definitions for iodef_demo.xml
+============================================================================================================
+    -->
+
+    <field_group id="groupMEDUSA" >
+      <field field_ref="CHN"   name="CHN"   />
+      <field field_ref="CHD"   name="CHD"   />
+      <field field_ref="PHN"   name="PHN"   />
+      <field field_ref="PHD"   name="PHD"   />
+      <field field_ref="ZMI"   name="ZMI"   />
+      <field field_ref="ZME"   name="ZME"   />
+      <field field_ref="DIN"   name="DIN"   />
+      <field field_ref="SIL"   name="SIL"   />
+      <field field_ref="FER"   name="FER"   />
+      <field field_ref="DET"   name="DET"   />
+      <field field_ref="PDS"   name="PDS"   />
+      <field field_ref="DTC"   name="DTC"   />
+      <field field_ref="DiC"   name="DIC"   />
+      <field field_ref="ALK"   name="ALK"   />
+      <field field_ref="OXY"   name="OXY"   />
+      </field_group>
+
+    <field_group id="groupIDTRA" >
+      <field field_ref="IDTRA" name="IDTRA" />
+    </field_group>
+
+    <field_group id="groupIDTRA_dia" >
+      <field field_ref="qtrIDTRA"    name="qtrIDTRA"  />
+      <field field_ref="qintIDTRA"   name="qintIDTRA" />
+      <field field_ref="invIDTRA"    name="invIDTRA"  />
+    </field_group>
+
+    <field_group id="groupCFC" >
+      <field field_ref="CFC11" name="CFC11" />
+    </field_group>
+
+    <field_group id="groupCFC_dia" >
+      <field field_ref="qtrCFC11"    name="qtrCFC11"   />
+      <field field_ref="qintCFC11"   name="qintCFC11"  />
+    </field_group>
+
+    <field_group id="groupAGE" >
+      <field field_ref="Age" name="Age" />
+    </field_group>
+
+    <field_group id="groupMEDUSA_dia" >
+      <field field_ref= "INVTN"      name="INVTN"      />
+      <field field_ref= "INVTSI"     name="INVTSI"     />
+      <field field_ref= "INVTFE"     name="INVTFE"     />
+      <field field_ref= "PRN"        name="PRN"        />
+      <field field_ref= "MPN"        name="MPN"        />
+      <field field_ref= "PRD"        name="PRD"        />
+      <field field_ref= "MPD"        name="MPD"        />
+      <field field_ref= "OPAL"       name="OPAL"       />
+      <field field_ref= "OPALDISS"   name="OPALDISS"   />
+      <field field_ref= "GMIPn"      name="GMIPn"      />
+      <field field_ref= "GMID"       name="GMID"       />
+      <field field_ref= "MZMI"       name="MZMI"       />
+      <field field_ref= "GMEPN"      name="GMEPN"      />
+      <field field_ref= "GMEPD"      name="GMEPD"      />
+      <field field_ref= "GMEZMI"     name="GMEZMI"     />
+      <field field_ref= "GMED"       name="GMED"       />
+      <field field_ref= "MZME"       name="MZME"       />
+      <field field_ref= "DETN"       name="DETN"       />
+      <field field_ref= "MDET"       name="MDET"       />
+      <field field_ref= "AEOLIAN"    name="AEOLIAN"    />
+      <field field_ref= "BENTHIC"    name="BENTHIC"    />
+      <field field_ref= "SCAVENGE"   name="SCAVENGE"   />
+      <field field_ref= "PN_JLIM"    name="PN_JLIM"    />
+      <field field_ref= "PN_NLIM"    name="PN_NLIM"    />
+      <field field_ref= "PN_FELIM"   name="PN_FELIM"   />
+      <field field_ref= "PD_JLIM"    name="PD_JLIM"    />
+      <field field_ref= "PD_NLIM"    name="PD_NLIM"    />
+      <field field_ref= "PD_FELIM"   name="PD_FELIM"   />
+      <field field_ref= "PD_SILIM"   name="PD_SILIM"   />
+      <field field_ref= "PDSILIM2"   name="PDSILIM2"   />
+      <field field_ref= "SDT__100"   name="SDT__100"   />
+      <field field_ref= "SDT__200"   name="SDT__200"   />
+      <field field_ref= "SDT__500"   name="SDT__500"   />
+      <field field_ref= "SDT_1000"   name="SDT_1000"   />
+      <field field_ref= "TOTREG_N"   name="TOTREG_N"   />
+      <field field_ref= "TOTRG_SI"   name="TOTRG_SI"   />
+      <field field_ref= "REG__100"   name="REG__100"   />
+      <field field_ref= "REG__200"   name="REG__200"   />
+      <field field_ref= "REG__500"   name="REG__500"   />
+      <field field_ref= "REG_1000"   name="REG_1000"   />
+      <field field_ref= "FASTN"      name="FASTN"      />
+      <field field_ref= "FASTSI"     name="FASTSI"     />
+      <field field_ref= "FASTFE"     name="FASTFE"     />
+      <field field_ref= "FASTC"      name="FASTC"      />
+      <field field_ref= "FASTCA"     name="FASTCA"     />
+      <field field_ref= "FDT__100"   name="FDT__100"   />
+      <field field_ref= "FDT__200"   name="FDT__200"   />
+      <field field_ref= "FDT__500"   name="FDT__500"   />
+      <field field_ref= "FDT_1000"   name="FDT_1000"   /> 
+      <field field_ref= "RG__100F"   name="RG__100F"   />
+      <field field_ref= "RG__200F"   name="RG__200F"   />
+      <field field_ref= "RG__500F"   name="RG__500F"   />
+      <field field_ref= "RG_1000F"   name="RG_1000F"   />
+      <field field_ref= "FDS__100"   name="FDS__100"   />
+      <field field_ref= "FDS__200"   name="FDS__200"   />
+      <field field_ref= "FDS__500"   name="FDS__500"   />
+      <field field_ref= "FDS_1000"   name="FDS_1000"   />
+      <field field_ref= "RGS_100F"   name="RGS_100F"   />
+      <field field_ref= "RGS_200F"   name="RGS_200F"   />
+      <field field_ref= "RGS_500F"   name="RGS_500F"   />
+      <field field_ref= "RGS1000F"   name="RGS1000F"   />
+      <field field_ref= "REMINN"     name="REMINN"     />
+      <field field_ref= "REMINSI"    name="REMINSI"    />
+      <field field_ref= "REMINFE"    name="REMINFE"    />
+      <field field_ref= "SEAFLRN"    name="SEAFLRN"    /> 
+      <field field_ref= "SEAFLRSI"   name="SEAFLRSI"   />
+      <field field_ref= "SEAFLRFE"   name="SEAFLRFE"   />
+      <field field_ref= "SEAFLRC"    name="SEAFLRC"    />
+      <field field_ref= "SEAFLRCA"   name="SEAFLRCA"   />
+      <field field_ref= "MED_QSR"    name="MED_QSR"    />
+      <field field_ref= "MED_XPAR"   name="MED_XPAR"   />
+      <field field_ref= "INTFLX_N"   name="INTFLX_N"   />
+      <field field_ref= "INTFLX_SI"  name="INTFLX_SI"  />
+      <field field_ref= "INTFLX_FE"  name="INTFLX_FE"  />
+      <field field_ref= "INT_PN"     name="INT_PN"     />
+      <field field_ref= "INT_PD"     name="INT_PD"     />
+      <field field_ref= "ML_PRN"     name="ML_PRN"     />
+      <field field_ref= "ML_PRD"     name="ML_PRD"     />
+      <field field_ref= "OCAL_CCD"   name="OCAL_CCD"   />
+      <field field_ref= "OCAL_LVL"   name="OCAL_LVL"   />
+      <field field_ref= "FE_0000"    name="FE_0000"    />
+      <field field_ref= "FE_0100"    name="FE_0100"    />
+      <field field_ref= "FE_0200"    name="FE_0200"    /> 
+      <field field_ref= "FE_0500"    name="FE_0500"    />
+      <field field_ref= "FE_1000"    name="FE_1000"    />
+      <field field_ref= "MED_XZE"    name="MED_XZE"    />
+      <field field_ref= "WIND"       name="WIND"       />
+      <field field_ref= "ATM_PCO2"   name="ATM_PCO2"   />
+      <field field_ref= "OCN_PH"     name="OCN_PH"     />
+      <field field_ref= "OCN_PCO2"   name="OCN_PCO2"   />
+      <field field_ref= "OCNH2CO3"   name="OCNH2CO3"   />
+      <field field_ref= "OCN_HCO3"   name="OCN_HCO3"   />
+      <field field_ref= "OCN_CO3"    name="OCN_CO3"    />
+      <field field_ref= "CO2FLUX"    name="CO2FLUX"    />
+      <field field_ref= "FGCO2"      name="FGCO2"      />
+      <field field_ref= "OM_CAL"     name="OM_CAL"     />
+      <field field_ref= "OM_ARG"     name="OM_ARG"     />
+      <field field_ref= "TCO2"       name="TCO2"       />
+      <field field_ref= "TALK"       name="TALK"       />
+      <field field_ref= "KW660"      name="KW660"      />
+      <field field_ref= "ATM_PP0"    name="ATM_PP0"    />
+      <field field_ref= "O2FLUX"     name="O2FLUX"     />
+      <field field_ref= "O2SAT"      name="O2SAT"      />
+      <field field_ref= "CAL_CCD"    name="CAL_CCD"    />
+      <field field_ref= "ARG_CCD"    name="ARG_CCD"    />
+      <field field_ref= "SFR_OCAL"   name="SFR_OCAL"   />
+      <field field_ref= "SFR_OARG"   name="SFR_OARG"   />
+      <field field_ref= "N_PROD"     name="N_PROD"     />
+      <field field_ref= "N_CONS"     name="N_CONS"     />
+      <field field_ref= "C_PROD"     name="C_PROD"     />
+      <field field_ref= "C_CONS"     name="C_CONS"     />
+      <field field_ref= "O2_PROD"    name="O2_PROD"    />
+      <field field_ref= "O2_CONS"    name="O2_CONS"    />
+      <field field_ref= "O2_ANOX"    name="O2_ANOX"    />
+      <field field_ref= "RR_0100"    name="RR_0100"    />
+      <field field_ref= "RR_0500"    name="RR_0500"    />
+      <field field_ref= "RR_1000"    name="RR_1000"    />
+      <field field_ref= "IBEN_N"     name="IBEN_N"     />
+      <field field_ref= "IBEN_FE"    name="IBEN_FE"    />
+      <field field_ref= "IBEN_C"     name="IBEN_C"     />
+      <field field_ref= "IBEN_SI"    name="IBEN_SI"    />
+      <field field_ref= "IBEN_CA"    name="IBEN_CA"    />
+      <field field_ref= "OBEN_N"     name="OBEN_N"     />
+      <field field_ref= "OBEN_FE"    name="OBEN_FE"    />
+      <field field_ref= "OBEN_C"     name="OBEN_C"     />
+      <field field_ref= "OBEN_SI"    name="OBEN_SI"    />
+      <field field_ref= "OBEN_CA"    name="OBEN_CA"    />
+      <field field_ref= "BEN_N"      name="BEN_N"      />
+      <field field_ref= "BEN_FE"     name="BEN_FE"     />
+      <field field_ref= "BEN_C"      name="BEN_C"      />
+      <field field_ref= "BEN_SI"     name="BEN_SI"     />
+      <field field_ref= "BEN_CA"     name="BEN_CA"     />
+      <field field_ref= "DETC"       name="DETC"       />
+      <field field_ref= "SDC__100"   name="SDC__100"   />
+      <field field_ref= "SDC__200"   name="SDC__200"   />
+      <field field_ref= "SDC__500"   name="SDC__500"   />
+      <field field_ref= "SDC_1000"   name="SDC_1000"   />
+      <field field_ref= "INVTC"      name="INVTC"      />
+      <field field_ref= "INVTALK"    name="INVTALK"    />
+      <field field_ref= "INVTO2"     name="INVTO2"     />
+      <field field_ref= "LYSO_CA"    name="LYSO_CA"    />
+      <field field_ref= "COM_RESP"   name="COM_RESP"   />
+      <field field_ref= "PN_LLOSS"   name="PN_LLOSS"   />
+      <field field_ref= "PD_LLOSS"   name="PD_LLOSS"   />
+      <field field_ref= "ZI_LLOSS"   name="ZI_LLOSS"   />
+      <field field_ref= "ZE_LLOSS"   name="ZE_LLOSS"   />
+      <field field_ref= "ZI_MES_N"   name="ZI_MES_N"   />
+      <field field_ref= "ZI_MES_D"   name="ZI_MES_D"   />
+      <field field_ref= "ZI_MES_C"   name="ZI_MES_C"   />
+      <field field_ref= "ZI_MESDC"   name="ZI_MESDC"   />
+      <field field_ref= "ZI_EXCR"    name="ZI_EXCR"    />
+      <field field_ref= "ZI_RESP"    name="ZI_RESP"    />
+      <field field_ref= "ZI_GROW"    name="ZI_GROW"    />
+      <field field_ref= "ZE_MES_N"   name="ZE_MES_N"   />
+      <field field_ref= "ZE_MES_D"   name="ZE_MES_D"   />
+      <field field_ref= "ZE_MES_C"   name="ZE_MES_C"   />
+      <field field_ref= "ZE_MESDC"   name="ZE_MESDC"   />
+      <field field_ref= "ZE_EXCR"    name="ZE_EXCR"    />
+      <field field_ref= "ZE_RESP"    name="ZE_RESP"    />
+      <field field_ref= "ZE_GROW"    name="ZE_GROW"    />
+      <field field_ref= "MDETC"      name="MDETC"      />
+      <field field_ref= "GMIDC"      name="GMIDC"      />
+      <field field_ref= "GMEDC"      name="GMEDC"      />
+      <field field_ref= "INT_ZMI"    name="INT_ZMI"    />
+      <field field_ref= "INT_ZME"    name="INT_ZME"    />
+      <field field_ref= "INT_DET"    name="INT_DET"    />
+      <field field_ref= "INT_DTC"    name="INT_DTC"    />
+      <field field_ref= "ATM_XCO2"   name="ATM_XCO2"   />
+      <field field_ref= "OCN_FCO2"   name="OCN_FCO2"   />
+      <field field_ref= "ATM_FCO2"   name="ATM_FCO2"   />
+      <field field_ref= "OCN_RHOSW"  name="OCN_RHOSW"  />
+      <field field_ref= "OCN_SCHCO2" name="OCN_SCHCO2" />
+      <field field_ref= "OCN_KWCO2"  name="OCN_KWCO2"  />
+      <field field_ref= "OCN_K0"     name="OCN_K0"     />
+      <field field_ref= "CO2STARAIR" name="CO2STARAIR" />
+      <field field_ref= "OCN_DPCO2"  name="OCN_DPCO2"  />
+    </field_group>
+
+    <field_group id="groupMEDUSA_3dd" >
+      <field field_ref= "TPP3"       name="TPP3"       />
+      <field field_ref= "DETFLUX3"   name="DETFLUX3"   />
+      <field field_ref= "REMIN3N"    name="REMIN3N"    />
+      <field field_ref= "PH3"        name="PH3"        />
+      <field field_ref= "OM_CAL3"    name="OM_CAL3"    /> 
+    </field_group>
+
+    <field_group id="groupMEDUSA_dms" >
+      <field field_ref= "DMS_SURF"   name="DMS_SURF"   />
+      <field field_ref= "DMS_ANDR"   name="DMS_ANDR"   />
+      <field field_ref= "DMS_SIMO"   name="DMS_SIMO"   />
+      <field field_ref= "DMS_ARAN"   name="DMS_ARAN"   />
+      <field field_ref= "DMS_HALL"   name="DMS_HALL"   />
+    </field_group>
+
+    <field_group id="groupMEDUSA_riv" >
+      <field field_ref= "RUNOFF"     name="RUNOFF"     />
+      <field field_ref= "RIV_N"      name="RIV_N"      />
+      <field field_ref= "RIV_SI"     name="RIV_SI"     />
+      <field field_ref= "RIV_C"      name="RIV_C"      />
+      <field field_ref= "RIV_ALK"    name="RIV_ALK"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_cmip6" >
+      <field field_ref= "epC100"     name="epC100"     />
+      <field field_ref= "epCALC100"  name="epCALC100"  />
+      <field field_ref= "epN100"     name="epN100"     />
+      <field field_ref= "epSI100"    name="epSI100"    />
+      <field field_ref= "INTDISSIC"  name="INTDISSIC"  />
+      <field field_ref= "INTDISSIN"  name="INTDISSIN"  />
+      <field field_ref= "INTDISSISI" name="INTDISSISI" />
+      <field field_ref= "INTTALK"    name="INTTALK"    />
+      <field field_ref= "O2min"      name="O2min"      />
+      <field field_ref= "ZO2min"     name="ZO2min"     />
+      <field field_ref= "FBDDTALK"   name="FBDDTALK"   />
+      <field field_ref= "FBDDTDIC"   name="FBDDTDIC"   />
+      <field field_ref= "FBDDTDIFE"  name="FBDDTDIFE"  />
+      <field field_ref= "FBDDTDIN"   name="FBDDTDIN"   />
+      <field field_ref= "FBDDTDISI"  name="FBDDTDISI"  />
+      <field field_ref= "TPPD3"      name="TPPD3"      />
+      <field field_ref= "BDDTALK3"   name="BDDTALK3"   />
+      <field field_ref= "BDDTDIC3"   name="BDDTDIC3"   />
+      <field field_ref= "BDDTDIFE3"  name="BDDTDIFE3"  />
+      <field field_ref= "BDDTDIN3"   name="BDDTDIN3"   />
+      <field field_ref= "BDDTDISI3"  name="BDDTDISI3"  />
+      <field field_ref= "FD_NIT3"    name="FD_NIT3"    />
+      <field field_ref= "FD_SIL3"    name="FD_SIL3"    />
+      <field field_ref= "FD_CAR3"    name="FD_CAR3"    />
+      <field field_ref= "FD_CAL3"    name="FD_CAL3"    />
+      <field field_ref= "CO33"       name="CO33"       />
+      <field field_ref= "CO3SATARAG3" name="CO3SATARAG3" />
+      <field field_ref= "CO3SATCALC3" name="CO3SATCALC3" />
+      <field field_ref= "DCALC3"     name="DCALC3"     />
+      <field field_ref= "EXPC3"      name="EXPC3"      />
+      <field field_ref= "EXPN3"      name="EXPN3"      />
+      <field field_ref= "FEDISS3"    name="FEDISS3"    />
+      <field field_ref= "FESCAV3"    name="FESCAV3"    />
+      <field field_ref= "MIGRAZP3"   name="MIGRAZP3"   />
+      <field field_ref= "MIGRAZD3"   name="MIGRAZD3"   />
+      <field field_ref= "MEGRAZP3"   name="MEGRAZP3"   />
+      <field field_ref= "MEGRAZD3"   name="MEGRAZD3"   />
+      <field field_ref= "MEGRAZZ3"   name="MEGRAZZ3"   />
+      <field field_ref= "O2SAT3"     name="O2SAT3"     />
+      <field field_ref= "PBSI3"      name="PBSI3"      />
+      <field field_ref= "PCAL3"      name="PCAL3"      />
+      <field field_ref= "REMOC3"     name="REMOC3"     />
+      <field field_ref= "PNLIMJ3"    name="PNLIMJ3"    />
+      <field field_ref= "PNLIMN3"    name="PNLIMN3"    />
+      <field field_ref= "PNLIMFE3"   name="PNLIMFE3"   />
+      <field field_ref= "PDLIMJ3"    name="PDLIMJ3"    />
+      <field field_ref= "PDLIMN3"    name="PDLIMN3"    />
+      <field field_ref= "PDLIMFE3"   name="PDLIMFE3"   />
+      <field field_ref= "PDLIMSI3"   name="PDLIMSI3"   />
+    </field_group>
+
+</field_definition>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/field_def_bgc_CMIP6.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/field_def_bgc_CMIP6.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/field_def_bgc_CMIP6.xml	(revision 7693)
@@ -0,0 +1,778 @@
+<!--
+<?xml version="1.0"?>
+       -->
+ 
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+   <field_definition level="1" prec="8" operation="average" enabled=".TRUE." default_value="1.e20" > <!-- time step automaticaly defined -->
+
+    <!-- 
+============================================================================================================
+                                     Biogeochemistry model variables
+============================================================================================================
+    -->
+
+      <!-- ptrc on T grid -->
+
+     <field_group id="ptrc_T" grid_ref="grid_T_3D">
+       <field id="DIC"          long_name="Dissolved inorganic Concentration"        unit="mmol/m3" />
+       <field id="DIC_E3T"      long_name="DIC * E3T"                                unit="mmol/m2" > DIC * e3t </field >
+       <field id="Alkalini"     long_name="Total Alkalinity Concentration"           unit="mmol/m3" />
+       <field id="Alkalini_E3T" long_name="Alkalini * E3T"                           unit="mmol/m2"  > Alkalini * e3t </field >
+       <field id="O2"           long_name="Oxygen Concentration"                     unit="mmol/m3" />
+       <field id="O2_E3T"       long_name="O2 * E3T"                                 unit="mmol/m2"  > O2 * e3t </field >
+       <field id="CaCO3"        long_name="Calcite Concentration"                    unit="mmol/m3" />
+       <field id="CaCO3_E3T"    long_name="CaCO3 * E3T"                              unit="mmol/m2"  > CaCO3 * e3t </field >
+       <field id="PO4"          long_name="Phosphate Concentration"                  unit="mmol/m3" />
+       <field id="PO4_E3T"      long_name="PO4 * E3T"                                unit="mmol/m2"  > PO4 * e3t </field >
+       <field id="POC"          long_name="Small organic carbon Concentration"       unit="mmol/m3" />
+       <field id="POC_E3T"      long_name="POC * E3T"                                unit="mmol/m2"  > POC * e3t </field >
+       <field id="Si"           long_name="Silicate Concentration"                   unit="mmol/m3" />
+       <field id="Si_E3T"       long_name="Si * E3T"                                 unit="mmol/m2"  > Si * e3t </field >
+       <field id="PHY"          long_name="(Nano)Phytoplankton Concentration"        unit="mmol/m3" />
+       <field id="PHY_E3T"      long_name="PHY * E3T"                                unit="mmol/m2"  > PHY * e3t </field >
+       <field id="ZOO"          long_name="(Micro)Zooplankton Concentration"         unit="mmol/m3" />
+       <field id="ZOO_E3T"      long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO * e3t </field >
+       <field id="DOC"          long_name="Dissolved organic Concentration"          unit="mmol/m3" />
+       <field id="DOC_E3T"      long_name="DOC * E3T"                                unit="mmol/m2"  > DOC * e3t </field >
+       <field id="PHY2"         long_name="Diatoms Concentration"                    unit="mmol/m3" />
+       <field id="PHY2_E3T"     long_name="PHY2 * E3T"                               unit="mmol/m2"  > PHY2 * e3t </field >
+       <field id="ZOO2"         long_name="Mesozooplankton Concentration"            unit="mmol/m3" />
+       <field id="ZOO2_E3T"     long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO2 * e3t </field >
+       <field id="DSi"          long_name="Diatoms Silicate Concentration"           unit="mmol/m3" />
+       <field id="DSi_E3T"      long_name="Dsi * E3T"                                unit="mmol/m2"  > DSi * e3t </field >
+       <field id="Fer"          long_name="Dissolved Iron Concentration"             unit="mmol/m3" />
+       <field id="Fer_E3T"      long_name="Fer * E3T"                                unit="mmol/m2"  > Fer * e3t </field >
+       <field id="BFe"          long_name="Big iron particles Concentration"         unit="mmol/m3" />
+       <field id="BFe_E3T"      long_name="BFe * E3T"                                unit="mmol/m2"  > BFe * e3t </field >
+       <field id="GOC"          long_name="Big organic carbon Concentration"         unit="mmol/m3" />
+       <field id="GOC_E3T"      long_name="GOC * E3T"                                unit="mmol/m2"  > GOC * e3t </field >
+       <field id="SFe"          long_name="Small iron particles Concentration"       unit="mmol/m3" />
+       <field id="SFe_E3T"      long_name="SFe * E3T"                                unit="mmol/m2"  > SFe * e3t </field >
+       <field id="DFe"          long_name="Diatoms iron  Concentration"              unit="mmol/m3" />
+       <field id="DFe_E3T"      long_name="DFe * E3T"                                unit="mmol/m2"  > DFe * e3t </field >
+       <field id="GSi"          long_name="Sinking biogenic Silicate Concentration"  unit="mmol/m3" />
+       <field id="GSi_E3T"      long_name="GSi * E3T"                                unit="mmol/m2"  > GSi * e3t </field >
+       <field id="NFe"          long_name="Nano iron Concentration"                  unit="mmol/m3" />
+       <field id="NFe_E3T"      long_name="NFe * E3T"                                unit="mmol/m2"  > NFe * e3t </field >
+       <field id="NCHL"         long_name="Nano chlorophyl Concentration"            unit="mg/m3"   />
+       <field id="NCHL_E3T"     long_name="NCHL * E3T"                               unit="mmol/m2"  > NCHL * e3t </field >
+       <field id="DCHL"         long_name="Diatoms chlorophyl Concentration"         unit="mg/m3"   />
+       <field id="DCHL_E3T"     long_name="DCHL * E3T"                               unit="mmol/m2"  > DCHL * e3t </field >
+       <field id="NO3"          long_name="Nitrate Concentration"                    unit="mmol/m3" />
+       <field id="NO3_E3T"      long_name="NO3 * E3T"                                unit="mmol/m2"  > NO3 * e3t </field >
+       <field id="NH4"          long_name="Ammonium Concentration"                   unit="mmol/m3" />
+       <field id="NH4_E3T"      long_name="NH4 * E3T"                                unit="mmol/m2"  > NH4 * e3t </field >
+
+      <!-- MEDUSA : variables available with key_medusa -->
+       <field id="CHN"      long_name="Chl-a concentration in non-diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="CHD"      long_name="Chl-a concentration in     diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="PHN"      long_name="non-diatom phytoplankton"                          unit="mmol-N/m3" />
+       <field id="PHD"      long_name="diatom     phytoplankton"                          unit="mmol-N/m3" />
+       <field id="ZMI"      long_name="micro zooplankton"                                 unit="mmol-N/m3" />
+       <field id="ZME"      long_name="meso  zooplankton"                                 unit="mmol-N/m3" />
+       <field id="DIN"      long_name="dissolved inorganic nitrogen"                      unit="mmol-N/m3" />
+       <field id="SIL"      long_name="dissolved silicic acid"                            unit="mmolSi/m3" />
+       <field id="FER"      long_name="dissolved iron"                                    unit="mmolFe/m3" />
+       <field id="DET"      long_name="detrital nitrogen"                                 unit="mmol-N/m3" />
+       <field id="PDS"      long_name="biogenic silicon in diatom phytoplankton"          unit="mmolSi/m3" />
+       <field id="DTC"      long_name="detrital carbon"                                   unit="mmol-C/m3" />
+       <field id="DiC"      long_name="dissolved inorganic carbon"                        unit="mmol-C/m3" />
+       <field id="ALK"      long_name="alkalinity"                                        unit="meq/m3"    />
+       <field id="OXY"      long_name="dissolved oxygen"                                  unit="mmolO2/m3" />
+
+      <!-- Ideal traceurs : variables available with key_idtra -->
+       <field id="IDTRA"    long_name="Ideal traceur concentration "                      unit="mmol/m3"    />
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="Num"         long_name="Number of organic particles"              unit="1" />
+       <field id="Num_E3T"     long_name="Num * E3T"                                unit="m"  > Num * e3t </field >
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="DET"         long_name="Detritus"                                 unit="mmol-N/m3" />
+       <field id="DET_E3T"     long_name="DET * E3T"                                unit="mmol-N/m2"  > DET * e3t </field >
+       <field id="DOM"         long_name="Dissolved Organic Matter"                 unit="mmol-N/m3" />
+       <field id="DOM_E3T"     long_name="DOM * E3T"                                unit="mmol-N/m2"  > DOM * e3t </field >
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="CFC11"       long_name="CFC-11 Concentration"                     unit="umol/m3" />
+       <field id="CFC11_E3T"   long_name="CFC11 * E3T"                              unit="umol/m2"  > CFC11 * e3t </field >
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="C14B"        long_name="Bomb C14 Concentration"                   unit="1"         />
+       <field id="C14B_E3T"    long_name="C14B * E3T"                               unit="m"  > C14B * e3t </field >
+       <!-- AGE : variables available with key_age -->
+       <field id="Age"        long_name="Sea Water Age Since Surface contact" standard_name="sea_water_age_since_surface_contact"  unit="yr"         />
+       <field id="Age_e3t"    long_name="Age * e3t"                                 unit="yr * m"  > Age * e3t </field >
+     </field_group>
+
+     <!-- PISCES additional diagnostics on T grid  -->
+
+     <field_group id="diad_T" grid_ref="grid_T_2D">
+       <field id="PH"          long_name="PH"                                      unit="1"          grid_ref="grid_T_3D" />
+       <field id="CO3"         long_name="Bicarbonates"                            unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="CO3sat"      long_name="CO3 saturation"                          unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="PAR"         long_name="Photosynthetically Available Radiation"  unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PARDM"       long_name="Daily mean PAR"                          unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PPPHY"       long_name="Primary production of nanophyto"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPPHY2"      long_name="Primary production of diatoms"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWN"      long_name="New Primary production of nanophyto"     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWD"      long_name="New Primary production of diatoms"       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PBSi"        long_name="Primary production of Si diatoms"        unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeN"        long_name="Primary production of nano iron"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeD"        long_name="Primary production of diatoms iron"      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="xfracal"     long_name="Calcifying fraction"                     unit="1"          grid_ref="grid_T_3D" />
+       <field id="PCAL"        long_name="Calcite production"                      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DCAL"        long_name="Calcite dissolution"                     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ1"       long_name="Grazing by microzooplankton"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ2"       long_name="Grazing by mesozooplankton"              unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="REMIN"       long_name="Oxic remineralization of OM"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DENIT"       long_name="Anoxic remineralization of OM"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Nfix"        long_name="Nitrogen fixation"                       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Mumax"       long_name="Maximum growth rate"                     unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuN"         long_name="Realized growth rate for nanophyto"      unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuD"         long_name="Realized growth rate for diatomes"       unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="LNnut"       long_name="Nutrient limitation term in Nanophyto"   unit=""           grid_ref="grid_T_3D" />
+       <field id="LDnut"       long_name="Nutrient limitation term in Diatoms"     unit=""           grid_ref="grid_T_3D" />
+       <field id="LNFe"        long_name="Iron limitation term in Nanophyto"       unit=""           grid_ref="grid_T_3D" />
+       <field id="LDFe"        long_name="Iron limitation term in Diatoms"         unit=""           grid_ref="grid_T_3D" />
+       <field id="LNlight"     long_name="Light limitation term in Nanophyto"      unit=""           grid_ref="grid_T_3D" />
+       <field id="LDlight"     long_name="Light limitation term in Diatoms"        unit=""           grid_ref="grid_T_3D" />
+       <field id="Fe2"         long_name="Iron II concentration"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Fe3"         long_name="Iron III concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL1"        long_name="Complexed Iron concentration with L1"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL2"        long_name="Complexed Iron concentration with L2"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeP"         long_name="Precipitated Iron III"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL1"         long_name="Total L1 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL2"         long_name="Total L2 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="pdust"       long_name="dust concentration"                      unit="g/m3"                            />
+       <field id="Totlig"      long_name="Total ligand concentation"               unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Biron"       long_name="Bioavailable iron"                       unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Sdenit"      long_name="Nitrate reduction in the sediments"      unit="mol/m2/s"                        />
+       <field id="Ironice"     long_name="Iron input/uptake due to sea ice"        unit="mol/m2/s"                        />
+       <field id="HYDR"        long_name="Iron input from hydrothemal vents"       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EPC100"      long_name="Export of carbon particles at 100 m"     unit="mol/m2/s"                        />
+       <field id="EPFE100"     long_name="Export of biogenic iron at 100 m"        unit="mol/m2/s"                        />
+       <field id="EPSI100"     long_name="Export of Silicate at 100 m"             unit="mol/m2/s"                        />
+       <field id="EPCAL100"    long_name="Export of Calcite at 100 m"              unit="mol/m2/s"                        />
+       <field id="EXPC"        long_name="Export of carbon"                        unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPFE"       long_name="Export of biogenic iron"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPSI"       long_name="Export of Silicate"                      unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPCAL"      long_name="Export of Calcite"                       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="Cflx"        long_name="DIC flux"                                unit="mol/m2/s"                        />
+       <field id="Oflx"        long_name="Oxygen flux"                             unit="mol/m2/s"                        />
+       <field id="Kg"          long_name="Gas transfer"                            unit="mol/m2/s/uatm"                   />
+       <field id="Dpco2"       long_name="Delta CO2"                               unit="uatm"                            />
+       <field id="Dpo2"        long_name="Delta O2"                                unit="uatm"                            />
+       <field id="Heup"        long_name="Euphotic layer depth"                    unit="m"                               />
+       <field id="Irondep"     long_name="Iron deposition from dust"               unit="mol/m2/s"                        />
+       <field id="Ironsed"     long_name="Iron deposition from sediment"           unit="mol/m2/s"   grid_ref="grid_T_3D" />
+
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="EPN100"      long_name="Particulate number flux at 100 m"        unit="mol/m2/s"                        />
+       <field id="EXPN"        long_name="Particulate number flux"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="XNUM"        long_name="Number of particles in aggregats"        unit="1"          grid_ref="grid_T_3D" />
+       <field id="WSC"         long_name="sinking speed of mass flux"              unit="m2/s"       grid_ref="grid_T_3D" />
+       <field id="WSN"         long_name="sinking speed of number flux"            unit="m2/s"       grid_ref="grid_T_3D" />
+
+       <!-- dbio_T on T grid : variables available with key_diaar5 -->
+       <field id="TPP"         long_name="Total Primary production of phyto"                   unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPNEW"       long_name="New Primary production of phyto"                     unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPBFE"       long_name="Total biogenic iron production"                      unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="INTDIC"      long_name="DIC content"                                         unit="kg/m2"                          />
+       <field id="O2MIN"       long_name="Oxygen minimum concentration"                        unit="mol/m3"                          />
+       <field id="ZO2MIN"      long_name="Depth of oxygen minimum concentration"               unit="m"                              />
+       <field id="INTNFIX"     long_name="Nitrogen fixation rate : vert. integrated"           unit="mol/m2/s"                       />
+       <field id="INTPPPHY"    long_name="Vertically integrated primary production by nanophy" unit="mol/m2/s"                       />
+       <field id="INTPPPHY2"   long_name="Vertically integrated primary production by diatom"  unit="mol/m2/s"                       />
+       <field id="INTPP"       long_name="Vertically integrated primary production by phyto"   unit="mol/m2/s"                       />
+       <field id="INTPNEW"     long_name="Vertically integrated new primary production"        unit="mol/m2/s"                       />
+       <field id="INTPBFE"     long_name="Vertically integrated of biogenic iron production"   unit="mol/m2/s"                       />
+       <field id="INTPBSI"     long_name="Vertically integrated of biogenic Si production"     unit="mol/m2/s"                       />
+       <field id="INTPCAL"     long_name="Vertically integrated of calcite production"         unit="mol/m2/s"                       />
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="FNO3PHY"     long_name="FNO3PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4PHY"     long_name="FNH4PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4NO3"     long_name="FNH4NO3"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="TNO3PHY"     long_name="TNO3PHY"                                 unit=""  /> 
+       <field id="TNH4PHY"     long_name="TNH4PHY"                                 unit=""  /> 
+       <field id="TPHYDOM"     long_name="TPHYDOM"                                 unit=""  /> 
+       <field id="TPHYNH4"     long_name="TPHYNH4"                                 unit=""  /> 
+       <field id="TPHYZOO"     long_name="TPHYZOO"                                 unit=""  /> 
+       <field id="TPHYDET"     long_name="TPHYDET"                                 unit=""  /> 
+       <field id="TDETZOO"     long_name="TDETZOO"                                 unit=""  /> 
+       <field id="TZOODET"     long_name="TZOODET"                                 unit=""  /> 
+       <field id="TZOOBOD"     long_name="TZOOBOD"                                 unit=""  /> 
+       <field id="TZOONH4"     long_name="TZOONH4"                                 unit=""  /> 
+       <field id="TZOODOM"     long_name="TZOODOM"                                 unit=""  /> 
+       <field id="TNH4NO3"     long_name="TNH4NO3"                                 unit=""  /> 
+       <field id="TDOMNH4"     long_name="TDOMNH4"                                 unit=""  /> 
+       <field id="TDETNH4"     long_name="TDETNH4"                                 unit=""  /> 
+       <field id="TPHYTOT"     long_name="TPHYTOT"                                 unit=""  /> 
+       <field id="TZOOTOT"     long_name="TZOOTOT"                                 unit=""  /> 
+       <field id="SEDPOC"      long_name="SEDPOC"                                  unit=""  /> 
+       <field id="TDETSED"     long_name="TDETSED"                                 unit=""  /> 
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="qtrCFC11"    long_name="Air-sea flux of CFC-11"                  unit="mol/m2/s"   />
+       <field id="qintCFC11"   long_name="Cumulative air-sea flux of CFC-11"       unit="mol/m2"     />
+
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="qtrC14b"     long_name="Air-sea flux of Bomb C14"                unit="mol/m2/s"   />
+       <field id="qintC14b"    long_name="Cumulative air-sea flux of Bomb C14"     unit="mol/m2"     />
+       <field id="fdecay"      long_name="Radiactive decay of Bomb C14"            unit="mol/m3"  grid_ref="grid_T_3D"  />
+
+       <!-- IDTRA : variables available with key_idtra -->
+       <field id="qtrIDTRA"    long_name="Air-sea flux of Ideal Tracer"             unit="mol/m2/s"   />
+       <field id="qintIDTRA"   long_name="Cumulative air-sea flux of Ideal Tracer"  unit="mol/m2"     />
+       <field id="invIDTRA"    long_name="Vertical inventory"                       unit="mol/m2"     />
+
+       <!-- MEDUSA additional diagnostics on T grid  -->
+       <field id= "INVTN"      long_name="Column N inventory"                        unit="mmolN/m2"    />
+       <field id= "INVTSI"     long_name="Column Si inventory"                       unit="mmolSi/m2"   />
+       <field id= "INVTFE"     long_name="Column Fe inventory"                       unit="mmolFe/m2"   />
+       <field id= "PRN"        long_name="Non-diatom primary production"             unit="mmolN/m2/d"  />
+       <field id= "MPN"        long_name="Non-diatom non-grazing losses"             unit="mmolN/m2/d"  />
+       <field id= "PRD"        long_name="Diatom primary production"                 unit="mmolN/m2/d"  />
+       <field id= "MPD"        long_name="Diatom non-grazing losses"                 unit="mmolN/m2/d"  />
+       <field id= "DSED"       long_name="Gravitational sinking of Detritus"         unit="mmolN/m2/d"  />
+       <field id= "OPAL"       long_name="Diatom biogenic opal production"           unit="mmolSi/m2/d" />
+       <field id= "OPALDISS"   long_name="Diatom biogenic opal dissolution"          unit="mmolSi/m2/d" />
+       <field id= "GMIPn"      long_name="Microzoo grazing on non-diatoms"           unit="mmolN/m2/d"  />
+       <field id= "GMID"       long_name="Microzoo grazing on detritus"              unit="mmolN/m2/d"  />
+       <field id= "MZMI"       long_name="Microzoo non-grazing losses"               unit="mmolN/m2/d"  />
+       <field id= "GMEPN"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEPD"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEZMI"     long_name="Mesozoo grazing on microzoo"               unit="mmolN/m2/d"  />
+       <field id= "GMED"       long_name="Mesozoo grazing on detritus"               unit="mmolN/m2/d"  />
+       <field id= "MZME"       long_name="Mesozoo non-grazing losses"                unit="mmolN/m2/d"  />
+       <field id= "DEXP"       long_name="Detritus export"                           unit="mmolN/m2/d"  />
+       <field id= "DETN"       long_name="Slow detritus creation"                    unit="mmolN/m2/d"  />
+       <field id= "MDET"       long_name="Detritus non-grazing losses"               unit="MmolN/m2/d"  />
+       <field id= "AEOLIAN"    long_name="Aeolian deposition of iron"                unit="mmolFe/m2/d" />
+       <field id= "BENTHIC"    long_name="Benthic supply of iron"                    unit="mmolFe/m2/d" />
+       <field id= "SCAVENGE"   long_name="Scavenged iron"                            unit="mmolFe/m2/d" />
+       <field id= "PN_JLIM"    long_name="Non-diatom light limitation"               unit="-"           />
+       <field id= "PN_NLIM"    long_name="Non-diatom N limitation"                   unit="-"           />
+       <field id= "PN_FELIM"   long_name="Non-diatom Fe limitation"                  unit="-"           />
+       <field id= "PD_JLIM"    long_name="Diatom light limitation"                   unit="-"           />
+       <field id= "PD_NLIM"    long_name="Diatom N limitation"                       unit="-"           />
+       <field id= "PD_FELIM"   long_name="Diatom Fe limitation"                      unit="-"           />
+       <field id= "PD_SILIM"   long_name="Diatom Si limitation"                      unit="-"           />
+       <field id= "PDSILIM2"   long_name="Diatom Si uptake limitation"               unit="-"           />
+       <field id= "SDT__100"   long_name="Slow detrital flux at  100 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__200"   long_name="Slow detrital flux at  200 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__500"   long_name="Slow detrital flux at  500 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT_1000"   long_name="Slow detrital flux at 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "TOTREG_N"   long_name="Full column regenerated N"                 unit="mmolN/m2/d"  />
+       <field id= "TOTRG_SI"   long_name="Full column regenerated Si"                unit="mmolSi/m2/d" />
+       <field id= "REG__100"   long_name="Regenerated N to  100 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__200"   long_name="Regenerated N to  200 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__500"   long_name="Regenerated N to  500 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG_1000"   long_name="Regenerated N to 1000 m"                   unit="mmolN/m2/d"  />
+       <field id= "FASTN"      long_name="Fast-sinking flux N"                       unit="mmolN/m2/d"  />
+       <field id= "FASTSI"     long_name="Fast-sinking flux Si"                      unit="mmolSi/m2/d" />
+       <field id= "FASTFE"     long_name="Fast-sinking flux Fe"                      unit="mmolFe/m2/d" />
+       <field id= "FASTC"      long_name="Fast-sinking flux C"                       unit="mmolC/m2/d"  />
+       <field id= "FASTCA"     long_name="Fast-sinking flux CaCO3"                   unit="mmolC/m2/d"  />
+       <field id= "FDT__100"   long_name="Fast detrital N flux at  100 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__200"   long_name="Fast detrital N flux at  200 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__500"   long_name="Fast detrital N flux at  500 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT_1000"   long_name="Fast detrital N flux at 1000 m"            unit="mmolN/m2/d"  />
+       <field id= "RG__100F"   long_name="Regenerated fast N to  100 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__200F"   long_name="Regenerated fast N to  200 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__500F"   long_name="Regenerated fast N to  500 m"              unit="mmolN/m2/d"  />
+       <field id= "RG_1000F"   long_name="Regenerated fast N to 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "FDS__100"   long_name="Fast detrital Si flux at  100 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__200"   long_name="Fast detrital Si flux at  200 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__500"   long_name="Fast detrital Si flux at  500 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS_1000"   long_name="Fast detrital Si flux at 1000 m"           unit="mmolSi/m2/d" />
+       <field id= "RGS_100F"   long_name="Regenerated fast Si to  100 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_200F"   long_name="Regenerated fast Si to  200 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_500F"   long_name="Regenerated fast Si to  500 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS1000F"   long_name="Regenerated fast Si to 1000 m"             unit="mmolSi/m2/d" />
+       <field id= "REMINN"     long_name="Fast-sinking remin flux N"                 unit="mmolN/m2/d"  />
+       <field id= "REMINSI"    long_name="Fast-sinking remin flux Si"                unit="mmolSi/m2/d" />
+       <field id= "REMINFE"    long_name="Fast-sinking remin flux Fe"                unit="mmolFe/m2/d" />
+       <field id= "REMINC"     long_name="Fast-sinking remin flux C"                 unit="mmolC/m2/d"  />
+       <field id= "REMINCA"    long_name="Fast-sinking remin flux CaCO3"             unit="mmolC/m2/d"  />
+       <field id= "SEAFLRN"    long_name="Seafloor flux of N"                        unit="mmolN/m2/d"  />
+       <field id= "SEAFLRSI"   long_name="Seafloor flux of Si"                       unit="mmolSi/m2/d" />
+       <field id= "SEAFLRFE"   long_name="Seafloor flux of Fe"                       unit="mmolFe/m2/d" />
+       <field id= "SEAFLRC"    long_name="Seafloor flux of C"                        unit="mmolC/m2/d"  />
+       <field id= "SEAFLRCA"   long_name="Seafloor flux of CaCO3"                    unit="mmolC/m2/d"  />
+       <field id= "MED_QSR"    long_name="Sea surface radiation"                     unit="W/m2"        />
+       <field id= "MED_XPAR"   long_name="Top level radiation"                       unit="W/m2"        />
+       <field id= "INTFLX_N"   long_name="Integrated N  cycle fluxes"                unit="mmolN/m2/d"  />
+       <field id= "INTFLX_SI"  long_name="Integrated Si cycle fluxes"                unit="mmolSi/m2/d" />
+       <field id= "INTFLX_FE"  long_name="Integrated Fe cycle fluxes"                unit="mmolFe/m2/d" />
+       <field id= "INT_PN"     long_name="Vertically integrated Pn"                  unit="mmolN/m2"    />
+       <field id= "INT_PD"     long_name="Vertically integrated Pd"                  unit="mmolN/m2"    />
+       <field id= "ML_PRN"     long_name="Non-diatom mixed layer PP"                 unit="mmolN/m2/d"  />
+       <field id= "ML_PRD"     long_name="Diatom mixed layer PP"                     unit="mmolN/m2/d"  />
+       <field id= "OCAL_CCD"   long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "OCAL_LVL"   long_name="Calcite CCD level"                         unit="-"           />
+       <field id= "FE_0000"    long_name="Free iron at    0m"                        unit="-"           />
+       <field id= "FE_0100"    long_name="Free iron at  100m"                        unit="-"           />
+       <field id= "FE_0200"    long_name="Free iron at  200m"                        unit="-"           />
+       <field id= "FE_0500"    long_name="Free iron at  500m"                        unit="-"           />
+       <field id= "FE_1000"    long_name="Free iron at 1000m"                        unit="-"           />
+       <field id= "MED_XZE"    long_name="Euphotic depth"                            unit="m"           />
+       <field id= "WIND"       long_name="Surface scalar wind"                       unit="m/s"         />
+       <field id= "ATM_PCO2"   long_name="Atmospheric pCO2"                          unit="ppmv"        />
+       <field id= "OCN_PH"     long_name="Surface ocean pH"                          unit="-"           />
+       <field id= "OCN_PCO2"   long_name="Surface ocean pCO2"                        unit="ppmv"        />
+       <field id= "OCNH2CO3"   long_name="Surface ocean H2CO3 conc"                  unit="mmolC/m3"    />
+       <field id= "OCN_HCO3"   long_name="Surface ocean HCO3 conc"                   unit="mmolC/m3"    />
+       <field id= "OCN_CO3"    long_name="Surface ocean CO3 conc"                    unit="mmolC/m3"    />
+       <field id= "CO2FLUX"    long_name="Air-sea CO2 flux"                          unit="mmolC/m2/d"  />
+       <field id= "OM_CAL"     long_name="Omega calcite"                             unit="-"           />
+       <field id= "OM_ARG"     long_name="Omega aragonite"                           unit="-"           />
+       <field id= "TCO2"       long_name="Total CO2"                                 unit="umol/kg"     />
+       <field id= "TALK"       long_name="Total alkalinity"                          unit="ueq/kg"      />
+       <field id= "KW660"      long_name="Piston velocity"                           unit="m/s"         />
+       <field id= "ATM_PP0"    long_name="Atmospheric pressure"                      unit="bar"         />
+       <field id= "O2FLUX"     long_name="Air-sea O2 flux"                           unit="mmolO2/m2/d" />
+       <field id= "O2SAT"      long_name="Surface ocean O2 saturation"               unit="mmolO2/m3"   />
+       <field id= "CAL_CCD"    long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "ARG_CCD"    long_name="Aragonite CCD depth"                       unit="m"           />
+       <field id= "SFR_OCAL"   long_name="Seafloor omega calcite"                    unit="-"           />
+       <field id= "SFR_OARG"   long_name="Seafloor omega aragonite"                  unit="-"           />
+       <field id= "N_PROD"     long_name="Nitrogen production"                       unit="mmolN/m2/d"  />
+       <field id= "N_CONS"     long_name="Nitrogen consumption"                      unit="mmolN/m2/d"  />
+       <field id= "C_PROD"     long_name="Carbon production"                         unit="mmolC/m2/d"  />
+       <field id= "C_CONS"     long_name="Carbon consumption"                        unit="mmolC/m2/d"  />
+       <field id= "O2_PROD"    long_name="Oxygen production"                         unit="mmolO2/m2/d" />
+       <field id= "O2_CONS"    long_name="Oxygen consumption"                        unit="mmolO2/m2/d" />
+       <field id= "O2_ANOX"    long_name="Unrealised oxygen consumption"             unit="mmolO2/m2/d" />
+       <field id= "RR_0100"    long_name="Rain ratio at  100m"                       unit="molC/molC"   />
+       <field id= "RR_0500"    long_name="Rain ratio at  500m"                       unit="molC/molC"   />
+       <field id= "RR_1000"    long_name="Rain ratio at 1000m"                       unit="molC/molC"   />
+       <field id= "IBEN_N"     long_name="Benthic input nitrogen"                    unit="mmolN/m2/d"  />
+       <field id= "IBEN_FE"    long_name="Benthic input iron"                        unit="mmolFe/m2/d" />
+       <field id= "IBEN_C"     long_name="Benthic input carbon"                      unit="mmolC/m2/d"  />
+       <field id= "IBEN_SI"    long_name="Benthic input silicon"                     unit="mmolSi/m2/d" />
+       <field id= "IBEN_CA"    long_name="Benthic input CaCO3"                       unit="mmolC/m2/d"  />
+       <field id= "OBEN_N"     long_name="Benthic output nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "OBEN_FE"    long_name="Benthic output iron"                       unit="mmolFe/m2/d" />
+       <field id= "OBEN_C"     long_name="Benthic output carbon"                     unit="mmolC/m2/d"  />
+       <field id= "OBEN_SI"    long_name="Benthic output silicon"                    unit="mmolSi/m2/d" />
+       <field id= "OBEN_CA"    long_name="Benthic output CaCO3"                      unit="mmolC/m2/d"  />
+       <field id= "BEN_N"      long_name="Benthic nitrogen"                          unit="mmolN/m2"    />
+       <field id= "BEN_FE"     long_name="Benthic iron"                              unit="mmolFe/m2"   />
+       <field id= "BEN_C"      long_name="Benthic carbon"                            unit="mmolC/m2"    />
+       <field id= "BEN_SI"     long_name="Benthic silicon"                           unit="mmolSi/m2"   />
+       <field id= "BEN_CA"     long_name="Benthic CaCO3"                             unit="mmolC/m2"    />
+       <field id= "RUNOFF"     long_name="River runoff"                              unit="m/d"         />
+       <field id= "RIV_N"      long_name="Riverine input nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "RIV_SI"     long_name="Riverine input silicon"                    unit="mmolSi/m2/d" />
+       <field id= "RIV_C"      long_name="Riverine input carbon"                     unit="mmolSi/m2/d" />
+       <field id= "RIV_ALK"    long_name="Riverine input alkalinity"                 unit="meq/m2/d"    />
+       <field id= "DETC"       long_name="Slow detritus C creation"                  unit="mmolC/m2/d"  />
+       <field id= "SDC__100"   long_name="Slow detrital C flux at  100 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__200"   long_name="Slow detrital C flux at  200 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__500"   long_name="Slow detrital C flux at  500 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC_1000"   long_name="Slow detrital C flux at 1000 m"            unit="mmolC/m2/d"  />
+       <field id= "INVTC"      long_name="Column C inventory"                        unit="mmolC/m2"    />
+       <field id= "INVTALK"    long_name="Column alkalinity inventory"               unit="meq/m2"      />
+       <field id= "INVTO2"     long_name="Column O2 inventory"                       unit="mmolO2/m2"   />
+       <field id= "LYSO_CA"    long_name="Incorrect benthic output CaCO3"            unit="mmolC/m2/d"  />
+       <field id= "COM_RESP"   long_name="Community respiration"                     unit="mmolC/m2/d"  />
+       <field id= "PN_LLOSS"   long_name="Non-diatom linear losses"                  unit="mmolN/m2/d"  />
+       <field id= "PD_LLOSS"   long_name="Diatom linear losses"                      unit="mmolN/m2/d"  />
+       <field id= "ZI_LLOSS"   long_name="Microzooplankton linear losses"            unit="mmolN/m2/d"  />
+       <field id= "ZE_LLOSS"   long_name="Mesozooplankton linear losses"             unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_N"   long_name="Microzoo messy feeding loss to N"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_D"   long_name="Microzoo messy feeding loss to D"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_C"   long_name="Microzoo messy feeding loss to C"          unit="mmolC/m2/d"  />
+       <field id= "ZI_MESDC"   long_name="Microzoo messy feeding loss to Dc"         unit="mmolC/m2/d"  />
+       <field id= "ZI_EXCR"    long_name="Microzoo excretion"                        unit="mmolN/m2/d"  />
+       <field id= "ZI_RESP"    long_name="Microzoo respiration"                      unit="mmolC/m2/d"  />
+       <field id= "ZI_GROW"    long_name="Microzoo growth"                           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_N"   long_name="Mesozoo messy feeding loss to N"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_D"   long_name="Mesozoo messy feeding loss to D"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_C"   long_name="Mesozoo messy feeding loss to C"           unit="mmolC/m2/d"  />
+       <field id= "ZE_MESDC"   long_name="Mesozoo messy feeding loss to Dc"          unit="mmolC/m2/d"  />
+       <field id= "ZE_EXCR"    long_name="Mesozoo excretion"                         unit="mmolN/m2/d"  />
+       <field id= "ZE_RESP"    long_name="Mesozoo respiration"                       unit="mmolC/m2/d"  />
+       <field id= "ZE_GROW"    long_name="Mesozoo growth"                            unit="mmolN/m2/d"  />
+       <field id= "MDETC"      long_name="Detritus non-grazing losses, carbon"       unit="mmolC/m2/d"  />
+       <field id= "GMIDC"      long_name="Microzoo grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "GMEDC"      long_name="Mesozoo  grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "INT_ZMI"    long_name="Vertically integrated Zmi"                 unit="mmolN/m2"    />
+       <field id= "INT_ZME"    long_name="Vertically integrated Zme"                 unit="mmolN/m2"    />
+       <field id= "INT_DET"    long_name="Vertically integrated Det"                 unit="mmolN/m2"    />
+       <field id= "INT_DTC"    long_name="Vertically integrated Dtc"                 unit="mmolC/m2"    />
+       <field id= "DMS_SURF"   long_name="DMS Surface Concentration"                 unit="nmol/L"      />
+       <field id= "DMS_ANDR"   long_name="DMS Surface Concentration, Anderson"       unit="nmol/L"      />
+       <field id= "DMS_SIMO"   long_name="DMS Surface Concentration, SimoDach"       unit="nmol/L"      />
+       <field id= "DMS_ARAN"   long_name="DMS Surface Concentration, AranamiT"       unit="nmol/L"      />
+       <field id= "DMS_HALL"   long_name="DMS Surface Concentration, Halloran"       unit="nmol/L"      />
+
+       <!-- AXY (08/11/16): add new 2D CMIP6 diagnostics -->
+       <field id= "epC100"     long_name="Downward Flux of Particle Organic Carbon"  unit="mmolC/m2/d"  />
+       <field id= "epCALC100"  long_name="Downward Flux of Calcite"                  unit="mmolC/m2/d"  />
+       <field id= "epN100"     long_name="Downward Flux of Particulate Nitrogen"     unit="mmolN/m2/d"  />
+       <field id= "epSI100"    long_name="Downward Flux of Particulate Silica"       unit="mmolSi/m2/d" />
+       <field id= "FGCO2"      long_name="Surface Downward CO2 Flux"                 unit="kg/m2/s"     />
+       <field id= "INTDISSIC"  long_name="Dissolved Inorganic Carbon Content"        unit="mmolC/m2"    />
+       <field id= "INTDISSIN"  long_name="Dissolved Inorganic Nitrogen Content"      unit="mmolN/m2"    />
+       <field id= "INTDISSISI" long_name="Dissolved Inorganic Silicon Content"       unit="mmolSi/m2"   />
+       <field id= "INTALK"     long_name="Dissolved Alkalinity Content"              unit="meq/m2"      />
+       <field id= "O2min"      long_name="Oxygen Minimum Concentration"              unit="mmolO2/m3"   />
+       <field id= "ZO2min"     long_name="Depth of Oxygen Minimum Concentration"     unit="m"           />
+
+       <field id= "TPP3"       long_name="Total primary production 3D"               unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "DETFLUX3"   long_name="Total detrital flux 3D"                    unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMIN3N"    long_name="Total remin flux N 3D"                     unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PH3"        long_name="Ocean pH 3D"                               unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "OM_CAL3"    long_name="Omega calcite 3D"                          unit="-"             grid_ref="grid_T_3D"  />
+
+       <!-- AXY (08/11/16): add new 3D CMIP6 diagnostics -->
+       <field id= "TPPD3"      long_name="Diatom primary production 3D"              unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTALK3"   long_name="Change of Alkalinity due to Biology"       unit="meq/m3/d"      grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIC3"   long_name="Change of DI Carbon due to Biology"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTIFE3"   long_name="Change of DI Iron due to Biology"          unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIN3"   long_name="Change of DI Nitrogen due to Biology"      unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTDISI3"  long_name="Change of DI Silicon due to Biology"       unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_NIT3"    long_name="Fast sinking detrital nitrogen"            unit="mmolN/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_SIL3"    long_name="Fast sinking detrital silicon"             unit="mmolSi/m2/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_CAR3"    long_name="Fast sinking detrital carbon"              unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_CAL3"    long_name="Fast sinking detrital calcium carbonate"   unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "CO33"       long_name="Carbonate ion concentration"               unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATARG3" long_name="Carbonate aragonite saturation conc"       unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATCAL3" long_name="Carbonate calcite saturation conc"         unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "DCALC3"     long_name="Calcite dissolution"                       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPC3"      long_name="Downward Flux of Particulate Org Carbon"   unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPN3"      long_name="Downward Flux of Particulate Org Nitrogen" unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "FEDISS3"    long_name="Particle Source of Dissolved Iron"         unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FESCAV3"    long_name="Nonbiogenic Iron Scavenging"               unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZP3"   long_name="Microzooplankton grazing on phytoplankton" unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZD3"   long_name="Microzooplankton grazing on detritus"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZP3"   long_name="Mesozooplankton grazing on phytoplankton"  unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZD3"   long_name="Mesozooplankton grazing on detritus"       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZZ3"   long_name="Mesozooplankton grazing on microzoop"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "O2SAT3"     long_name="Dissolved Oxygen Saturation Concentration" unit="mmolO2/m3"     grid_ref="grid_T_3D"  />
+       <field id= "PBSI3"      long_name="Biogenic Silica Production"                unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "PCAL3"      long_name="Biogenic Calcite Production"               unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMOC3"     long_name="Remineralization of Organic Carbon"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PNLIMJ3"    long_name="Irradiance limitation of non-diatoms"      unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMN3"    long_name="Nitrogen limitation of non-diatoms"        unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMFE3"   long_name="Iron limitation of non-diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMJ3"    long_name="Irradiance limitation of diatoms"          unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMN3"    long_name="Nitrogen limitation of diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMFE3"   long_name="Iron limitation of diatoms"                unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMSI3"   long_name="Silicon limitation of diatoms"             unit="-"             grid_ref="grid_T_3D"  />
+
+     </field_group>
+
+     <field_group id="PISCES_scalar"  domain_ref="1point" >
+       <field id="pno3tot"         long_name="global mean nitrate concentration"                  unit="mol/m3"   />
+       <field id="ppo4tot"         long_name="global mean phosphorus concentration"               unit="mol/m3"   />
+       <field id="psiltot"         long_name="global mean silicate concentration"                 unit="mol/m3"   />
+       <field id="palktot"         long_name="global mean alkalinity concentration"               unit="mol/m3"   />
+       <field id="pfertot"         long_name="global mean iron concentration"                     unit="mol/m3"   />
+       <field id="tcflx"           long_name="total Flux of Carbon out of the ocean"              unit="mol/s"   />
+       <field id="tcflxcum"        long_name="cumulative total Flux of Carbon out of the ocean"   unit="mol/s"   />
+       <field id="tcexp"           long_name="total Carbon export at 100m"                        unit="mol/s"   />
+       <field id="tintpp"          long_name="global total integrated primary production"         unit="mol/s"   />
+       <field id="tnfix"           long_name="global total nitrogen fixation"                     unit="mol/s"   />
+       <field id="tdenit"          long_name="Total denitrification"                              unit="mol/s"   />
+     </field_group>
+
+    <!-- 
+============================================================================================================
+                                        Definitions for iodef_demo.xml
+============================================================================================================
+    -->
+
+    <field_group id="groupMEDUSA" >
+      <field field_ref="CHN"   name="CHN"   />
+      <field field_ref="CHD"   name="CHD"   />
+      <field field_ref="PHN"   name="PHN"   />
+      <field field_ref="PHD"   name="PHD"   />
+      <field field_ref="ZMI"   name="ZMI"   />
+      <field field_ref="ZME"   name="ZME"   />
+      <field field_ref="DIN"   name="DIN"   />
+      <field field_ref="SIL"   name="SIL"   />
+      <field field_ref="FER"   name="FER"   />
+      <field field_ref="DET"   name="DET"   />
+      <field field_ref="PDS"   name="PDS"   />
+      <field field_ref="DTC"   name="DTC"   />
+      <field field_ref="DiC"   name="DIC"   />
+      <field field_ref="ALK"   name="ALK"   />
+      <field field_ref="OXY"   name="OXY"   />
+      </field_group>
+
+    <field_group id="groupIDTRA" >
+      <field field_ref="IDTRA" name="IDTRA" />
+    </field_group>
+
+    <field_group id="groupIDTRA_dia" >
+      <field field_ref="qtrIDTRA"    name="qtrIDTRA"  />
+      <field field_ref="qintIDTRA"   name="qintIDTRA" />
+      <field field_ref="invIDTRA"    name="invIDTRA"  />
+    </field_group>
+
+    <field_group id="groupCFC" >
+      <field field_ref="CFC11" name="CFC11" />
+    </field_group>
+
+    <field_group id="groupCFC_dia" >
+      <field field_ref="qtrCFC11"    name="qtrCFC11"   />
+      <field field_ref="qintCFC11"   name="qintCFC11"  />
+    </field_group>
+
+    <field_group id="groupAGE" >
+      <field field_ref="Age" name="Age" />
+    </field_group>
+
+    <field_group id="groupMEDUSA_dia" >
+      <field field_ref= "INVTN"      name="INVTN"      />
+      <field field_ref= "INVTSI"     name="INVTSI"     />
+      <field field_ref= "INVTFE"     name="INVTFE"     />
+      <field field_ref= "PRN"        name="PRN"        />
+      <field field_ref= "MPN"        name="MPN"        />
+      <field field_ref= "PRD"        name="PRD"        />
+      <field field_ref= "MPD"        name="MPD"        />
+      <field field_ref= "OPAL"       name="OPAL"       />
+      <field field_ref= "OPALDISS"   name="OPALDISS"   />
+      <field field_ref= "GMIPn"      name="GMIPn"      />
+      <field field_ref= "GMID"       name="GMID"       />
+      <field field_ref= "MZMI"       name="MZMI"       />
+      <field field_ref= "GMEPN"      name="GMEPN"      />
+      <field field_ref= "GMEPD"      name="GMEPD"      />
+      <field field_ref= "GMEZMI"     name="GMEZMI"     />
+      <field field_ref= "GMED"       name="GMED"       />
+      <field field_ref= "MZME"       name="MZME"       />
+      <field field_ref= "DETN"       name="DETN"       />
+      <field field_ref= "MDET"       name="MDET"       />
+      <field field_ref= "AEOLIAN"    name="AEOLIAN"    />
+      <field field_ref= "BENTHIC"    name="BENTHIC"    />
+      <field field_ref= "SCAVENGE"   name="SCAVENGE"   />
+      <field field_ref= "PN_JLIM"    name="PN_JLIM"    />
+      <field field_ref= "PN_NLIM"    name="PN_NLIM"    />
+      <field field_ref= "PN_FELIM"   name="PN_FELIM"   />
+      <field field_ref= "PD_JLIM"    name="PD_JLIM"    />
+      <field field_ref= "PD_NLIM"    name="PD_NLIM"    />
+      <field field_ref= "PD_FELIM"   name="PD_FELIM"   />
+      <field field_ref= "PD_SILIM"   name="PD_SILIM"   />
+      <field field_ref= "PDSILIM2"   name="PDSILIM2"   />
+      <field field_ref= "SDT__100"   name="SDT__100"   />
+      <field field_ref= "SDT__200"   name="SDT__200"   />
+      <field field_ref= "SDT__500"   name="SDT__500"   />
+      <field field_ref= "SDT_1000"   name="SDT_1000"   />
+      <field field_ref= "TOTREG_N"   name="TOTREG_N"   />
+      <field field_ref= "TOTRG_SI"   name="TOTRG_SI"   />
+      <field field_ref= "REG__100"   name="REG__100"   />
+      <field field_ref= "REG__200"   name="REG__200"   />
+      <field field_ref= "REG__500"   name="REG__500"   />
+      <field field_ref= "REG_1000"   name="REG_1000"   />
+      <field field_ref= "FASTN"      name="FASTN"      />
+      <field field_ref= "FASTSI"     name="FASTSI"     />
+      <field field_ref= "FASTFE"     name="FASTFE"     />
+      <field field_ref= "FASTC"      name="FASTC"      />
+      <field field_ref= "FASTCA"     name="FASTCA"     />
+      <field field_ref= "FDT__100"   name="FDT__100"   />
+      <field field_ref= "FDT__200"   name="FDT__200"   />
+      <field field_ref= "FDT__500"   name="FDT__500"   />
+      <field field_ref= "FDT_1000"   name="FDT_1000"   /> 
+      <field field_ref= "RG__100F"   name="RG__100F"   />
+      <field field_ref= "RG__200F"   name="RG__200F"   />
+      <field field_ref= "RG__500F"   name="RG__500F"   />
+      <field field_ref= "RG_1000F"   name="RG_1000F"   />
+      <field field_ref= "FDS__100"   name="FDS__100"   />
+      <field field_ref= "FDS__200"   name="FDS__200"   />
+      <field field_ref= "FDS__500"   name="FDS__500"   />
+      <field field_ref= "FDS_1000"   name="FDS_1000"   />
+      <field field_ref= "RGS_100F"   name="RGS_100F"   />
+      <field field_ref= "RGS_200F"   name="RGS_200F"   />
+      <field field_ref= "RGS_500F"   name="RGS_500F"   />
+      <field field_ref= "RGS1000F"   name="RGS1000F"   />
+      <field field_ref= "REMINN"     name="REMINN"     />
+      <field field_ref= "REMINSI"    name="REMINSI"    />
+      <field field_ref= "REMINFE"    name="REMINFE"    />
+      <field field_ref= "SEAFLRN"    name="SEAFLRN"    /> 
+      <field field_ref= "SEAFLRSI"   name="SEAFLRSI"   />
+      <field field_ref= "SEAFLRFE"   name="SEAFLRFE"   />
+      <field field_ref= "SEAFLRC"    name="SEAFLRC"    />
+      <field field_ref= "SEAFLRCA"   name="SEAFLRCA"   />
+      <field field_ref= "MED_QSR"    name="MED_QSR"    />
+      <field field_ref= "MED_XPAR"   name="MED_XPAR"   />
+      <field field_ref= "INTFLX_N"   name="INTFLX_N"   />
+      <field field_ref= "INTFLX_SI"  name="INTFLX_SI"  />
+      <field field_ref= "INTFLX_FE"  name="INTFLX_FE"  />
+      <field field_ref= "INT_PN"     name="INT_PN"     />
+      <field field_ref= "INT_PD"     name="INT_PD"     />
+      <field field_ref= "ML_PRN"     name="ML_PRN"     />
+      <field field_ref= "ML_PRD"     name="ML_PRD"     />
+      <field field_ref= "OCAL_CCD"   name="OCAL_CCD"   />
+      <field field_ref= "OCAL_LVL"   name="OCAL_LVL"   />
+      <field field_ref= "FE_0000"    name="FE_0000"    />
+      <field field_ref= "FE_0100"    name="FE_0100"    />
+      <field field_ref= "FE_0200"    name="FE_0200"    /> 
+      <field field_ref= "FE_0500"    name="FE_0500"    />
+      <field field_ref= "FE_1000"    name="FE_1000"    />
+      <field field_ref= "MED_XZE"    name="MED_XZE"    />
+      <field field_ref= "WIND"       name="WIND"       />
+      <field field_ref= "ATM_PCO2"   name="ATM_PCO2"   />
+      <field field_ref= "OCN_PH"     name="OCN_PH"     />
+      <field field_ref= "OCN_PCO2"   name="OCN_PCO2"   />
+      <field field_ref= "OCNH2CO3"   name="OCNH2CO3"   />
+      <field field_ref= "OCN_HCO3"   name="OCN_HCO3"   />
+      <field field_ref= "OCN_CO3"    name="OCN_CO3"    />
+      <field field_ref= "CO2FLUX"    name="CO2FLUX"    />
+      <field field_ref= "OM_CAL"     name="OM_CAL"     />
+      <field field_ref= "OM_ARG"     name="OM_ARG"     />
+      <field field_ref= "TCO2"       name="TCO2"       />
+      <field field_ref= "TALK"       name="TALK"       />
+      <field field_ref= "KW660"      name="KW660"      />
+      <field field_ref= "ATM_PP0"    name="ATM_PP0"    />
+      <field field_ref= "O2FLUX"     name="O2FLUX"     />
+      <field field_ref= "O2SAT"      name="O2SAT"      />
+      <field field_ref= "CAL_CCD"    name="CAL_CCD"    />
+      <field field_ref= "ARG_CCD"    name="ARG_CCD"    />
+      <field field_ref= "SFR_OCAL"   name="SFR_OCAL"   />
+      <field field_ref= "SFR_OARG"   name="SFR_OARG"   />
+      <field field_ref= "N_PROD"     name="N_PROD"     />
+      <field field_ref= "N_CONS"     name="N_CONS"     />
+      <field field_ref= "C_PROD"     name="C_PROD"     />
+      <field field_ref= "C_CONS"     name="C_CONS"     />
+      <field field_ref= "O2_PROD"    name="O2_PROD"    />
+      <field field_ref= "O2_CONS"    name="O2_CONS"    />
+      <field field_ref= "O2_ANOX"    name="O2_ANOX"    />
+      <field field_ref= "RR_0100"    name="RR_0100"    />
+      <field field_ref= "RR_0500"    name="RR_0500"    />
+      <field field_ref= "RR_1000"    name="RR_1000"    />
+      <field field_ref= "IBEN_N"     name="IBEN_N"     />
+      <field field_ref= "IBEN_FE"    name="IBEN_FE"    />
+      <field field_ref= "IBEN_C"     name="IBEN_C"     />
+      <field field_ref= "IBEN_SI"    name="IBEN_SI"    />
+      <field field_ref= "IBEN_CA"    name="IBEN_CA"    />
+      <field field_ref= "OBEN_N"     name="OBEN_N"     />
+      <field field_ref= "OBEN_FE"    name="OBEN_FE"    />
+      <field field_ref= "OBEN_C"     name="OBEN_C"     />
+      <field field_ref= "OBEN_SI"    name="OBEN_SI"    />
+      <field field_ref= "OBEN_CA"    name="OBEN_CA"    />
+      <field field_ref= "BEN_N"      name="BEN_N"      />
+      <field field_ref= "BEN_FE"     name="BEN_FE"     />
+      <field field_ref= "BEN_C"      name="BEN_C"      />
+      <field field_ref= "BEN_SI"     name="BEN_SI"     />
+      <field field_ref= "BEN_CA"     name="BEN_CA"     />
+      <field field_ref= "DETC"       name="DETC"       />
+      <field field_ref= "SDC__100"   name="SDC__100"   />
+      <field field_ref= "SDC__200"   name="SDC__200"   />
+      <field field_ref= "SDC__500"   name="SDC__500"   />
+      <field field_ref= "SDC_1000"   name="SDC_1000"   />
+      <field field_ref= "INVTC"      name="INVTC"      />
+      <field field_ref= "INVTALK"    name="INVTALK"    />
+      <field field_ref= "INVTO2"     name="INVTO2"     />
+      <field field_ref= "LYSO_CA"    name="LYSO_CA"    />
+      <field field_ref= "COM_RESP"   name="COM_RESP"   />
+      <field field_ref= "PN_LLOSS"   name="PN_LLOSS"   />
+      <field field_ref= "PD_LLOSS"   name="PD_LLOSS"   />
+      <field field_ref= "ZI_LLOSS"   name="ZI_LLOSS"   />
+      <field field_ref= "ZE_LLOSS"   name="ZE_LLOSS"   />
+      <field field_ref= "ZI_MES_N"   name="ZI_MES_N"   />
+      <field field_ref= "ZI_MES_D"   name="ZI_MES_D"   />
+      <field field_ref= "ZI_MES_C"   name="ZI_MES_C"   />
+      <field field_ref= "ZI_MESDC"   name="ZI_MESDC"   />
+      <field field_ref= "ZI_EXCR"    name="ZI_EXCR"    />
+      <field field_ref= "ZI_RESP"    name="ZI_RESP"    />
+      <field field_ref= "ZI_GROW"    name="ZI_GROW"    />
+      <field field_ref= "ZE_MES_N"   name="ZE_MES_N"   />
+      <field field_ref= "ZE_MES_D"   name="ZE_MES_D"   />
+      <field field_ref= "ZE_MES_C"   name="ZE_MES_C"   />
+      <field field_ref= "ZE_MESDC"   name="ZE_MESDC"   />
+      <field field_ref= "ZE_EXCR"    name="ZE_EXCR"    />
+      <field field_ref= "ZE_RESP"    name="ZE_RESP"    />
+      <field field_ref= "ZE_GROW"    name="ZE_GROW"    />
+      <field field_ref= "MDETC"      name="MDETC"      />
+      <field field_ref= "GMIDC"      name="GMIDC"      />
+      <field field_ref= "GMEDC"      name="GMEDC"      />
+      <field field_ref= "INT_ZMI"    name="INT_ZMI"    />
+      <field field_ref= "INT_ZME"    name="INT_ZME"    />
+      <field field_ref= "INT_DET"    name="INT_DET"    />
+      <field field_ref= "INT_DTC"    name="INT_DTC"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_3dd" >
+      <field field_ref= "TPP3"       name="TPP3"       />
+      <field field_ref= "DETFLUX3"   name="DETFLUX3"   />
+      <field field_ref= "REMIN3N"    name="REMIN3N"    />
+      <field field_ref= "PH3"        name="PH3"        />
+      <field field_ref= "OM_CAL3"    name="OM_CAL3"    /> 
+    </field_group>
+
+    <field_group id="groupMEDUSA_dms" >
+      <field field_ref= "DMS_SURF"   name="DMS_SURF"   />
+      <field field_ref= "DMS_ANDR"   name="DMS_ANDR"   />
+      <field field_ref= "DMS_SIMO"   name="DMS_SIMO"   />
+      <field field_ref= "DMS_ARAN"   name="DMS_ARAN"   />
+      <field field_ref= "DMS_HALL"   name="DMS_HALL"   />
+    </field_group>
+
+    <field_group id="groupMEDUSA_riv" >
+      <field field_ref= "RUNOFF"     name="RUNOFF"     />
+      <field field_ref= "RIV_N"      name="RIV_N"      />
+      <field field_ref= "RIV_SI"     name="RIV_SI"     />
+      <field field_ref= "RIV_C"      name="RIV_C"      />
+      <field field_ref= "RIV_ALK"    name="RIV_ALK"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_cmip6" >
+      <field field_ref= "epC100"     name="epC100"     />
+      <field field_ref= "epCALC100"  name="epCALC100"  />
+      <field field_ref= "epN100"     name="epN100"     />
+      <field field_ref= "epSI100"    name="epSI100"    />
+      <field field_ref= "FGCO2"      name="FGCO2"      />
+      <field field_ref= "INTDISSIC"  name="INTDISSIC"  />
+      <field field_ref= "INTDISSIN"  name="INTDISSIN"  />
+      <field field_ref= "INTDISSISI" name="INTDISSISI" />
+      <field field_ref= "INTALK"     name="INTALK"     />
+      <field field_ref= "O2min"      name="O2min"      />
+      <field field_ref= "ZO2min"     name="ZO2min"     />
+      <field field_ref= "TPPD3"      name="TPPD3"      />
+      <field field_ref= "BDDTALK3"   name="BDDTALK3"   />
+      <field field_ref= "BDDTDIC3"   name="BDDTDIC3"   />
+      <field field_ref= "BDDTIFE3"   name="BDDTIFE3"   />
+      <field field_ref= "BDDTDIN3"   name="BDDTDIN3"   />
+      <field field_ref= "BDDTDISI3"  name="BDDTDISI3"  />
+      <field field_ref= "FD_NIT3"    name="FD_NIT3"    />
+      <field field_ref= "FD_SIL3"    name="FD_SIL3"    />
+      <field field_ref= "FD_CAR3"    name="FD_CAR3"    />
+      <field field_ref= "FD_CAL3"    name="FD_CAL3"    />
+      <field field_ref= "CO33"       name="CO33"       />
+      <field field_ref= "CO3SATARG3" name="CO3SATARG3" />
+      <field field_ref= "CO3SATCAL3" name="CO3SATCAL3" />
+      <field field_ref= "DCALC3"     name="DCALC3"     />
+      <field field_ref= "EXPC3"      name="EXPC3"      />
+      <field field_ref= "EXPN3"      name="EXPN3"      />
+      <field field_ref= "FEDISS3"    name="FEDISS3"    />
+      <field field_ref= "FESCAV3"    name="FESCAV3"    />
+      <field field_ref= "MIGRAZP3"   name="MIGRAZP3"   />
+      <field field_ref= "MIGRAZD3"   name="MIGRAZD3"   />
+      <field field_ref= "MEGRAZP3"   name="MEGRAZP3"   />
+      <field field_ref= "MEGRAZD3"   name="MEGRAZD3"   />
+      <field field_ref= "MEGRAZZ3"   name="MEGRAZZ3"   />
+      <field field_ref= "O2SAT3"     name="O2SAT3"     />
+      <field field_ref= "PBSI3"      name="PBSI3"      />
+      <field field_ref= "PCAL3"      name="PCAL3"      />
+      <field field_ref= "REMOC3"     name="REMOC3"     />
+      <field field_ref= "PNLIMJ3"    name="PNLIMJ3"    />
+      <field field_ref= "PNLIMN3"    name="PNLIMN3"    />
+      <field field_ref= "PNLIMFE3"   name="PNLIMFE3"   />
+      <field field_ref= "PDLIMJ3"    name="PDLIMJ3"    />
+      <field field_ref= "PDLIMN3"    name="PDLIMN3"    />
+      <field field_ref= "PDLIMFE3"   name="PDLIMFE3"   />
+      <field field_ref= "PDLIMSI3"   name="PDLIMSI3"   />
+    </field_group>
+
+</field_definition>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/iodef_medusa_et_al.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/iodef_medusa_et_al.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/XIOS2/iodef_medusa_et_al.xml	(revision 7693)
@@ -0,0 +1,249 @@
+<!-- GO6.0 version of the XIOS namelist -->
+<!-- XIOS2 version namelist -->
+
+<?xml version="1.0"?>
+<simulation> 
+
+ <context id="nemo" >
+    
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+    <field_definition src="./field_def.xml"/>
+    <field_definition src="./field_def_bgc.xml"/>
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".FALSE."> <!-- 6h files -->
+        <file id="file8" name_suffix="_UK_shelf" description="Forcings for the UK shelf seas model" >
+          <field field_ref="toce"         name="votemper"     grid_ref="grid_T_3D_zoom"    operation="instant" standard_name="sea_water_potential_temperature"/> 
+          <field field_ref="soce"         name="vosaline"     grid_ref="grid_T_3D_zoom"    operation="instant" standard_name="sea_water_salinity"/>   
+          <field field_ref="ssh"          name="sossheig"     grid_ref="grid_T_2D_zoom"    operation="instant" standard_name="sea_surface_height_above_geoid"/>
+          <field field_ref="uoce"         name="vozocrtx"     grid_ref="grid_U_3D_zoom"    operation="instant" standard_name="sea_water_x_velocity"/>
+          <field field_ref="voce"         name="vomecrty"     grid_ref="grid_V_3D_zoom"    operation="instant" standard_name="sea_water_y_velocity"/>
+          <field field_ref="ubar"         name="ubar"         grid_ref="grid_U_3D_zoom"    operation="instant" standard_name="ocean_barotropic_current_along_i-axis"/>
+          <field field_ref="vbar"         name="vbar"         grid_ref="grid_V_3D_zoom"    operation="instant" standard_name="ocean_barotropic_current_along_j-axis"/>
+        </file>
+      </file_group>
+     
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+
+      <file_group id="10d" output_freq="10d"  output_level="10" enabled=".TRUE.">  <!-- 10d files -->   
+    
+	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+          <field_group group_ref="SPIN-UP_T" />
+	</file>
+	
+	<file id="file2" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field_group group_ref="SPIN-UP_U" />	
+	</file>
+	
+	<file id="file3" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field_group group_ref="SPIN-UP_V" />
+	</file>
+
+	<file id="file4" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field_group group_ref="SPIN-UP_W" />
+	</file>
+	
+	<file id="file5" name_suffix="_diaptr" description="process diagnostics" >
+          <field_group group_ref="SPIN-UP_diaptr" />
+	</file>	
+	
+        <file id="file6" name_suffix="_ptrc_T" description="Medusa sms variables" >
+          <field_group group_ref="groupMEDUSA" />
+          <field_group group_ref="groupIDTRA" />
+          <field_group group_ref="groupCFC" />
+        </file>
+
+        <file id="file7" name_suffix="_diad_T" description="Medusa diagnostic variables" >
+          <field_group group_ref="groupMEDUSA_dia" /> 
+          <field_group group_ref="groupMEDUSA_3dd" /> 
+          <field_group group_ref="groupMEDUSA_dms" />
+          <field_group group_ref="groupIDTRA_dia" />
+          <field_group group_ref="groupCFC_dia" />
+        </file>
+       
+      </file_group>
+      
+  
+      <!-- file_group id="1m" output_freq="1mo" split_freq="1mo" output_level="10" enabled=".TRUE." -->  <!-- 1mo files -->   
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".FALSE.">  <!-- 1mo files -->   
+
+        <file id="file9" name_suffix="_grid_T" description="ocean T grid variables" >
+          <field_group group_ref="SPIN-UP_T" />
+	</file>
+	
+	<file id="file10" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field_group group_ref="SPIN-UP_U" />
+	</file>
+	
+	<file id="file11" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field_group group_ref="SPIN-UP_V" />
+	</file>
+	
+	<file id="file12" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field_group group_ref="SPIN-UP_W" />
+	</file>
+	
+	<file id="file13" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field_group group_ref="SPIN-UP_diaptr" />
+	</file>
+	
+        <file id="file14" name_suffix="_ptrc_T" description="Medusa sms variables" >
+          <field_group group_ref="groupMEDUSA" />
+          <field_group group_ref="groupIDTRA" />
+          <field_group group_ref="groupCFC" />
+        </file>
+
+        <file id="file15" name_suffix="_diad_T" description="Medusa diagnostic variables" >
+          <field_group group_ref="groupMEDUSA_dia" /> 
+          <field_group group_ref="groupMEDUSA_3dd" /> 
+          <field_group group_ref="groupMEDUSA_dms" />
+          <field_group group_ref="groupIDTRA_dia" />
+          <field_group group_ref="groupCFC_dia" />
+        </file>
+
+      </file_group>
+
+      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real yearly files -->
+      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
+    
+    <!-- 
+============================================================================================================
+= grid definition = = DO NOT CHANGE =
+============================================================================================================
+    -->
+
+   <axis_definition>
+      <axis id="deptht" standard_name="depth" long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu" standard_name="depth" long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv" standard_name="depth" long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw" standard_name="depth" long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat" long_name="Float number"      unit="-"  />
+      <axis id="icbcla" long_name="Iceberg class"     unit="-"  />
+   </axis_definition>
+    
+   <domain_definition src="./domain_def.xml"/>
+   
+   
+  <grid_definition>
+        <!--  -->
+       <grid id="grid_T_2D" >
+         <domain id="grid_T" />
+       </grid>
+        <!--  -->
+       <grid id="grid_T_3D_ncatice" >
+         <domain id="grid_T" />
+         <axis id="ncatice" />
+       </grid>
+        <!--  -->
+       <grid id="grid_T_3D" >
+         <domain id="grid_T" />
+         <axis id="deptht" />
+       </grid>
+        <!--  -->
+       <grid id="grid_U_2D" >
+         <domain id="grid_U" />
+       </grid>
+        <!--  -->
+       <grid id="grid_U_3D" >
+         <domain id="grid_U" />
+         <axis id="depthu" />
+       </grid>
+        <!--  -->
+       <grid id="grid_V_2D" >
+         <domain id="grid_V" />
+       </grid>
+        <!--  -->
+       <grid id="grid_V_3D" >
+         <domain id="grid_V" />
+         <axis id="depthv" />
+       </grid>
+        <!--  -->
+       <grid id="grid_W_2D" >
+         <domain id="grid_W" />
+       </grid>
+        <!--  -->
+       <grid id="grid_W_3D" >
+         <domain id="grid_W" />
+         <axis id="depthw" />
+       </grid>
+        <!--  -->
+       <grid id="grid_1point" >
+         <domain domain_ref="1point"/>
+       </grid>
+        <!--  -->
+       <grid id="grid_T_nfloat" >
+         <domain id="grid_T" />
+         <axis id="nfloat" />
+       </grid>
+        <!--  -->
+       <grid id="grid_EqT" >
+         <domain domain_ref="EqT" />
+       </grid>
+        <!--  -->
+       <grid id="gznl_T_2D">
+         <domain domain_ref="ptr" />
+       </grid>
+        <!--  -->
+       <grid id="gznl_T_3D">
+         <domain domain_ref="ptr" />
+         <axis id="deptht" />
+       </grid>
+        <!--  -->
+       <grid id="gznl_W_2D">
+         <domain domain_ref="ptr" />
+       </grid>
+        <!--  -->
+       <grid id="gznl_W_3D">
+         <domain domain_ref="ptr" />
+         <axis id="depthw" />
+       </grid>
+  </grid_definition>  
+
+  <context id="xios">
+
+      <variable_definition>
+	
+     <!-- 
+        We must have buffer_size > jpi*jpj*jpk*8 (with jpi and jpj the subdomain size)
+-->
+	  <variable id="info_level"                type="int">0</variable>
+	  <variable id="using_server"              type="bool">true</variable>
+	  <variable id="using_oasis"               type="bool">true</variable>
+	  <variable id="oasis_codes_id"            type="string" >toyoce</variable>
+	
+      </variable_definition>
+               
+  </context>
+  
+</simulation>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml	(revision 7693)
@@ -0,0 +1,812 @@
+<!--
+< GO6.0 version of the XIOS namelist >
+< XIOS2 version namelist >
+
+<?xml version="1.0"?>
+       -->
+ 
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+   <field_definition level="1" prec="8" operation="average" enabled=".TRUE." default_value="1.e20" > <!-- time step automaticaly defined -->
+
+    <!-- 
+============================================================================================================
+                                     Biogeochemistry model variables
+============================================================================================================
+    -->
+
+      <!-- ptrc on T grid -->
+
+     <field_group id="ptrc_T" grid_ref="grid_T_3D">
+       <field id="DIC"          long_name="Dissolved inorganic Concentration"        unit="mmol/m3" />
+       <field id="DIC_E3T"      long_name="DIC * E3T"                                unit="mmol/m2" > DIC * e3t </field >
+       <field id="Alkalini"     long_name="Total Alkalinity Concentration"           unit="mmol/m3" />
+       <field id="Alkalini_E3T" long_name="Alkalini * E3T"                           unit="mmol/m2"  > Alkalini * e3t </field >
+       <field id="O2"           long_name="Oxygen Concentration"                     unit="mmol/m3" />
+       <field id="O2_E3T"       long_name="O2 * E3T"                                 unit="mmol/m2"  > O2 * e3t </field >
+       <field id="CaCO3"        long_name="Calcite Concentration"                    unit="mmol/m3" />
+       <field id="CaCO3_E3T"    long_name="CaCO3 * E3T"                              unit="mmol/m2"  > CaCO3 * e3t </field >
+       <field id="PO4"          long_name="Phosphate Concentration"                  unit="mmol/m3" />
+       <field id="PO4_E3T"      long_name="PO4 * E3T"                                unit="mmol/m2"  > PO4 * e3t </field >
+       <field id="POC"          long_name="Small organic carbon Concentration"       unit="mmol/m3" />
+       <field id="POC_E3T"      long_name="POC * E3T"                                unit="mmol/m2"  > POC * e3t </field >
+       <field id="Si"           long_name="Silicate Concentration"                   unit="mmol/m3" />
+       <field id="Si_E3T"       long_name="Si * E3T"                                 unit="mmol/m2"  > Si * e3t </field >
+       <field id="PHY"          long_name="(Nano)Phytoplankton Concentration"        unit="mmol/m3" />
+       <field id="PHY_E3T"      long_name="PHY * E3T"                                unit="mmol/m2"  > PHY * e3t </field >
+       <field id="ZOO"          long_name="(Micro)Zooplankton Concentration"         unit="mmol/m3" />
+       <field id="ZOO_E3T"      long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO * e3t </field >
+       <field id="DOC"          long_name="Dissolved organic Concentration"          unit="mmol/m3" />
+       <field id="DOC_E3T"      long_name="DOC * E3T"                                unit="mmol/m2"  > DOC * e3t </field >
+       <field id="PHY2"         long_name="Diatoms Concentration"                    unit="mmol/m3" />
+       <field id="PHY2_E3T"     long_name="PHY2 * E3T"                               unit="mmol/m2"  > PHY2 * e3t </field >
+       <field id="ZOO2"         long_name="Mesozooplankton Concentration"            unit="mmol/m3" />
+       <field id="ZOO2_E3T"     long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO2 * e3t </field >
+       <field id="DSi"          long_name="Diatoms Silicate Concentration"           unit="mmol/m3" />
+       <field id="DSi_E3T"      long_name="Dsi * E3T"                                unit="mmol/m2"  > DSi * e3t </field >
+       <field id="Fer"          long_name="Dissolved Iron Concentration"             unit="mmol/m3" />
+       <field id="Fer_E3T"      long_name="Fer * E3T"                                unit="mmol/m2"  > Fer * e3t </field >
+       <field id="BFe"          long_name="Big iron particles Concentration"         unit="mmol/m3" />
+       <field id="BFe_E3T"      long_name="BFe * E3T"                                unit="mmol/m2"  > BFe * e3t </field >
+       <field id="GOC"          long_name="Big organic carbon Concentration"         unit="mmol/m3" />
+       <field id="GOC_E3T"      long_name="GOC * E3T"                                unit="mmol/m2"  > GOC * e3t </field >
+       <field id="SFe"          long_name="Small iron particles Concentration"       unit="mmol/m3" />
+       <field id="SFe_E3T"      long_name="SFe * E3T"                                unit="mmol/m2"  > SFe * e3t </field >
+       <field id="DFe"          long_name="Diatoms iron  Concentration"              unit="mmol/m3" />
+       <field id="DFe_E3T"      long_name="DFe * E3T"                                unit="mmol/m2"  > DFe * e3t </field >
+       <field id="GSi"          long_name="Sinking biogenic Silicate Concentration"  unit="mmol/m3" />
+       <field id="GSi_E3T"      long_name="GSi * E3T"                                unit="mmol/m2"  > GSi * e3t </field >
+       <field id="NFe"          long_name="Nano iron Concentration"                  unit="mmol/m3" />
+       <field id="NFe_E3T"      long_name="NFe * E3T"                                unit="mmol/m2"  > NFe * e3t </field >
+       <field id="NCHL"         long_name="Nano chlorophyl Concentration"            unit="mg/m3"   />
+       <field id="NCHL_E3T"     long_name="NCHL * E3T"                               unit="mmol/m2"  > NCHL * e3t </field >
+       <field id="DCHL"         long_name="Diatoms chlorophyl Concentration"         unit="mg/m3"   />
+       <field id="DCHL_E3T"     long_name="DCHL * E3T"                               unit="mmol/m2"  > DCHL * e3t </field >
+       <field id="NO3"          long_name="Nitrate Concentration"                    unit="mmol/m3" />
+       <field id="NO3_E3T"      long_name="NO3 * E3T"                                unit="mmol/m2"  > NO3 * e3t </field >
+       <field id="NH4"          long_name="Ammonium Concentration"                   unit="mmol/m3" />
+       <field id="NH4_E3T"      long_name="NH4 * E3T"                                unit="mmol/m2"  > NH4 * e3t </field >
+
+      <!-- MEDUSA : variables available with key_medusa -->
+       <field id="CHN"      long_name="Chl-a concentration in non-diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="CHD"      long_name="Chl-a concentration in     diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="PHN"      long_name="non-diatom phytoplankton"                          unit="mmol-N/m3" />
+       <field id="PHD"      long_name="diatom     phytoplankton"                          unit="mmol-N/m3" />
+       <field id="ZMI"      long_name="micro zooplankton"                                 unit="mmol-N/m3" />
+       <field id="ZME"      long_name="meso  zooplankton"                                 unit="mmol-N/m3" />
+       <field id="DIN"      long_name="dissolved inorganic nitrogen"                      unit="mmol-N/m3" />
+       <field id="SIL"      long_name="dissolved silicic acid"                            unit="mmolSi/m3" />
+       <field id="FER"      long_name="dissolved iron"                                    unit="mmolFe/m3" />
+       <field id="DET"      long_name="detrital nitrogen"                                 unit="mmol-N/m3" />
+       <field id="PDS"      long_name="biogenic silicon in diatom phytoplankton"          unit="mmolSi/m3" />
+       <field id="DTC"      long_name="detrital carbon"                                   unit="mmol-C/m3" />
+       <field id="DiC"      long_name="dissolved inorganic carbon"                        unit="mmol-C/m3" />
+       <field id="ALK"      long_name="alkalinity"                                        unit="meq/m3"    />
+       <field id="OXY"      long_name="dissolved oxygen"                                  unit="mmolO2/m3" />
+
+      <!-- Ideal traceurs : variables available with key_idtra -->
+       <field id="IDTRA"    long_name="Ideal traceur concentration "                      unit="mmol/m3"    />
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="Num"         long_name="Number of organic particles"              unit="1" />
+       <field id="Num_E3T"     long_name="Num * E3T"                                unit="m"  > Num * e3t </field >
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="DET"         long_name="Detritus"                                 unit="mmol-N/m3" />
+       <field id="DET_E3T"     long_name="DET * E3T"                                unit="mmol-N/m2"  > DET * e3t </field >
+       <field id="DOM"         long_name="Dissolved Organic Matter"                 unit="mmol-N/m3" />
+       <field id="DOM_E3T"     long_name="DOM * E3T"                                unit="mmol-N/m2"  > DOM * e3t </field >
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="CFC11"       long_name="CFC-11 Concentration"                     unit="umol/m3" />
+       <field id="CFC11_E3T"   long_name="CFC11 * E3T"                              unit="umol/m2"  > CFC11 * e3t </field >
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="C14B"        long_name="Bomb C14 Concentration"                   unit="1"         />
+       <field id="C14B_E3T"    long_name="C14B * E3T"                               unit="m"  > C14B * e3t </field >
+       <!-- AGE : variables available with key_age -->
+       <field id="Age"        long_name="Sea Water Age Since Surface contact" standard_name="sea_water_age_since_surface_contact"  unit="yr"         />
+       <field id="Age_e3t"    long_name="Age * e3t"                                 unit="yr * m"  > Age * e3t </field >
+     </field_group>
+
+     <!-- PISCES additional diagnostics on T grid  -->
+
+     <field_group id="diad_T" grid_ref="grid_T_2D">
+       <field id="PH"          long_name="PH"                                      unit="1"          grid_ref="grid_T_3D" />
+       <field id="CO3"         long_name="Bicarbonates"                            unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="CO3sat"      long_name="CO3 saturation"                          unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="PAR"         long_name="Photosynthetically Available Radiation"  unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PARDM"       long_name="Daily mean PAR"                          unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PPPHY"       long_name="Primary production of nanophyto"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPPHY2"      long_name="Primary production of diatoms"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWN"      long_name="New Primary production of nanophyto"     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWD"      long_name="New Primary production of diatoms"       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PBSi"        long_name="Primary production of Si diatoms"        unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeN"        long_name="Primary production of nano iron"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeD"        long_name="Primary production of diatoms iron"      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="xfracal"     long_name="Calcifying fraction"                     unit="1"          grid_ref="grid_T_3D" />
+       <field id="PCAL"        long_name="Calcite production"                      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DCAL"        long_name="Calcite dissolution"                     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ1"       long_name="Grazing by microzooplankton"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ2"       long_name="Grazing by mesozooplankton"              unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="REMIN"       long_name="Oxic remineralization of OM"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DENIT"       long_name="Anoxic remineralization of OM"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Nfix"        long_name="Nitrogen fixation"                       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Mumax"       long_name="Maximum growth rate"                     unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuN"         long_name="Realized growth rate for nanophyto"      unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuD"         long_name="Realized growth rate for diatomes"       unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="LNnut"       long_name="Nutrient limitation term in Nanophyto"   unit=""           grid_ref="grid_T_3D" />
+       <field id="LDnut"       long_name="Nutrient limitation term in Diatoms"     unit=""           grid_ref="grid_T_3D" />
+       <field id="LNFe"        long_name="Iron limitation term in Nanophyto"       unit=""           grid_ref="grid_T_3D" />
+       <field id="LDFe"        long_name="Iron limitation term in Diatoms"         unit=""           grid_ref="grid_T_3D" />
+       <field id="LNlight"     long_name="Light limitation term in Nanophyto"      unit=""           grid_ref="grid_T_3D" />
+       <field id="LDlight"     long_name="Light limitation term in Diatoms"        unit=""           grid_ref="grid_T_3D" />
+       <field id="Fe2"         long_name="Iron II concentration"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Fe3"         long_name="Iron III concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL1"        long_name="Complexed Iron concentration with L1"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL2"        long_name="Complexed Iron concentration with L2"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeP"         long_name="Precipitated Iron III"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL1"         long_name="Total L1 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL2"         long_name="Total L2 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="pdust"       long_name="dust concentration"                      unit="g/m3"                            />
+       <field id="Totlig"      long_name="Total ligand concentation"               unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Biron"       long_name="Bioavailable iron"                       unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Sdenit"      long_name="Nitrate reduction in the sediments"      unit="mol/m2/s"                        />
+       <field id="Ironice"     long_name="Iron input/uptake due to sea ice"        unit="mol/m2/s"                        />
+       <field id="HYDR"        long_name="Iron input from hydrothemal vents"       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EPC100"      long_name="Export of carbon particles at 100 m"     unit="mol/m2/s"                        />
+       <field id="EPFE100"     long_name="Export of biogenic iron at 100 m"        unit="mol/m2/s"                        />
+       <field id="EPSI100"     long_name="Export of Silicate at 100 m"             unit="mol/m2/s"                        />
+       <field id="EPCAL100"    long_name="Export of Calcite at 100 m"              unit="mol/m2/s"                        />
+       <field id="EXPC"        long_name="Export of carbon"                        unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPFE"       long_name="Export of biogenic iron"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPSI"       long_name="Export of Silicate"                      unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPCAL"      long_name="Export of Calcite"                       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="Cflx"        long_name="DIC flux"                                unit="mol/m2/s"                        />
+       <field id="Oflx"        long_name="Oxygen flux"                             unit="mol/m2/s"                        />
+       <field id="Kg"          long_name="Gas transfer"                            unit="mol/m2/s/uatm"                   />
+       <field id="Dpco2"       long_name="Delta CO2"                               unit="uatm"                            />
+       <field id="Dpo2"        long_name="Delta O2"                                unit="uatm"                            />
+       <field id="Heup"        long_name="Euphotic layer depth"                    unit="m"                               />
+       <field id="Irondep"     long_name="Iron deposition from dust"               unit="mol/m2/s"                        />
+       <field id="Ironsed"     long_name="Iron deposition from sediment"           unit="mol/m2/s"   grid_ref="grid_T_3D" />
+
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="EPN100"      long_name="Particulate number flux at 100 m"        unit="mol/m2/s"                        />
+       <field id="EXPN"        long_name="Particulate number flux"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="XNUM"        long_name="Number of particles in aggregats"        unit="1"          grid_ref="grid_T_3D" />
+       <field id="WSC"         long_name="sinking speed of mass flux"              unit="m2/s"       grid_ref="grid_T_3D" />
+       <field id="WSN"         long_name="sinking speed of number flux"            unit="m2/s"       grid_ref="grid_T_3D" />
+
+       <!-- dbio_T on T grid : variables available with key_diaar5 -->
+       <field id="TPP"         long_name="Total Primary production of phyto"                   unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPNEW"       long_name="New Primary production of phyto"                     unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPBFE"       long_name="Total biogenic iron production"                      unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="INTDIC"      long_name="DIC content"                                         unit="kg/m2"                          />
+       <field id="O2MIN"       long_name="Oxygen minimum concentration"                        unit="mol/m3"                          />
+       <field id="ZO2MIN"      long_name="Depth of oxygen minimum concentration"               unit="m"                              />
+       <field id="INTNFIX"     long_name="Nitrogen fixation rate : vert. integrated"           unit="mol/m2/s"                       />
+       <field id="INTPPPHY"    long_name="Vertically integrated primary production by nanophy" unit="mol/m2/s"                       />
+       <field id="INTPPPHY2"   long_name="Vertically integrated primary production by diatom"  unit="mol/m2/s"                       />
+       <field id="INTPP"       long_name="Vertically integrated primary production by phyto"   unit="mol/m2/s"                       />
+       <field id="INTPNEW"     long_name="Vertically integrated new primary production"        unit="mol/m2/s"                       />
+       <field id="INTPBFE"     long_name="Vertically integrated of biogenic iron production"   unit="mol/m2/s"                       />
+       <field id="INTPBSI"     long_name="Vertically integrated of biogenic Si production"     unit="mol/m2/s"                       />
+       <field id="INTPCAL"     long_name="Vertically integrated of calcite production"         unit="mol/m2/s"                       />
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="FNO3PHY"     long_name="FNO3PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4PHY"     long_name="FNH4PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4NO3"     long_name="FNH4NO3"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="TNO3PHY"     long_name="TNO3PHY"                                 unit=""  /> 
+       <field id="TNH4PHY"     long_name="TNH4PHY"                                 unit=""  /> 
+       <field id="TPHYDOM"     long_name="TPHYDOM"                                 unit=""  /> 
+       <field id="TPHYNH4"     long_name="TPHYNH4"                                 unit=""  /> 
+       <field id="TPHYZOO"     long_name="TPHYZOO"                                 unit=""  /> 
+       <field id="TPHYDET"     long_name="TPHYDET"                                 unit=""  /> 
+       <field id="TDETZOO"     long_name="TDETZOO"                                 unit=""  /> 
+       <field id="TZOODET"     long_name="TZOODET"                                 unit=""  /> 
+       <field id="TZOOBOD"     long_name="TZOOBOD"                                 unit=""  /> 
+       <field id="TZOONH4"     long_name="TZOONH4"                                 unit=""  /> 
+       <field id="TZOODOM"     long_name="TZOODOM"                                 unit=""  /> 
+       <field id="TNH4NO3"     long_name="TNH4NO3"                                 unit=""  /> 
+       <field id="TDOMNH4"     long_name="TDOMNH4"                                 unit=""  /> 
+       <field id="TDETNH4"     long_name="TDETNH4"                                 unit=""  /> 
+       <field id="TPHYTOT"     long_name="TPHYTOT"                                 unit=""  /> 
+       <field id="TZOOTOT"     long_name="TZOOTOT"                                 unit=""  /> 
+       <field id="SEDPOC"      long_name="SEDPOC"                                  unit=""  /> 
+       <field id="TDETSED"     long_name="TDETSED"                                 unit=""  /> 
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="qtrCFC11"    long_name="Air-sea flux of CFC-11"                  unit="mol/m2/s"   />
+       <field id="qintCFC11"   long_name="Cumulative air-sea flux of CFC-11"       unit="mol/m2"     />
+
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="qtrC14b"     long_name="Air-sea flux of Bomb C14"                unit="mol/m2/s"   />
+       <field id="qintC14b"    long_name="Cumulative air-sea flux of Bomb C14"     unit="mol/m2"     />
+       <field id="fdecay"      long_name="Radiactive decay of Bomb C14"            unit="mol/m3"  grid_ref="grid_T_3D"  />
+
+       <!-- IDTRA : variables available with key_idtra -->
+       <field id="qtrIDTRA"    long_name="Air-sea flux of Ideal Tracer"             unit="mol/m2/s"   />
+       <field id="qintIDTRA"   long_name="Cumulative air-sea flux of Ideal Tracer"  unit="mol/m2"     />
+       <field id="invIDTRA"    long_name="Vertical inventory"                       unit="mol/m2"     />
+
+       <!-- MEDUSA additional diagnostics on T grid  -->
+       <field id= "INVTN"      long_name="Column N inventory"                        unit="mmolN/m2"    />
+       <field id= "INVTSI"     long_name="Column Si inventory"                       unit="mmolSi/m2"   />
+       <field id= "INVTFE"     long_name="Column Fe inventory"                       unit="mmolFe/m2"   />
+       <field id= "PRN"        long_name="Non-diatom primary production"             unit="mmolN/m2/d"  />
+       <field id= "MPN"        long_name="Non-diatom non-grazing losses"             unit="mmolN/m2/d"  />
+       <field id= "PRD"        long_name="Diatom primary production"                 unit="mmolN/m2/d"  />
+       <field id= "MPD"        long_name="Diatom non-grazing losses"                 unit="mmolN/m2/d"  />
+       <field id= "DSED"       long_name="Gravitational sinking of Detritus"         unit="mmolN/m2/d"  />
+       <field id= "OPAL"       long_name="Diatom biogenic opal production"           unit="mmolSi/m2/d" />
+       <field id= "OPALDISS"   long_name="Diatom biogenic opal dissolution"          unit="mmolSi/m2/d" />
+       <field id= "GMIPn"      long_name="Microzoo grazing on non-diatoms"           unit="mmolN/m2/d"  />
+       <field id= "GMID"       long_name="Microzoo grazing on detritus"              unit="mmolN/m2/d"  />
+       <field id= "MZMI"       long_name="Microzoo non-grazing losses"               unit="mmolN/m2/d"  />
+       <field id= "GMEPN"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEPD"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEZMI"     long_name="Mesozoo grazing on microzoo"               unit="mmolN/m2/d"  />
+       <field id= "GMED"       long_name="Mesozoo grazing on detritus"               unit="mmolN/m2/d"  />
+       <field id= "MZME"       long_name="Mesozoo non-grazing losses"                unit="mmolN/m2/d"  />
+       <field id= "DEXP"       long_name="Detritus export"                           unit="mmolN/m2/d"  />
+       <field id= "DETN"       long_name="Slow detritus creation"                    unit="mmolN/m2/d"  />
+       <field id= "MDET"       long_name="Detritus non-grazing losses"               unit="MmolN/m2/d"  />
+       <field id= "AEOLIAN"    long_name="Aeolian deposition of iron"                unit="mmolFe/m2/d" />
+       <field id= "BENTHIC"    long_name="Benthic supply of iron"                    unit="mmolFe/m2/d" />
+       <field id= "SCAVENGE"   long_name="Scavenged iron"                            unit="mmolFe/m2/d" />
+       <field id= "PN_JLIM"    long_name="Non-diatom light limitation"               unit="-"           />
+       <field id= "PN_NLIM"    long_name="Non-diatom N limitation"                   unit="-"           />
+       <field id= "PN_FELIM"   long_name="Non-diatom Fe limitation"                  unit="-"           />
+       <field id= "PD_JLIM"    long_name="Diatom light limitation"                   unit="-"           />
+       <field id= "PD_NLIM"    long_name="Diatom N limitation"                       unit="-"           />
+       <field id= "PD_FELIM"   long_name="Diatom Fe limitation"                      unit="-"           />
+       <field id= "PD_SILIM"   long_name="Diatom Si limitation"                      unit="-"           />
+       <field id= "PDSILIM2"   long_name="Diatom Si uptake limitation"               unit="-"           />
+       <field id= "SDT__100"   long_name="Slow detrital flux at  100 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__200"   long_name="Slow detrital flux at  200 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__500"   long_name="Slow detrital flux at  500 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT_1000"   long_name="Slow detrital flux at 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "TOTREG_N"   long_name="Full column regenerated N"                 unit="mmolN/m2/d"  />
+       <field id= "TOTRG_SI"   long_name="Full column regenerated Si"                unit="mmolSi/m2/d" />
+       <field id= "REG__100"   long_name="Regenerated N to  100 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__200"   long_name="Regenerated N to  200 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__500"   long_name="Regenerated N to  500 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG_1000"   long_name="Regenerated N to 1000 m"                   unit="mmolN/m2/d"  />
+       <field id= "FASTN"      long_name="Fast-sinking flux N"                       unit="mmolN/m2/d"  />
+       <field id= "FASTSI"     long_name="Fast-sinking flux Si"                      unit="mmolSi/m2/d" />
+       <field id= "FASTFE"     long_name="Fast-sinking flux Fe"                      unit="mmolFe/m2/d" />
+       <field id= "FASTC"      long_name="Fast-sinking flux C"                       unit="mmolC/m2/d"  />
+       <field id= "FASTCA"     long_name="Fast-sinking flux CaCO3"                   unit="mmolC/m2/d"  />
+       <field id= "FDT__100"   long_name="Fast detrital N flux at  100 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__200"   long_name="Fast detrital N flux at  200 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__500"   long_name="Fast detrital N flux at  500 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT_1000"   long_name="Fast detrital N flux at 1000 m"            unit="mmolN/m2/d"  />
+       <field id= "RG__100F"   long_name="Regenerated fast N to  100 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__200F"   long_name="Regenerated fast N to  200 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__500F"   long_name="Regenerated fast N to  500 m"              unit="mmolN/m2/d"  />
+       <field id= "RG_1000F"   long_name="Regenerated fast N to 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "FDS__100"   long_name="Fast detrital Si flux at  100 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__200"   long_name="Fast detrital Si flux at  200 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__500"   long_name="Fast detrital Si flux at  500 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS_1000"   long_name="Fast detrital Si flux at 1000 m"           unit="mmolSi/m2/d" />
+       <field id= "RGS_100F"   long_name="Regenerated fast Si to  100 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_200F"   long_name="Regenerated fast Si to  200 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_500F"   long_name="Regenerated fast Si to  500 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS1000F"   long_name="Regenerated fast Si to 1000 m"             unit="mmolSi/m2/d" />
+       <field id= "REMINN"     long_name="Fast-sinking remin flux N"                 unit="mmolN/m2/d"  />
+       <field id= "REMINSI"    long_name="Fast-sinking remin flux Si"                unit="mmolSi/m2/d" />
+       <field id= "REMINFE"    long_name="Fast-sinking remin flux Fe"                unit="mmolFe/m2/d" />
+       <field id= "REMINC"     long_name="Fast-sinking remin flux C"                 unit="mmolC/m2/d"  />
+       <field id= "REMINCA"    long_name="Fast-sinking remin flux CaCO3"             unit="mmolC/m2/d"  />
+       <field id= "SEAFLRN"    long_name="Seafloor flux of N"                        unit="mmolN/m2/d"  />
+       <field id= "SEAFLRSI"   long_name="Seafloor flux of Si"                       unit="mmolSi/m2/d" />
+       <field id= "SEAFLRFE"   long_name="Seafloor flux of Fe"                       unit="mmolFe/m2/d" />
+       <field id= "SEAFLRC"    long_name="Seafloor flux of C"                        unit="mmolC/m2/d"  />
+       <field id= "SEAFLRCA"   long_name="Seafloor flux of CaCO3"                    unit="mmolC/m2/d"  />
+       <field id= "MED_QSR"    long_name="Sea surface radiation"                     unit="W/m2"        />
+       <field id= "MED_XPAR"   long_name="Top level radiation"                       unit="W/m2"        />
+       <field id= "INTFLX_N"   long_name="Integrated N  cycle fluxes"                unit="mmolN/m2/d"  />
+       <field id= "INTFLX_SI"  long_name="Integrated Si cycle fluxes"                unit="mmolSi/m2/d" />
+       <field id= "INTFLX_FE"  long_name="Integrated Fe cycle fluxes"                unit="mmolFe/m2/d" />
+       <field id= "INT_PN"     long_name="Vertically integrated Pn"                  unit="mmolN/m2"    />
+       <field id= "INT_PD"     long_name="Vertically integrated Pd"                  unit="mmolN/m2"    />
+       <field id= "ML_PRN"     long_name="Non-diatom mixed layer PP"                 unit="mmolN/m2/d"  />
+       <field id= "ML_PRD"     long_name="Diatom mixed layer PP"                     unit="mmolN/m2/d"  />
+       <field id= "OCAL_CCD"   long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "OCAL_LVL"   long_name="Calcite CCD level"                         unit="-"           />
+       <field id= "FE_0000"    long_name="Free iron at    0m"                        unit="-"           />
+       <field id= "FE_0100"    long_name="Free iron at  100m"                        unit="-"           />
+       <field id= "FE_0200"    long_name="Free iron at  200m"                        unit="-"           />
+       <field id= "FE_0500"    long_name="Free iron at  500m"                        unit="-"           />
+       <field id= "FE_1000"    long_name="Free iron at 1000m"                        unit="-"           />
+       <field id= "MED_XZE"    long_name="Euphotic depth"                            unit="m"           />
+       <field id= "WIND"       long_name="Surface scalar wind"                       unit="m/s"         />
+       <field id= "ATM_PCO2"   long_name="Atmospheric pCO2"                          unit="uatm"        />
+       <field id= "OCN_PH"     long_name="Surface ocean pH"                          unit="-"           />
+       <field id= "OCN_PCO2"   long_name="Surface ocean pCO2"                        unit="uatm"        />
+       <field id= "OCNH2CO3"   long_name="Surface ocean H2CO3 conc"                  unit="mmolC/m3"    />
+       <field id= "OCN_HCO3"   long_name="Surface ocean HCO3 conc"                   unit="mmolC/m3"    />
+       <field id= "OCN_CO3"    long_name="Surface ocean CO3 conc"                    unit="mmolC/m3"    />
+       <field id= "CO2FLUX"    long_name="Air-sea CO2 flux"                          unit="mmolC/m2/d"  />
+       <field id= "FGCO2"      long_name="Surface Downward CO2 Flux"                 unit="kg-CO2/m2/s" />
+       <field id= "OM_CAL"     long_name="Omega calcite"                             unit="-"           />
+       <field id= "OM_ARG"     long_name="Omega aragonite"                           unit="-"           />
+       <field id= "TCO2"       long_name="Total CO2"                                 unit="umol/kg"     />
+       <field id= "TALK"       long_name="Total alkalinity"                          unit="ueq/kg"      />
+       <field id= "KW660"      long_name="Piston velocity"                           unit="m/s"         />
+       <field id= "ATM_PP0"    long_name="Atmospheric pressure"                      unit="atm"         />
+       <field id= "O2FLUX"     long_name="Air-sea O2 flux"                           unit="mmolO2/m2/d" />
+       <field id= "O2SAT"      long_name="Surface ocean O2 saturation"               unit="mmolO2/m3"   />
+       <field id= "CAL_CCD"    long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "ARG_CCD"    long_name="Aragonite CCD depth"                       unit="m"           />
+       <field id= "SFR_OCAL"   long_name="Seafloor omega calcite"                    unit="-"           />
+       <field id= "SFR_OARG"   long_name="Seafloor omega aragonite"                  unit="-"           />
+       <field id= "N_PROD"     long_name="Nitrogen production"                       unit="mmolN/m2/d"  />
+       <field id= "N_CONS"     long_name="Nitrogen consumption"                      unit="mmolN/m2/d"  />
+       <field id= "C_PROD"     long_name="Carbon production"                         unit="mmolC/m2/d"  />
+       <field id= "C_CONS"     long_name="Carbon consumption"                        unit="mmolC/m2/d"  />
+       <field id= "O2_PROD"    long_name="Oxygen production"                         unit="mmolO2/m2/d" />
+       <field id= "O2_CONS"    long_name="Oxygen consumption"                        unit="mmolO2/m2/d" />
+       <field id= "O2_ANOX"    long_name="Unrealised oxygen consumption"             unit="mmolO2/m2/d" />
+       <field id= "RR_0100"    long_name="Rain ratio at  100m"                       unit="molC/molC"   />
+       <field id= "RR_0500"    long_name="Rain ratio at  500m"                       unit="molC/molC"   />
+       <field id= "RR_1000"    long_name="Rain ratio at 1000m"                       unit="molC/molC"   />
+       <field id= "IBEN_N"     long_name="Benthic input nitrogen"                    unit="mmolN/m2/d"  />
+       <field id= "IBEN_FE"    long_name="Benthic input iron"                        unit="mmolFe/m2/d" />
+       <field id= "IBEN_C"     long_name="Benthic input carbon"                      unit="mmolC/m2/d"  />
+       <field id= "IBEN_SI"    long_name="Benthic input silicon"                     unit="mmolSi/m2/d" />
+       <field id= "IBEN_CA"    long_name="Benthic input CaCO3"                       unit="mmolC/m2/d"  />
+       <field id= "OBEN_N"     long_name="Benthic output nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "OBEN_FE"    long_name="Benthic output iron"                       unit="mmolFe/m2/d" />
+       <field id= "OBEN_C"     long_name="Benthic output carbon"                     unit="mmolC/m2/d"  />
+       <field id= "OBEN_SI"    long_name="Benthic output silicon"                    unit="mmolSi/m2/d" />
+       <field id= "OBEN_CA"    long_name="Benthic output CaCO3"                      unit="mmolC/m2/d"  />
+       <field id= "BEN_N"      long_name="Benthic nitrogen"                          unit="mmolN/m2"    />
+       <field id= "BEN_FE"     long_name="Benthic iron"                              unit="mmolFe/m2"   />
+       <field id= "BEN_C"      long_name="Benthic carbon"                            unit="mmolC/m2"    />
+       <field id= "BEN_SI"     long_name="Benthic silicon"                           unit="mmolSi/m2"   />
+       <field id= "BEN_CA"     long_name="Benthic CaCO3"                             unit="mmolC/m2"    />
+       <field id= "RUNOFF"     long_name="River runoff"                              unit="m/d"         />
+       <field id= "RIV_N"      long_name="Riverine input nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "RIV_SI"     long_name="Riverine input silicon"                    unit="mmolSi/m2/d" />
+       <field id= "RIV_C"      long_name="Riverine input carbon"                     unit="mmolSi/m2/d" />
+       <field id= "RIV_ALK"    long_name="Riverine input alkalinity"                 unit="meq/m2/d"    />
+       <field id= "DETC"       long_name="Slow detritus C creation"                  unit="mmolC/m2/d"  />
+       <field id= "SDC__100"   long_name="Slow detrital C flux at  100 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__200"   long_name="Slow detrital C flux at  200 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__500"   long_name="Slow detrital C flux at  500 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC_1000"   long_name="Slow detrital C flux at 1000 m"            unit="mmolC/m2/d"  />
+       <field id= "INVTC"      long_name="Column C inventory"                        unit="mmolC/m2"    />
+       <field id= "INVTALK"    long_name="Column alkalinity inventory"               unit="meq/m2"      />
+       <field id= "INVTO2"     long_name="Column O2 inventory"                       unit="mmolO2/m2"   />
+       <field id= "LYSO_CA"    long_name="Incorrect benthic output CaCO3"            unit="mmolC/m2/d"  />
+       <field id= "COM_RESP"   long_name="Community respiration"                     unit="mmolC/m2/d"  />
+       <field id= "PN_LLOSS"   long_name="Non-diatom linear losses"                  unit="mmolN/m2/d"  />
+       <field id= "PD_LLOSS"   long_name="Diatom linear losses"                      unit="mmolN/m2/d"  />
+       <field id= "ZI_LLOSS"   long_name="Microzooplankton linear losses"            unit="mmolN/m2/d"  />
+       <field id= "ZE_LLOSS"   long_name="Mesozooplankton linear losses"             unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_N"   long_name="Microzoo messy feeding loss to N"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_D"   long_name="Microzoo messy feeding loss to D"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_C"   long_name="Microzoo messy feeding loss to C"          unit="mmolC/m2/d"  />
+       <field id= "ZI_MESDC"   long_name="Microzoo messy feeding loss to Dc"         unit="mmolC/m2/d"  />
+       <field id= "ZI_EXCR"    long_name="Microzoo excretion"                        unit="mmolN/m2/d"  />
+       <field id= "ZI_RESP"    long_name="Microzoo respiration"                      unit="mmolC/m2/d"  />
+       <field id= "ZI_GROW"    long_name="Microzoo growth"                           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_N"   long_name="Mesozoo messy feeding loss to N"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_D"   long_name="Mesozoo messy feeding loss to D"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_C"   long_name="Mesozoo messy feeding loss to C"           unit="mmolC/m2/d"  />
+       <field id= "ZE_MESDC"   long_name="Mesozoo messy feeding loss to Dc"          unit="mmolC/m2/d"  />
+       <field id= "ZE_EXCR"    long_name="Mesozoo excretion"                         unit="mmolN/m2/d"  />
+       <field id= "ZE_RESP"    long_name="Mesozoo respiration"                       unit="mmolC/m2/d"  />
+       <field id= "ZE_GROW"    long_name="Mesozoo growth"                            unit="mmolN/m2/d"  />
+       <field id= "MDETC"      long_name="Detritus non-grazing losses, carbon"       unit="mmolC/m2/d"  />
+       <field id= "GMIDC"      long_name="Microzoo grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "GMEDC"      long_name="Mesozoo  grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "INT_ZMI"    long_name="Vertically integrated Zmi"                 unit="mmolN/m2"    />
+       <field id= "INT_ZME"    long_name="Vertically integrated Zme"                 unit="mmolN/m2"    />
+       <field id= "INT_DET"    long_name="Vertically integrated Det"                 unit="mmolN/m2"    />
+       <field id= "INT_DTC"    long_name="Vertically integrated Dtc"                 unit="mmolC/m2"    />
+       <field id= "DMS_SURF"   long_name="DMS Surface Concentration"                 unit="nmol/L"      />
+       <field id= "DMS_ANDR"   long_name="DMS Surface Concentration, Anderson"       unit="nmol/L"      />
+       <field id= "DMS_SIMO"   long_name="DMS Surface Concentration, SimoDach"       unit="nmol/L"      />
+       <field id= "DMS_ARAN"   long_name="DMS Surface Concentration, AranamiT"       unit="nmol/L"      />
+       <field id= "DMS_HALL"   long_name="DMS Surface Concentration, Halloran"       unit="nmol/L"      />
+       <field id= "ATM_XCO2"   long_name="Atmospheric xCO2"                          unit="ppm"         />
+       <field id= "OCN_FCO2"   long_name="Surface ocean fCO2"                        unit="uatm"        />
+       <field id= "ATM_FCO2"   long_name="Atmospheric fCO2"                          unit="uatm"        />
+       <field id= "OCN_RHOSW"  long_name="MOCSY rhoSW"                               unit="kg/m3"       />
+       <field id= "OCN_SCHCO2" long_name="MOCSY Schmidt CO2"                         unit="-"           />
+       <field id= "OCN_KWCO2"  long_name="MOCSY kw CO2"                              unit="m/s"         />
+       <field id= "OCN_K0"     long_name="MOCSY k0"                                  unit="(mol/kg)/atm" />
+       <field id= "CO2STARAIR" long_name="MOCSY CO2star air"                         unit="mmol/m3"     />
+       <field id= "OCN_DPCO2"  long_name="MOCSY delta pCO2"                          unit="uatm"        />
+       
+
+       <!-- AXY (08/11/16): add new 2D CMIP6 diagnostics -->
+       <field id= "epC100"     long_name="Downward Flux of Particle Organic Carbon"  unit="mmolC/m2/d"  />
+       <field id= "epCALC100"  long_name="Downward Flux of Calcite"                  unit="mmolC/m2/d"  />
+       <field id= "epN100"     long_name="Downward Flux of Particulate Nitrogen"     unit="mmolN/m2/d"  />
+       <field id= "epSI100"    long_name="Downward Flux of Particulate Silica"       unit="mmolSi/m2/d" />
+       <field id= "INTDISSIC"  long_name="Dissolved Inorganic Carbon Content"        unit="mmolC/m2"    />
+       <field id= "INTDISSIN"  long_name="Dissolved Inorganic Nitrogen Content"      unit="mmolN/m2"    />
+       <field id= "INTDISSISI" long_name="Dissolved Inorganic Silicon Content"       unit="mmolSi/m2"   />
+       <field id= "INTTALK"    long_name="Dissolved Alkalinity Content"              unit="meq/m2"      />
+       <field id= "O2min"      long_name="Oxygen Minimum Concentration"              unit="mmolO2/m3"   />
+       <field id= "ZO2min"     long_name="Depth of Oxygen Minimum Concentration"     unit="m"           />
+       <field id= "FBDDTALK"   long_name="Int. change of Alkalinity due to Biology"  unit="meq/m2/d"    />
+       <field id= "FBDDTDIC"   long_name="Int. change of DI Carbon due to Biology"   unit="mmolC/m2/d"  />
+       <field id= "FBDDTDIFE"  long_name="Int. change of DI Iron due to Biology"     unit="mmolFe/m2/d" />
+       <field id= "FBDDTDIN"   long_name="Int. change of DI Nitrogen due to Biology" unit="mmolN/m2/d"  />
+       <field id= "FBDDTDISI"  long_name="Int. change of DI Silicon due to Biology"  unit="mmolSi/m2/d" />
+       
+
+       <!-- MEDUSA 3D diagnostics -->
+       <field id= "TPP3"       long_name="Total primary production 3D"               unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "DETFLUX3"   long_name="Total detrital flux 3D"                    unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMIN3N"    long_name="Total remin flux N 3D"                     unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PH3"        long_name="Ocean pH 3D"                               unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "OM_CAL3"    long_name="Omega calcite 3D"                          unit="-"             grid_ref="grid_T_3D"  />
+
+       <!-- AXY (08/11/16): add new 3D CMIP6 diagnostics -->
+       <field id= "TPPD3"      long_name="Diatom primary production 3D"              unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTALK3"   long_name="Change of Alkalinity due to Biology"       unit="meq/m3/d"      grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIC3"   long_name="Change of DI Carbon due to Biology"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIFE3"  long_name="Change of DI Iron due to Biology"          unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIN3"   long_name="Change of DI Nitrogen due to Biology"      unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTDISI3"  long_name="Change of DI Silicon due to Biology"       unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_NIT3"    long_name="Fast sinking detrital nitrogen"            unit="mmolN/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_SIL3"    long_name="Fast sinking detrital silicon"             unit="mmolSi/m2/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_CAR3"    long_name="Fast sinking detrital carbon"              unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_CAL3"    long_name="Fast sinking detrital calcium carbonate"   unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "CO33"       long_name="Carbonate ion concentration"               unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATARAG3" long_name="Carbonate aragonite saturation conc"      unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATCALC3" long_name="Carbonate calcite saturation conc"        unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "DCALC3"     long_name="Calcite dissolution"                       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPC3"      long_name="Downward Flux of Particulate Org Carbon"   unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPN3"      long_name="Downward Flux of Particulate Org Nitrogen" unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "FEDISS3"    long_name="Particle Source of Dissolved Iron"         unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FESCAV3"    long_name="Nonbiogenic Iron Scavenging"               unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZP3"   long_name="Microzooplankton grazing on phytoplankton" unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZD3"   long_name="Microzooplankton grazing on detritus"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZP3"   long_name="Mesozooplankton grazing on phytoplankton"  unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZD3"   long_name="Mesozooplankton grazing on detritus"       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZZ3"   long_name="Mesozooplankton grazing on microzoop"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "O2SAT3"     long_name="Dissolved Oxygen Saturation Concentration" unit="mmolO2/m3"     grid_ref="grid_T_3D"  />
+       <field id= "PBSI3"      long_name="Biogenic Silica Production"                unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "PCAL3"      long_name="Biogenic Calcite Production"               unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMOC3"     long_name="Remineralization of Organic Carbon"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PNLIMJ3"    long_name="Irradiance limitation of non-diatoms"      unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMN3"    long_name="Nitrogen limitation of non-diatoms"        unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMFE3"   long_name="Iron limitation of non-diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMJ3"    long_name="Irradiance limitation of diatoms"          unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMN3"    long_name="Nitrogen limitation of diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMFE3"   long_name="Iron limitation of diatoms"                unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMSI3"   long_name="Silicon limitation of diatoms"             unit="-"             grid_ref="grid_T_3D"  />
+
+     </field_group>
+
+     <field_group id="PISCES_scalar"  domain_ref="1point" >
+       <field id="pno3tot"         long_name="global mean nitrate concentration"                  unit="mol/m3"   />
+       <field id="ppo4tot"         long_name="global mean phosphorus concentration"               unit="mol/m3"   />
+       <field id="psiltot"         long_name="global mean silicate concentration"                 unit="mol/m3"   />
+       <field id="palktot"         long_name="global mean alkalinity concentration"               unit="mol/m3"   />
+       <field id="pfertot"         long_name="global mean iron concentration"                     unit="mol/m3"   />
+       <field id="tcflx"           long_name="total Flux of Carbon out of the ocean"              unit="mol/s"   />
+       <field id="tcflxcum"        long_name="cumulative total Flux of Carbon out of the ocean"   unit="mol/s"   />
+       <field id="tcexp"           long_name="total Carbon export at 100m"                        unit="mol/s"   />
+       <field id="tintpp"          long_name="global total integrated primary production"         unit="mol/s"   />
+       <field id="tnfix"           long_name="global total nitrogen fixation"                     unit="mol/s"   />
+       <field id="tdenit"          long_name="Total denitrification"                              unit="mol/s"   />
+     </field_group>
+
+    <!-- 
+============================================================================================================
+                                        Definitions for iodef_demo.xml
+============================================================================================================
+    -->
+
+    <field_group id="groupMEDUSA" >
+      <field field_ref="CHN"   name="CHN"   />
+      <field field_ref="CHD"   name="CHD"   />
+      <field field_ref="PHN"   name="PHN"   />
+      <field field_ref="PHD"   name="PHD"   />
+      <field field_ref="ZMI"   name="ZMI"   />
+      <field field_ref="ZME"   name="ZME"   />
+      <field field_ref="DIN"   name="DIN"   />
+      <field field_ref="SIL"   name="SIL"   />
+      <field field_ref="FER"   name="FER"   />
+      <field field_ref="DET"   name="DET"   />
+      <field field_ref="PDS"   name="PDS"   />
+      <field field_ref="DTC"   name="DTC"   />
+      <field field_ref="DiC"   name="DIC"   />
+      <field field_ref="ALK"   name="ALK"   />
+      <field field_ref="OXY"   name="OXY"   />
+      </field_group>
+
+    <field_group id="groupIDTRA" >
+      <field field_ref="IDTRA" name="IDTRA" />
+    </field_group>
+
+    <field_group id="groupIDTRA_dia" >
+      <field field_ref="qtrIDTRA"    name="qtrIDTRA"  />
+      <field field_ref="qintIDTRA"   name="qintIDTRA" />
+      <field field_ref="invIDTRA"    name="invIDTRA"  />
+    </field_group>
+
+    <field_group id="groupCFC" >
+      <field field_ref="CFC11" name="CFC11" />
+    </field_group>
+
+    <field_group id="groupCFC_dia" >
+      <field field_ref="qtrCFC11"    name="qtrCFC11"   />
+      <field field_ref="qintCFC11"   name="qintCFC11"  />
+    </field_group>
+
+    <field_group id="groupAGE" >
+      <field field_ref="Age" name="Age" />
+    </field_group>
+
+    <field_group id="groupMEDUSA_dia" >
+      <field field_ref= "INVTN"      name="INVTN"      />
+      <field field_ref= "INVTSI"     name="INVTSI"     />
+      <field field_ref= "INVTFE"     name="INVTFE"     />
+      <field field_ref= "PRN"        name="PRN"        />
+      <field field_ref= "MPN"        name="MPN"        />
+      <field field_ref= "PRD"        name="PRD"        />
+      <field field_ref= "MPD"        name="MPD"        />
+      <field field_ref= "OPAL"       name="OPAL"       />
+      <field field_ref= "OPALDISS"   name="OPALDISS"   />
+      <field field_ref= "GMIPn"      name="GMIPn"      />
+      <field field_ref= "GMID"       name="GMID"       />
+      <field field_ref= "MZMI"       name="MZMI"       />
+      <field field_ref= "GMEPN"      name="GMEPN"      />
+      <field field_ref= "GMEPD"      name="GMEPD"      />
+      <field field_ref= "GMEZMI"     name="GMEZMI"     />
+      <field field_ref= "GMED"       name="GMED"       />
+      <field field_ref= "MZME"       name="MZME"       />
+      <field field_ref= "DETN"       name="DETN"       />
+      <field field_ref= "MDET"       name="MDET"       />
+      <field field_ref= "AEOLIAN"    name="AEOLIAN"    />
+      <field field_ref= "BENTHIC"    name="BENTHIC"    />
+      <field field_ref= "SCAVENGE"   name="SCAVENGE"   />
+      <field field_ref= "PN_JLIM"    name="PN_JLIM"    />
+      <field field_ref= "PN_NLIM"    name="PN_NLIM"    />
+      <field field_ref= "PN_FELIM"   name="PN_FELIM"   />
+      <field field_ref= "PD_JLIM"    name="PD_JLIM"    />
+      <field field_ref= "PD_NLIM"    name="PD_NLIM"    />
+      <field field_ref= "PD_FELIM"   name="PD_FELIM"   />
+      <field field_ref= "PD_SILIM"   name="PD_SILIM"   />
+      <field field_ref= "PDSILIM2"   name="PDSILIM2"   />
+      <field field_ref= "SDT__100"   name="SDT__100"   />
+      <field field_ref= "SDT__200"   name="SDT__200"   />
+      <field field_ref= "SDT__500"   name="SDT__500"   />
+      <field field_ref= "SDT_1000"   name="SDT_1000"   />
+      <field field_ref= "TOTREG_N"   name="TOTREG_N"   />
+      <field field_ref= "TOTRG_SI"   name="TOTRG_SI"   />
+      <field field_ref= "REG__100"   name="REG__100"   />
+      <field field_ref= "REG__200"   name="REG__200"   />
+      <field field_ref= "REG__500"   name="REG__500"   />
+      <field field_ref= "REG_1000"   name="REG_1000"   />
+      <field field_ref= "FASTN"      name="FASTN"      />
+      <field field_ref= "FASTSI"     name="FASTSI"     />
+      <field field_ref= "FASTFE"     name="FASTFE"     />
+      <field field_ref= "FASTC"      name="FASTC"      />
+      <field field_ref= "FASTCA"     name="FASTCA"     />
+      <field field_ref= "FDT__100"   name="FDT__100"   />
+      <field field_ref= "FDT__200"   name="FDT__200"   />
+      <field field_ref= "FDT__500"   name="FDT__500"   />
+      <field field_ref= "FDT_1000"   name="FDT_1000"   /> 
+      <field field_ref= "RG__100F"   name="RG__100F"   />
+      <field field_ref= "RG__200F"   name="RG__200F"   />
+      <field field_ref= "RG__500F"   name="RG__500F"   />
+      <field field_ref= "RG_1000F"   name="RG_1000F"   />
+      <field field_ref= "FDS__100"   name="FDS__100"   />
+      <field field_ref= "FDS__200"   name="FDS__200"   />
+      <field field_ref= "FDS__500"   name="FDS__500"   />
+      <field field_ref= "FDS_1000"   name="FDS_1000"   />
+      <field field_ref= "RGS_100F"   name="RGS_100F"   />
+      <field field_ref= "RGS_200F"   name="RGS_200F"   />
+      <field field_ref= "RGS_500F"   name="RGS_500F"   />
+      <field field_ref= "RGS1000F"   name="RGS1000F"   />
+      <field field_ref= "REMINN"     name="REMINN"     />
+      <field field_ref= "REMINSI"    name="REMINSI"    />
+      <field field_ref= "REMINFE"    name="REMINFE"    />
+      <field field_ref= "SEAFLRN"    name="SEAFLRN"    /> 
+      <field field_ref= "SEAFLRSI"   name="SEAFLRSI"   />
+      <field field_ref= "SEAFLRFE"   name="SEAFLRFE"   />
+      <field field_ref= "SEAFLRC"    name="SEAFLRC"    />
+      <field field_ref= "SEAFLRCA"   name="SEAFLRCA"   />
+      <field field_ref= "MED_QSR"    name="MED_QSR"    />
+      <field field_ref= "MED_XPAR"   name="MED_XPAR"   />
+      <field field_ref= "INTFLX_N"   name="INTFLX_N"   />
+      <field field_ref= "INTFLX_SI"  name="INTFLX_SI"  />
+      <field field_ref= "INTFLX_FE"  name="INTFLX_FE"  />
+      <field field_ref= "INT_PN"     name="INT_PN"     />
+      <field field_ref= "INT_PD"     name="INT_PD"     />
+      <field field_ref= "ML_PRN"     name="ML_PRN"     />
+      <field field_ref= "ML_PRD"     name="ML_PRD"     />
+      <field field_ref= "OCAL_CCD"   name="OCAL_CCD"   />
+      <field field_ref= "OCAL_LVL"   name="OCAL_LVL"   />
+      <field field_ref= "FE_0000"    name="FE_0000"    />
+      <field field_ref= "FE_0100"    name="FE_0100"    />
+      <field field_ref= "FE_0200"    name="FE_0200"    /> 
+      <field field_ref= "FE_0500"    name="FE_0500"    />
+      <field field_ref= "FE_1000"    name="FE_1000"    />
+      <field field_ref= "MED_XZE"    name="MED_XZE"    />
+      <field field_ref= "WIND"       name="WIND"       />
+      <field field_ref= "ATM_PCO2"   name="ATM_PCO2"   />
+      <field field_ref= "OCN_PH"     name="OCN_PH"     />
+      <field field_ref= "OCN_PCO2"   name="OCN_PCO2"   />
+      <field field_ref= "OCNH2CO3"   name="OCNH2CO3"   />
+      <field field_ref= "OCN_HCO3"   name="OCN_HCO3"   />
+      <field field_ref= "OCN_CO3"    name="OCN_CO3"    />
+      <field field_ref= "CO2FLUX"    name="CO2FLUX"    />
+      <field field_ref= "FGCO2"      name="FGCO2"      />
+      <field field_ref= "OM_CAL"     name="OM_CAL"     />
+      <field field_ref= "OM_ARG"     name="OM_ARG"     />
+      <field field_ref= "TCO2"       name="TCO2"       />
+      <field field_ref= "TALK"       name="TALK"       />
+      <field field_ref= "KW660"      name="KW660"      />
+      <field field_ref= "ATM_PP0"    name="ATM_PP0"    />
+      <field field_ref= "O2FLUX"     name="O2FLUX"     />
+      <field field_ref= "O2SAT"      name="O2SAT"      />
+      <field field_ref= "CAL_CCD"    name="CAL_CCD"    />
+      <field field_ref= "ARG_CCD"    name="ARG_CCD"    />
+      <field field_ref= "SFR_OCAL"   name="SFR_OCAL"   />
+      <field field_ref= "SFR_OARG"   name="SFR_OARG"   />
+      <field field_ref= "N_PROD"     name="N_PROD"     />
+      <field field_ref= "N_CONS"     name="N_CONS"     />
+      <field field_ref= "C_PROD"     name="C_PROD"     />
+      <field field_ref= "C_CONS"     name="C_CONS"     />
+      <field field_ref= "O2_PROD"    name="O2_PROD"    />
+      <field field_ref= "O2_CONS"    name="O2_CONS"    />
+      <field field_ref= "O2_ANOX"    name="O2_ANOX"    />
+      <field field_ref= "RR_0100"    name="RR_0100"    />
+      <field field_ref= "RR_0500"    name="RR_0500"    />
+      <field field_ref= "RR_1000"    name="RR_1000"    />
+      <field field_ref= "IBEN_N"     name="IBEN_N"     />
+      <field field_ref= "IBEN_FE"    name="IBEN_FE"    />
+      <field field_ref= "IBEN_C"     name="IBEN_C"     />
+      <field field_ref= "IBEN_SI"    name="IBEN_SI"    />
+      <field field_ref= "IBEN_CA"    name="IBEN_CA"    />
+      <field field_ref= "OBEN_N"     name="OBEN_N"     />
+      <field field_ref= "OBEN_FE"    name="OBEN_FE"    />
+      <field field_ref= "OBEN_C"     name="OBEN_C"     />
+      <field field_ref= "OBEN_SI"    name="OBEN_SI"    />
+      <field field_ref= "OBEN_CA"    name="OBEN_CA"    />
+      <field field_ref= "BEN_N"      name="BEN_N"      />
+      <field field_ref= "BEN_FE"     name="BEN_FE"     />
+      <field field_ref= "BEN_C"      name="BEN_C"      />
+      <field field_ref= "BEN_SI"     name="BEN_SI"     />
+      <field field_ref= "BEN_CA"     name="BEN_CA"     />
+      <field field_ref= "DETC"       name="DETC"       />
+      <field field_ref= "SDC__100"   name="SDC__100"   />
+      <field field_ref= "SDC__200"   name="SDC__200"   />
+      <field field_ref= "SDC__500"   name="SDC__500"   />
+      <field field_ref= "SDC_1000"   name="SDC_1000"   />
+      <field field_ref= "INVTC"      name="INVTC"      />
+      <field field_ref= "INVTALK"    name="INVTALK"    />
+      <field field_ref= "INVTO2"     name="INVTO2"     />
+      <field field_ref= "LYSO_CA"    name="LYSO_CA"    />
+      <field field_ref= "COM_RESP"   name="COM_RESP"   />
+      <field field_ref= "PN_LLOSS"   name="PN_LLOSS"   />
+      <field field_ref= "PD_LLOSS"   name="PD_LLOSS"   />
+      <field field_ref= "ZI_LLOSS"   name="ZI_LLOSS"   />
+      <field field_ref= "ZE_LLOSS"   name="ZE_LLOSS"   />
+      <field field_ref= "ZI_MES_N"   name="ZI_MES_N"   />
+      <field field_ref= "ZI_MES_D"   name="ZI_MES_D"   />
+      <field field_ref= "ZI_MES_C"   name="ZI_MES_C"   />
+      <field field_ref= "ZI_MESDC"   name="ZI_MESDC"   />
+      <field field_ref= "ZI_EXCR"    name="ZI_EXCR"    />
+      <field field_ref= "ZI_RESP"    name="ZI_RESP"    />
+      <field field_ref= "ZI_GROW"    name="ZI_GROW"    />
+      <field field_ref= "ZE_MES_N"   name="ZE_MES_N"   />
+      <field field_ref= "ZE_MES_D"   name="ZE_MES_D"   />
+      <field field_ref= "ZE_MES_C"   name="ZE_MES_C"   />
+      <field field_ref= "ZE_MESDC"   name="ZE_MESDC"   />
+      <field field_ref= "ZE_EXCR"    name="ZE_EXCR"    />
+      <field field_ref= "ZE_RESP"    name="ZE_RESP"    />
+      <field field_ref= "ZE_GROW"    name="ZE_GROW"    />
+      <field field_ref= "MDETC"      name="MDETC"      />
+      <field field_ref= "GMIDC"      name="GMIDC"      />
+      <field field_ref= "GMEDC"      name="GMEDC"      />
+      <field field_ref= "INT_ZMI"    name="INT_ZMI"    />
+      <field field_ref= "INT_ZME"    name="INT_ZME"    />
+      <field field_ref= "INT_DET"    name="INT_DET"    />
+      <field field_ref= "INT_DTC"    name="INT_DTC"    />
+      <field field_ref= "ATM_XCO2"   name="ATM_XCO2"   />
+      <field field_ref= "OCN_FCO2"   name="OCN_FCO2"   />
+      <field field_ref= "ATM_FCO2"   name="ATM_FCO2"   />
+      <field field_ref= "OCN_RHOSW"  name="OCN_RHOSW"  />
+      <field field_ref= "OCN_SCHCO2" name="OCN_SCHCO2" />
+      <field field_ref= "OCN_KWCO2"  name="OCN_KWCO2"  />
+      <field field_ref= "OCN_K0"     name="OCN_K0"     />
+      <field field_ref= "CO2STARAIR" name="CO2STARAIR" />
+      <field field_ref= "OCN_DPCO2"  name="OCN_DPCO2"  />
+    </field_group>
+
+    <field_group id="groupMEDUSA_3dd" >
+      <field field_ref= "TPP3"       name="TPP3"       />
+      <field field_ref= "DETFLUX3"   name="DETFLUX3"   />
+      <field field_ref= "REMIN3N"    name="REMIN3N"    />
+      <field field_ref= "PH3"        name="PH3"        />
+      <field field_ref= "OM_CAL3"    name="OM_CAL3"    /> 
+    </field_group>
+
+    <field_group id="groupMEDUSA_dms" >
+      <field field_ref= "DMS_SURF"   name="DMS_SURF"   />
+      <field field_ref= "DMS_ANDR"   name="DMS_ANDR"   />
+      <field field_ref= "DMS_SIMO"   name="DMS_SIMO"   />
+      <field field_ref= "DMS_ARAN"   name="DMS_ARAN"   />
+      <field field_ref= "DMS_HALL"   name="DMS_HALL"   />
+    </field_group>
+
+    <field_group id="groupMEDUSA_riv" >
+      <field field_ref= "RUNOFF"     name="RUNOFF"     />
+      <field field_ref= "RIV_N"      name="RIV_N"      />
+      <field field_ref= "RIV_SI"     name="RIV_SI"     />
+      <field field_ref= "RIV_C"      name="RIV_C"      />
+      <field field_ref= "RIV_ALK"    name="RIV_ALK"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_cmip6" >
+      <field field_ref= "epC100"     name="epC100"     />
+      <field field_ref= "epCALC100"  name="epCALC100"  />
+      <field field_ref= "epN100"     name="epN100"     />
+      <field field_ref= "epSI100"    name="epSI100"    />
+      <field field_ref= "INTDISSIC"  name="INTDISSIC"  />
+      <field field_ref= "INTDISSIN"  name="INTDISSIN"  />
+      <field field_ref= "INTDISSISI" name="INTDISSISI" />
+      <field field_ref= "INTTALK"    name="INTTALK"    />
+      <field field_ref= "O2min"      name="O2min"      />
+      <field field_ref= "ZO2min"     name="ZO2min"     />
+      <field field_ref= "FBDDTALK"   name="FBDDTALK"   />
+      <field field_ref= "FBDDTDIC"   name="FBDDTDIC"   />
+      <field field_ref= "FBDDTDIFE"  name="FBDDTDIFE"  />
+      <field field_ref= "FBDDTDIN"   name="FBDDTDIN"   />
+      <field field_ref= "FBDDTDISI"  name="FBDDTDISI"  />
+      <field field_ref= "TPPD3"      name="TPPD3"      />
+      <field field_ref= "BDDTALK3"   name="BDDTALK3"   />
+      <field field_ref= "BDDTDIC3"   name="BDDTDIC3"   />
+      <field field_ref= "BDDTDIFE3"  name="BDDTDIFE3"  />
+      <field field_ref= "BDDTDIN3"   name="BDDTDIN3"   />
+      <field field_ref= "BDDTDISI3"  name="BDDTDISI3"  />
+      <field field_ref= "FD_NIT3"    name="FD_NIT3"    />
+      <field field_ref= "FD_SIL3"    name="FD_SIL3"    />
+      <field field_ref= "FD_CAR3"    name="FD_CAR3"    />
+      <field field_ref= "FD_CAL3"    name="FD_CAL3"    />
+      <field field_ref= "CO33"       name="CO33"       />
+      <field field_ref= "CO3SATARAG3" name="CO3SATARAG3" />
+      <field field_ref= "CO3SATCALC3" name="CO3SATCALC3" />
+      <field field_ref= "DCALC3"     name="DCALC3"     />
+      <field field_ref= "EXPC3"      name="EXPC3"      />
+      <field field_ref= "EXPN3"      name="EXPN3"      />
+      <field field_ref= "FEDISS3"    name="FEDISS3"    />
+      <field field_ref= "FESCAV3"    name="FESCAV3"    />
+      <field field_ref= "MIGRAZP3"   name="MIGRAZP3"   />
+      <field field_ref= "MIGRAZD3"   name="MIGRAZD3"   />
+      <field field_ref= "MEGRAZP3"   name="MEGRAZP3"   />
+      <field field_ref= "MEGRAZD3"   name="MEGRAZD3"   />
+      <field field_ref= "MEGRAZZ3"   name="MEGRAZZ3"   />
+      <field field_ref= "O2SAT3"     name="O2SAT3"     />
+      <field field_ref= "PBSI3"      name="PBSI3"      />
+      <field field_ref= "PCAL3"      name="PCAL3"      />
+      <field field_ref= "REMOC3"     name="REMOC3"     />
+      <field field_ref= "PNLIMJ3"    name="PNLIMJ3"    />
+      <field field_ref= "PNLIMN3"    name="PNLIMN3"    />
+      <field field_ref= "PNLIMFE3"   name="PNLIMFE3"   />
+      <field field_ref= "PDLIMJ3"    name="PDLIMJ3"    />
+      <field field_ref= "PDLIMN3"    name="PDLIMN3"    />
+      <field field_ref= "PDLIMFE3"   name="PDLIMFE3"   />
+      <field field_ref= "PDLIMSI3"   name="PDLIMSI3"   />
+    </field_group>
+
+</field_definition>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc_CMIP6.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc_CMIP6.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc_CMIP6.xml	(revision 7693)
@@ -0,0 +1,778 @@
+<!--
+<?xml version="1.0"?>
+       -->
+ 
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+   <field_definition level="1" prec="8" operation="average" enabled=".TRUE." default_value="1.e20" > <!-- time step automaticaly defined -->
+
+    <!-- 
+============================================================================================================
+                                     Biogeochemistry model variables
+============================================================================================================
+    -->
+
+      <!-- ptrc on T grid -->
+
+     <field_group id="ptrc_T" grid_ref="grid_T_3D">
+       <field id="DIC"          long_name="Dissolved inorganic Concentration"        unit="mmol/m3" />
+       <field id="DIC_E3T"      long_name="DIC * E3T"                                unit="mmol/m2" > DIC * e3t </field >
+       <field id="Alkalini"     long_name="Total Alkalinity Concentration"           unit="mmol/m3" />
+       <field id="Alkalini_E3T" long_name="Alkalini * E3T"                           unit="mmol/m2"  > Alkalini * e3t </field >
+       <field id="O2"           long_name="Oxygen Concentration"                     unit="mmol/m3" />
+       <field id="O2_E3T"       long_name="O2 * E3T"                                 unit="mmol/m2"  > O2 * e3t </field >
+       <field id="CaCO3"        long_name="Calcite Concentration"                    unit="mmol/m3" />
+       <field id="CaCO3_E3T"    long_name="CaCO3 * E3T"                              unit="mmol/m2"  > CaCO3 * e3t </field >
+       <field id="PO4"          long_name="Phosphate Concentration"                  unit="mmol/m3" />
+       <field id="PO4_E3T"      long_name="PO4 * E3T"                                unit="mmol/m2"  > PO4 * e3t </field >
+       <field id="POC"          long_name="Small organic carbon Concentration"       unit="mmol/m3" />
+       <field id="POC_E3T"      long_name="POC * E3T"                                unit="mmol/m2"  > POC * e3t </field >
+       <field id="Si"           long_name="Silicate Concentration"                   unit="mmol/m3" />
+       <field id="Si_E3T"       long_name="Si * E3T"                                 unit="mmol/m2"  > Si * e3t </field >
+       <field id="PHY"          long_name="(Nano)Phytoplankton Concentration"        unit="mmol/m3" />
+       <field id="PHY_E3T"      long_name="PHY * E3T"                                unit="mmol/m2"  > PHY * e3t </field >
+       <field id="ZOO"          long_name="(Micro)Zooplankton Concentration"         unit="mmol/m3" />
+       <field id="ZOO_E3T"      long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO * e3t </field >
+       <field id="DOC"          long_name="Dissolved organic Concentration"          unit="mmol/m3" />
+       <field id="DOC_E3T"      long_name="DOC * E3T"                                unit="mmol/m2"  > DOC * e3t </field >
+       <field id="PHY2"         long_name="Diatoms Concentration"                    unit="mmol/m3" />
+       <field id="PHY2_E3T"     long_name="PHY2 * E3T"                               unit="mmol/m2"  > PHY2 * e3t </field >
+       <field id="ZOO2"         long_name="Mesozooplankton Concentration"            unit="mmol/m3" />
+       <field id="ZOO2_E3T"     long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO2 * e3t </field >
+       <field id="DSi"          long_name="Diatoms Silicate Concentration"           unit="mmol/m3" />
+       <field id="DSi_E3T"      long_name="Dsi * E3T"                                unit="mmol/m2"  > DSi * e3t </field >
+       <field id="Fer"          long_name="Dissolved Iron Concentration"             unit="mmol/m3" />
+       <field id="Fer_E3T"      long_name="Fer * E3T"                                unit="mmol/m2"  > Fer * e3t </field >
+       <field id="BFe"          long_name="Big iron particles Concentration"         unit="mmol/m3" />
+       <field id="BFe_E3T"      long_name="BFe * E3T"                                unit="mmol/m2"  > BFe * e3t </field >
+       <field id="GOC"          long_name="Big organic carbon Concentration"         unit="mmol/m3" />
+       <field id="GOC_E3T"      long_name="GOC * E3T"                                unit="mmol/m2"  > GOC * e3t </field >
+       <field id="SFe"          long_name="Small iron particles Concentration"       unit="mmol/m3" />
+       <field id="SFe_E3T"      long_name="SFe * E3T"                                unit="mmol/m2"  > SFe * e3t </field >
+       <field id="DFe"          long_name="Diatoms iron  Concentration"              unit="mmol/m3" />
+       <field id="DFe_E3T"      long_name="DFe * E3T"                                unit="mmol/m2"  > DFe * e3t </field >
+       <field id="GSi"          long_name="Sinking biogenic Silicate Concentration"  unit="mmol/m3" />
+       <field id="GSi_E3T"      long_name="GSi * E3T"                                unit="mmol/m2"  > GSi * e3t </field >
+       <field id="NFe"          long_name="Nano iron Concentration"                  unit="mmol/m3" />
+       <field id="NFe_E3T"      long_name="NFe * E3T"                                unit="mmol/m2"  > NFe * e3t </field >
+       <field id="NCHL"         long_name="Nano chlorophyl Concentration"            unit="mg/m3"   />
+       <field id="NCHL_E3T"     long_name="NCHL * E3T"                               unit="mmol/m2"  > NCHL * e3t </field >
+       <field id="DCHL"         long_name="Diatoms chlorophyl Concentration"         unit="mg/m3"   />
+       <field id="DCHL_E3T"     long_name="DCHL * E3T"                               unit="mmol/m2"  > DCHL * e3t </field >
+       <field id="NO3"          long_name="Nitrate Concentration"                    unit="mmol/m3" />
+       <field id="NO3_E3T"      long_name="NO3 * E3T"                                unit="mmol/m2"  > NO3 * e3t </field >
+       <field id="NH4"          long_name="Ammonium Concentration"                   unit="mmol/m3" />
+       <field id="NH4_E3T"      long_name="NH4 * E3T"                                unit="mmol/m2"  > NH4 * e3t </field >
+
+      <!-- MEDUSA : variables available with key_medusa -->
+       <field id="CHN"      long_name="Chl-a concentration in non-diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="CHD"      long_name="Chl-a concentration in     diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="PHN"      long_name="non-diatom phytoplankton"                          unit="mmol-N/m3" />
+       <field id="PHD"      long_name="diatom     phytoplankton"                          unit="mmol-N/m3" />
+       <field id="ZMI"      long_name="micro zooplankton"                                 unit="mmol-N/m3" />
+       <field id="ZME"      long_name="meso  zooplankton"                                 unit="mmol-N/m3" />
+       <field id="DIN"      long_name="dissolved inorganic nitrogen"                      unit="mmol-N/m3" />
+       <field id="SIL"      long_name="dissolved silicic acid"                            unit="mmolSi/m3" />
+       <field id="FER"      long_name="dissolved iron"                                    unit="mmolFe/m3" />
+       <field id="DET"      long_name="detrital nitrogen"                                 unit="mmol-N/m3" />
+       <field id="PDS"      long_name="biogenic silicon in diatom phytoplankton"          unit="mmolSi/m3" />
+       <field id="DTC"      long_name="detrital carbon"                                   unit="mmol-C/m3" />
+       <field id="DiC"      long_name="dissolved inorganic carbon"                        unit="mmol-C/m3" />
+       <field id="ALK"      long_name="alkalinity"                                        unit="meq/m3"    />
+       <field id="OXY"      long_name="dissolved oxygen"                                  unit="mmolO2/m3" />
+
+      <!-- Ideal traceurs : variables available with key_idtra -->
+       <field id="IDTRA"    long_name="Ideal traceur concentration "                      unit="mmol/m3"    />
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="Num"         long_name="Number of organic particles"              unit="1" />
+       <field id="Num_E3T"     long_name="Num * E3T"                                unit="m"  > Num * e3t </field >
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="DET"         long_name="Detritus"                                 unit="mmol-N/m3" />
+       <field id="DET_E3T"     long_name="DET * E3T"                                unit="mmol-N/m2"  > DET * e3t </field >
+       <field id="DOM"         long_name="Dissolved Organic Matter"                 unit="mmol-N/m3" />
+       <field id="DOM_E3T"     long_name="DOM * E3T"                                unit="mmol-N/m2"  > DOM * e3t </field >
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="CFC11"       long_name="CFC-11 Concentration"                     unit="umol/m3" />
+       <field id="CFC11_E3T"   long_name="CFC11 * E3T"                              unit="umol/m2"  > CFC11 * e3t </field >
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="C14B"        long_name="Bomb C14 Concentration"                   unit="1"         />
+       <field id="C14B_E3T"    long_name="C14B * E3T"                               unit="m"  > C14B * e3t </field >
+       <!-- AGE : variables available with key_age -->
+       <field id="Age"        long_name="Sea Water Age Since Surface contact" standard_name="sea_water_age_since_surface_contact"  unit="yr"         />
+       <field id="Age_e3t"    long_name="Age * e3t"                                 unit="yr * m"  > Age * e3t </field >
+     </field_group>
+
+     <!-- PISCES additional diagnostics on T grid  -->
+
+     <field_group id="diad_T" grid_ref="grid_T_2D">
+       <field id="PH"          long_name="PH"                                      unit="1"          grid_ref="grid_T_3D" />
+       <field id="CO3"         long_name="Bicarbonates"                            unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="CO3sat"      long_name="CO3 saturation"                          unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="PAR"         long_name="Photosynthetically Available Radiation"  unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PARDM"       long_name="Daily mean PAR"                          unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PPPHY"       long_name="Primary production of nanophyto"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPPHY2"      long_name="Primary production of diatoms"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWN"      long_name="New Primary production of nanophyto"     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWD"      long_name="New Primary production of diatoms"       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PBSi"        long_name="Primary production of Si diatoms"        unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeN"        long_name="Primary production of nano iron"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeD"        long_name="Primary production of diatoms iron"      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="xfracal"     long_name="Calcifying fraction"                     unit="1"          grid_ref="grid_T_3D" />
+       <field id="PCAL"        long_name="Calcite production"                      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DCAL"        long_name="Calcite dissolution"                     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ1"       long_name="Grazing by microzooplankton"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ2"       long_name="Grazing by mesozooplankton"              unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="REMIN"       long_name="Oxic remineralization of OM"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DENIT"       long_name="Anoxic remineralization of OM"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Nfix"        long_name="Nitrogen fixation"                       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Mumax"       long_name="Maximum growth rate"                     unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuN"         long_name="Realized growth rate for nanophyto"      unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuD"         long_name="Realized growth rate for diatomes"       unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="LNnut"       long_name="Nutrient limitation term in Nanophyto"   unit=""           grid_ref="grid_T_3D" />
+       <field id="LDnut"       long_name="Nutrient limitation term in Diatoms"     unit=""           grid_ref="grid_T_3D" />
+       <field id="LNFe"        long_name="Iron limitation term in Nanophyto"       unit=""           grid_ref="grid_T_3D" />
+       <field id="LDFe"        long_name="Iron limitation term in Diatoms"         unit=""           grid_ref="grid_T_3D" />
+       <field id="LNlight"     long_name="Light limitation term in Nanophyto"      unit=""           grid_ref="grid_T_3D" />
+       <field id="LDlight"     long_name="Light limitation term in Diatoms"        unit=""           grid_ref="grid_T_3D" />
+       <field id="Fe2"         long_name="Iron II concentration"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Fe3"         long_name="Iron III concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL1"        long_name="Complexed Iron concentration with L1"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL2"        long_name="Complexed Iron concentration with L2"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeP"         long_name="Precipitated Iron III"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL1"         long_name="Total L1 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL2"         long_name="Total L2 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="pdust"       long_name="dust concentration"                      unit="g/m3"                            />
+       <field id="Totlig"      long_name="Total ligand concentation"               unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Biron"       long_name="Bioavailable iron"                       unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Sdenit"      long_name="Nitrate reduction in the sediments"      unit="mol/m2/s"                        />
+       <field id="Ironice"     long_name="Iron input/uptake due to sea ice"        unit="mol/m2/s"                        />
+       <field id="HYDR"        long_name="Iron input from hydrothemal vents"       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EPC100"      long_name="Export of carbon particles at 100 m"     unit="mol/m2/s"                        />
+       <field id="EPFE100"     long_name="Export of biogenic iron at 100 m"        unit="mol/m2/s"                        />
+       <field id="EPSI100"     long_name="Export of Silicate at 100 m"             unit="mol/m2/s"                        />
+       <field id="EPCAL100"    long_name="Export of Calcite at 100 m"              unit="mol/m2/s"                        />
+       <field id="EXPC"        long_name="Export of carbon"                        unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPFE"       long_name="Export of biogenic iron"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPSI"       long_name="Export of Silicate"                      unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPCAL"      long_name="Export of Calcite"                       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="Cflx"        long_name="DIC flux"                                unit="mol/m2/s"                        />
+       <field id="Oflx"        long_name="Oxygen flux"                             unit="mol/m2/s"                        />
+       <field id="Kg"          long_name="Gas transfer"                            unit="mol/m2/s/uatm"                   />
+       <field id="Dpco2"       long_name="Delta CO2"                               unit="uatm"                            />
+       <field id="Dpo2"        long_name="Delta O2"                                unit="uatm"                            />
+       <field id="Heup"        long_name="Euphotic layer depth"                    unit="m"                               />
+       <field id="Irondep"     long_name="Iron deposition from dust"               unit="mol/m2/s"                        />
+       <field id="Ironsed"     long_name="Iron deposition from sediment"           unit="mol/m2/s"   grid_ref="grid_T_3D" />
+
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="EPN100"      long_name="Particulate number flux at 100 m"        unit="mol/m2/s"                        />
+       <field id="EXPN"        long_name="Particulate number flux"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="XNUM"        long_name="Number of particles in aggregats"        unit="1"          grid_ref="grid_T_3D" />
+       <field id="WSC"         long_name="sinking speed of mass flux"              unit="m2/s"       grid_ref="grid_T_3D" />
+       <field id="WSN"         long_name="sinking speed of number flux"            unit="m2/s"       grid_ref="grid_T_3D" />
+
+       <!-- dbio_T on T grid : variables available with key_diaar5 -->
+       <field id="TPP"         long_name="Total Primary production of phyto"                   unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPNEW"       long_name="New Primary production of phyto"                     unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPBFE"       long_name="Total biogenic iron production"                      unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="INTDIC"      long_name="DIC content"                                         unit="kg/m2"                          />
+       <field id="O2MIN"       long_name="Oxygen minimum concentration"                        unit="mol/m3"                          />
+       <field id="ZO2MIN"      long_name="Depth of oxygen minimum concentration"               unit="m"                              />
+       <field id="INTNFIX"     long_name="Nitrogen fixation rate : vert. integrated"           unit="mol/m2/s"                       />
+       <field id="INTPPPHY"    long_name="Vertically integrated primary production by nanophy" unit="mol/m2/s"                       />
+       <field id="INTPPPHY2"   long_name="Vertically integrated primary production by diatom"  unit="mol/m2/s"                       />
+       <field id="INTPP"       long_name="Vertically integrated primary production by phyto"   unit="mol/m2/s"                       />
+       <field id="INTPNEW"     long_name="Vertically integrated new primary production"        unit="mol/m2/s"                       />
+       <field id="INTPBFE"     long_name="Vertically integrated of biogenic iron production"   unit="mol/m2/s"                       />
+       <field id="INTPBSI"     long_name="Vertically integrated of biogenic Si production"     unit="mol/m2/s"                       />
+       <field id="INTPCAL"     long_name="Vertically integrated of calcite production"         unit="mol/m2/s"                       />
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="FNO3PHY"     long_name="FNO3PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4PHY"     long_name="FNH4PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4NO3"     long_name="FNH4NO3"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="TNO3PHY"     long_name="TNO3PHY"                                 unit=""  /> 
+       <field id="TNH4PHY"     long_name="TNH4PHY"                                 unit=""  /> 
+       <field id="TPHYDOM"     long_name="TPHYDOM"                                 unit=""  /> 
+       <field id="TPHYNH4"     long_name="TPHYNH4"                                 unit=""  /> 
+       <field id="TPHYZOO"     long_name="TPHYZOO"                                 unit=""  /> 
+       <field id="TPHYDET"     long_name="TPHYDET"                                 unit=""  /> 
+       <field id="TDETZOO"     long_name="TDETZOO"                                 unit=""  /> 
+       <field id="TZOODET"     long_name="TZOODET"                                 unit=""  /> 
+       <field id="TZOOBOD"     long_name="TZOOBOD"                                 unit=""  /> 
+       <field id="TZOONH4"     long_name="TZOONH4"                                 unit=""  /> 
+       <field id="TZOODOM"     long_name="TZOODOM"                                 unit=""  /> 
+       <field id="TNH4NO3"     long_name="TNH4NO3"                                 unit=""  /> 
+       <field id="TDOMNH4"     long_name="TDOMNH4"                                 unit=""  /> 
+       <field id="TDETNH4"     long_name="TDETNH4"                                 unit=""  /> 
+       <field id="TPHYTOT"     long_name="TPHYTOT"                                 unit=""  /> 
+       <field id="TZOOTOT"     long_name="TZOOTOT"                                 unit=""  /> 
+       <field id="SEDPOC"      long_name="SEDPOC"                                  unit=""  /> 
+       <field id="TDETSED"     long_name="TDETSED"                                 unit=""  /> 
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="qtrCFC11"    long_name="Air-sea flux of CFC-11"                  unit="mol/m2/s"   />
+       <field id="qintCFC11"   long_name="Cumulative air-sea flux of CFC-11"       unit="mol/m2"     />
+
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="qtrC14b"     long_name="Air-sea flux of Bomb C14"                unit="mol/m2/s"   />
+       <field id="qintC14b"    long_name="Cumulative air-sea flux of Bomb C14"     unit="mol/m2"     />
+       <field id="fdecay"      long_name="Radiactive decay of Bomb C14"            unit="mol/m3"  grid_ref="grid_T_3D"  />
+
+       <!-- IDTRA : variables available with key_idtra -->
+       <field id="qtrIDTRA"    long_name="Air-sea flux of Ideal Tracer"             unit="mol/m2/s"   />
+       <field id="qintIDTRA"   long_name="Cumulative air-sea flux of Ideal Tracer"  unit="mol/m2"     />
+       <field id="invIDTRA"    long_name="Vertical inventory"                       unit="mol/m2"     />
+
+       <!-- MEDUSA additional diagnostics on T grid  -->
+       <field id= "INVTN"      long_name="Column N inventory"                        unit="mmolN/m2"    />
+       <field id= "INVTSI"     long_name="Column Si inventory"                       unit="mmolSi/m2"   />
+       <field id= "INVTFE"     long_name="Column Fe inventory"                       unit="mmolFe/m2"   />
+       <field id= "PRN"        long_name="Non-diatom primary production"             unit="mmolN/m2/d"  />
+       <field id= "MPN"        long_name="Non-diatom non-grazing losses"             unit="mmolN/m2/d"  />
+       <field id= "PRD"        long_name="Diatom primary production"                 unit="mmolN/m2/d"  />
+       <field id= "MPD"        long_name="Diatom non-grazing losses"                 unit="mmolN/m2/d"  />
+       <field id= "DSED"       long_name="Gravitational sinking of Detritus"         unit="mmolN/m2/d"  />
+       <field id= "OPAL"       long_name="Diatom biogenic opal production"           unit="mmolSi/m2/d" />
+       <field id= "OPALDISS"   long_name="Diatom biogenic opal dissolution"          unit="mmolSi/m2/d" />
+       <field id= "GMIPn"      long_name="Microzoo grazing on non-diatoms"           unit="mmolN/m2/d"  />
+       <field id= "GMID"       long_name="Microzoo grazing on detritus"              unit="mmolN/m2/d"  />
+       <field id= "MZMI"       long_name="Microzoo non-grazing losses"               unit="mmolN/m2/d"  />
+       <field id= "GMEPN"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEPD"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEZMI"     long_name="Mesozoo grazing on microzoo"               unit="mmolN/m2/d"  />
+       <field id= "GMED"       long_name="Mesozoo grazing on detritus"               unit="mmolN/m2/d"  />
+       <field id= "MZME"       long_name="Mesozoo non-grazing losses"                unit="mmolN/m2/d"  />
+       <field id= "DEXP"       long_name="Detritus export"                           unit="mmolN/m2/d"  />
+       <field id= "DETN"       long_name="Slow detritus creation"                    unit="mmolN/m2/d"  />
+       <field id= "MDET"       long_name="Detritus non-grazing losses"               unit="MmolN/m2/d"  />
+       <field id= "AEOLIAN"    long_name="Aeolian deposition of iron"                unit="mmolFe/m2/d" />
+       <field id= "BENTHIC"    long_name="Benthic supply of iron"                    unit="mmolFe/m2/d" />
+       <field id= "SCAVENGE"   long_name="Scavenged iron"                            unit="mmolFe/m2/d" />
+       <field id= "PN_JLIM"    long_name="Non-diatom light limitation"               unit="-"           />
+       <field id= "PN_NLIM"    long_name="Non-diatom N limitation"                   unit="-"           />
+       <field id= "PN_FELIM"   long_name="Non-diatom Fe limitation"                  unit="-"           />
+       <field id= "PD_JLIM"    long_name="Diatom light limitation"                   unit="-"           />
+       <field id= "PD_NLIM"    long_name="Diatom N limitation"                       unit="-"           />
+       <field id= "PD_FELIM"   long_name="Diatom Fe limitation"                      unit="-"           />
+       <field id= "PD_SILIM"   long_name="Diatom Si limitation"                      unit="-"           />
+       <field id= "PDSILIM2"   long_name="Diatom Si uptake limitation"               unit="-"           />
+       <field id= "SDT__100"   long_name="Slow detrital flux at  100 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__200"   long_name="Slow detrital flux at  200 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__500"   long_name="Slow detrital flux at  500 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT_1000"   long_name="Slow detrital flux at 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "TOTREG_N"   long_name="Full column regenerated N"                 unit="mmolN/m2/d"  />
+       <field id= "TOTRG_SI"   long_name="Full column regenerated Si"                unit="mmolSi/m2/d" />
+       <field id= "REG__100"   long_name="Regenerated N to  100 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__200"   long_name="Regenerated N to  200 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__500"   long_name="Regenerated N to  500 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG_1000"   long_name="Regenerated N to 1000 m"                   unit="mmolN/m2/d"  />
+       <field id= "FASTN"      long_name="Fast-sinking flux N"                       unit="mmolN/m2/d"  />
+       <field id= "FASTSI"     long_name="Fast-sinking flux Si"                      unit="mmolSi/m2/d" />
+       <field id= "FASTFE"     long_name="Fast-sinking flux Fe"                      unit="mmolFe/m2/d" />
+       <field id= "FASTC"      long_name="Fast-sinking flux C"                       unit="mmolC/m2/d"  />
+       <field id= "FASTCA"     long_name="Fast-sinking flux CaCO3"                   unit="mmolC/m2/d"  />
+       <field id= "FDT__100"   long_name="Fast detrital N flux at  100 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__200"   long_name="Fast detrital N flux at  200 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__500"   long_name="Fast detrital N flux at  500 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT_1000"   long_name="Fast detrital N flux at 1000 m"            unit="mmolN/m2/d"  />
+       <field id= "RG__100F"   long_name="Regenerated fast N to  100 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__200F"   long_name="Regenerated fast N to  200 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__500F"   long_name="Regenerated fast N to  500 m"              unit="mmolN/m2/d"  />
+       <field id= "RG_1000F"   long_name="Regenerated fast N to 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "FDS__100"   long_name="Fast detrital Si flux at  100 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__200"   long_name="Fast detrital Si flux at  200 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__500"   long_name="Fast detrital Si flux at  500 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS_1000"   long_name="Fast detrital Si flux at 1000 m"           unit="mmolSi/m2/d" />
+       <field id= "RGS_100F"   long_name="Regenerated fast Si to  100 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_200F"   long_name="Regenerated fast Si to  200 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_500F"   long_name="Regenerated fast Si to  500 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS1000F"   long_name="Regenerated fast Si to 1000 m"             unit="mmolSi/m2/d" />
+       <field id= "REMINN"     long_name="Fast-sinking remin flux N"                 unit="mmolN/m2/d"  />
+       <field id= "REMINSI"    long_name="Fast-sinking remin flux Si"                unit="mmolSi/m2/d" />
+       <field id= "REMINFE"    long_name="Fast-sinking remin flux Fe"                unit="mmolFe/m2/d" />
+       <field id= "REMINC"     long_name="Fast-sinking remin flux C"                 unit="mmolC/m2/d"  />
+       <field id= "REMINCA"    long_name="Fast-sinking remin flux CaCO3"             unit="mmolC/m2/d"  />
+       <field id= "SEAFLRN"    long_name="Seafloor flux of N"                        unit="mmolN/m2/d"  />
+       <field id= "SEAFLRSI"   long_name="Seafloor flux of Si"                       unit="mmolSi/m2/d" />
+       <field id= "SEAFLRFE"   long_name="Seafloor flux of Fe"                       unit="mmolFe/m2/d" />
+       <field id= "SEAFLRC"    long_name="Seafloor flux of C"                        unit="mmolC/m2/d"  />
+       <field id= "SEAFLRCA"   long_name="Seafloor flux of CaCO3"                    unit="mmolC/m2/d"  />
+       <field id= "MED_QSR"    long_name="Sea surface radiation"                     unit="W/m2"        />
+       <field id= "MED_XPAR"   long_name="Top level radiation"                       unit="W/m2"        />
+       <field id= "INTFLX_N"   long_name="Integrated N  cycle fluxes"                unit="mmolN/m2/d"  />
+       <field id= "INTFLX_SI"  long_name="Integrated Si cycle fluxes"                unit="mmolSi/m2/d" />
+       <field id= "INTFLX_FE"  long_name="Integrated Fe cycle fluxes"                unit="mmolFe/m2/d" />
+       <field id= "INT_PN"     long_name="Vertically integrated Pn"                  unit="mmolN/m2"    />
+       <field id= "INT_PD"     long_name="Vertically integrated Pd"                  unit="mmolN/m2"    />
+       <field id= "ML_PRN"     long_name="Non-diatom mixed layer PP"                 unit="mmolN/m2/d"  />
+       <field id= "ML_PRD"     long_name="Diatom mixed layer PP"                     unit="mmolN/m2/d"  />
+       <field id= "OCAL_CCD"   long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "OCAL_LVL"   long_name="Calcite CCD level"                         unit="-"           />
+       <field id= "FE_0000"    long_name="Free iron at    0m"                        unit="-"           />
+       <field id= "FE_0100"    long_name="Free iron at  100m"                        unit="-"           />
+       <field id= "FE_0200"    long_name="Free iron at  200m"                        unit="-"           />
+       <field id= "FE_0500"    long_name="Free iron at  500m"                        unit="-"           />
+       <field id= "FE_1000"    long_name="Free iron at 1000m"                        unit="-"           />
+       <field id= "MED_XZE"    long_name="Euphotic depth"                            unit="m"           />
+       <field id= "WIND"       long_name="Surface scalar wind"                       unit="m/s"         />
+       <field id= "ATM_PCO2"   long_name="Atmospheric pCO2"                          unit="ppmv"        />
+       <field id= "OCN_PH"     long_name="Surface ocean pH"                          unit="-"           />
+       <field id= "OCN_PCO2"   long_name="Surface ocean pCO2"                        unit="ppmv"        />
+       <field id= "OCNH2CO3"   long_name="Surface ocean H2CO3 conc"                  unit="mmolC/m3"    />
+       <field id= "OCN_HCO3"   long_name="Surface ocean HCO3 conc"                   unit="mmolC/m3"    />
+       <field id= "OCN_CO3"    long_name="Surface ocean CO3 conc"                    unit="mmolC/m3"    />
+       <field id= "CO2FLUX"    long_name="Air-sea CO2 flux"                          unit="mmolC/m2/d"  />
+       <field id= "OM_CAL"     long_name="Omega calcite"                             unit="-"           />
+       <field id= "OM_ARG"     long_name="Omega aragonite"                           unit="-"           />
+       <field id= "TCO2"       long_name="Total CO2"                                 unit="umol/kg"     />
+       <field id= "TALK"       long_name="Total alkalinity"                          unit="ueq/kg"      />
+       <field id= "KW660"      long_name="Piston velocity"                           unit="m/s"         />
+       <field id= "ATM_PP0"    long_name="Atmospheric pressure"                      unit="bar"         />
+       <field id= "O2FLUX"     long_name="Air-sea O2 flux"                           unit="mmolO2/m2/d" />
+       <field id= "O2SAT"      long_name="Surface ocean O2 saturation"               unit="mmolO2/m3"   />
+       <field id= "CAL_CCD"    long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "ARG_CCD"    long_name="Aragonite CCD depth"                       unit="m"           />
+       <field id= "SFR_OCAL"   long_name="Seafloor omega calcite"                    unit="-"           />
+       <field id= "SFR_OARG"   long_name="Seafloor omega aragonite"                  unit="-"           />
+       <field id= "N_PROD"     long_name="Nitrogen production"                       unit="mmolN/m2/d"  />
+       <field id= "N_CONS"     long_name="Nitrogen consumption"                      unit="mmolN/m2/d"  />
+       <field id= "C_PROD"     long_name="Carbon production"                         unit="mmolC/m2/d"  />
+       <field id= "C_CONS"     long_name="Carbon consumption"                        unit="mmolC/m2/d"  />
+       <field id= "O2_PROD"    long_name="Oxygen production"                         unit="mmolO2/m2/d" />
+       <field id= "O2_CONS"    long_name="Oxygen consumption"                        unit="mmolO2/m2/d" />
+       <field id= "O2_ANOX"    long_name="Unrealised oxygen consumption"             unit="mmolO2/m2/d" />
+       <field id= "RR_0100"    long_name="Rain ratio at  100m"                       unit="molC/molC"   />
+       <field id= "RR_0500"    long_name="Rain ratio at  500m"                       unit="molC/molC"   />
+       <field id= "RR_1000"    long_name="Rain ratio at 1000m"                       unit="molC/molC"   />
+       <field id= "IBEN_N"     long_name="Benthic input nitrogen"                    unit="mmolN/m2/d"  />
+       <field id= "IBEN_FE"    long_name="Benthic input iron"                        unit="mmolFe/m2/d" />
+       <field id= "IBEN_C"     long_name="Benthic input carbon"                      unit="mmolC/m2/d"  />
+       <field id= "IBEN_SI"    long_name="Benthic input silicon"                     unit="mmolSi/m2/d" />
+       <field id= "IBEN_CA"    long_name="Benthic input CaCO3"                       unit="mmolC/m2/d"  />
+       <field id= "OBEN_N"     long_name="Benthic output nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "OBEN_FE"    long_name="Benthic output iron"                       unit="mmolFe/m2/d" />
+       <field id= "OBEN_C"     long_name="Benthic output carbon"                     unit="mmolC/m2/d"  />
+       <field id= "OBEN_SI"    long_name="Benthic output silicon"                    unit="mmolSi/m2/d" />
+       <field id= "OBEN_CA"    long_name="Benthic output CaCO3"                      unit="mmolC/m2/d"  />
+       <field id= "BEN_N"      long_name="Benthic nitrogen"                          unit="mmolN/m2"    />
+       <field id= "BEN_FE"     long_name="Benthic iron"                              unit="mmolFe/m2"   />
+       <field id= "BEN_C"      long_name="Benthic carbon"                            unit="mmolC/m2"    />
+       <field id= "BEN_SI"     long_name="Benthic silicon"                           unit="mmolSi/m2"   />
+       <field id= "BEN_CA"     long_name="Benthic CaCO3"                             unit="mmolC/m2"    />
+       <field id= "RUNOFF"     long_name="River runoff"                              unit="m/d"         />
+       <field id= "RIV_N"      long_name="Riverine input nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "RIV_SI"     long_name="Riverine input silicon"                    unit="mmolSi/m2/d" />
+       <field id= "RIV_C"      long_name="Riverine input carbon"                     unit="mmolSi/m2/d" />
+       <field id= "RIV_ALK"    long_name="Riverine input alkalinity"                 unit="meq/m2/d"    />
+       <field id= "DETC"       long_name="Slow detritus C creation"                  unit="mmolC/m2/d"  />
+       <field id= "SDC__100"   long_name="Slow detrital C flux at  100 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__200"   long_name="Slow detrital C flux at  200 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__500"   long_name="Slow detrital C flux at  500 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC_1000"   long_name="Slow detrital C flux at 1000 m"            unit="mmolC/m2/d"  />
+       <field id= "INVTC"      long_name="Column C inventory"                        unit="mmolC/m2"    />
+       <field id= "INVTALK"    long_name="Column alkalinity inventory"               unit="meq/m2"      />
+       <field id= "INVTO2"     long_name="Column O2 inventory"                       unit="mmolO2/m2"   />
+       <field id= "LYSO_CA"    long_name="Incorrect benthic output CaCO3"            unit="mmolC/m2/d"  />
+       <field id= "COM_RESP"   long_name="Community respiration"                     unit="mmolC/m2/d"  />
+       <field id= "PN_LLOSS"   long_name="Non-diatom linear losses"                  unit="mmolN/m2/d"  />
+       <field id= "PD_LLOSS"   long_name="Diatom linear losses"                      unit="mmolN/m2/d"  />
+       <field id= "ZI_LLOSS"   long_name="Microzooplankton linear losses"            unit="mmolN/m2/d"  />
+       <field id= "ZE_LLOSS"   long_name="Mesozooplankton linear losses"             unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_N"   long_name="Microzoo messy feeding loss to N"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_D"   long_name="Microzoo messy feeding loss to D"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_C"   long_name="Microzoo messy feeding loss to C"          unit="mmolC/m2/d"  />
+       <field id= "ZI_MESDC"   long_name="Microzoo messy feeding loss to Dc"         unit="mmolC/m2/d"  />
+       <field id= "ZI_EXCR"    long_name="Microzoo excretion"                        unit="mmolN/m2/d"  />
+       <field id= "ZI_RESP"    long_name="Microzoo respiration"                      unit="mmolC/m2/d"  />
+       <field id= "ZI_GROW"    long_name="Microzoo growth"                           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_N"   long_name="Mesozoo messy feeding loss to N"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_D"   long_name="Mesozoo messy feeding loss to D"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_C"   long_name="Mesozoo messy feeding loss to C"           unit="mmolC/m2/d"  />
+       <field id= "ZE_MESDC"   long_name="Mesozoo messy feeding loss to Dc"          unit="mmolC/m2/d"  />
+       <field id= "ZE_EXCR"    long_name="Mesozoo excretion"                         unit="mmolN/m2/d"  />
+       <field id= "ZE_RESP"    long_name="Mesozoo respiration"                       unit="mmolC/m2/d"  />
+       <field id= "ZE_GROW"    long_name="Mesozoo growth"                            unit="mmolN/m2/d"  />
+       <field id= "MDETC"      long_name="Detritus non-grazing losses, carbon"       unit="mmolC/m2/d"  />
+       <field id= "GMIDC"      long_name="Microzoo grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "GMEDC"      long_name="Mesozoo  grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "INT_ZMI"    long_name="Vertically integrated Zmi"                 unit="mmolN/m2"    />
+       <field id= "INT_ZME"    long_name="Vertically integrated Zme"                 unit="mmolN/m2"    />
+       <field id= "INT_DET"    long_name="Vertically integrated Det"                 unit="mmolN/m2"    />
+       <field id= "INT_DTC"    long_name="Vertically integrated Dtc"                 unit="mmolC/m2"    />
+       <field id= "DMS_SURF"   long_name="DMS Surface Concentration"                 unit="nmol/L"      />
+       <field id= "DMS_ANDR"   long_name="DMS Surface Concentration, Anderson"       unit="nmol/L"      />
+       <field id= "DMS_SIMO"   long_name="DMS Surface Concentration, SimoDach"       unit="nmol/L"      />
+       <field id= "DMS_ARAN"   long_name="DMS Surface Concentration, AranamiT"       unit="nmol/L"      />
+       <field id= "DMS_HALL"   long_name="DMS Surface Concentration, Halloran"       unit="nmol/L"      />
+
+       <!-- AXY (08/11/16): add new 2D CMIP6 diagnostics -->
+       <field id= "epC100"     long_name="Downward Flux of Particle Organic Carbon"  unit="mmolC/m2/d"  />
+       <field id= "epCALC100"  long_name="Downward Flux of Calcite"                  unit="mmolC/m2/d"  />
+       <field id= "epN100"     long_name="Downward Flux of Particulate Nitrogen"     unit="mmolN/m2/d"  />
+       <field id= "epSI100"    long_name="Downward Flux of Particulate Silica"       unit="mmolSi/m2/d" />
+       <field id= "FGCO2"      long_name="Surface Downward CO2 Flux"                 unit="kg/m2/s"     />
+       <field id= "INTDISSIC"  long_name="Dissolved Inorganic Carbon Content"        unit="mmolC/m2"    />
+       <field id= "INTDISSIN"  long_name="Dissolved Inorganic Nitrogen Content"      unit="mmolN/m2"    />
+       <field id= "INTDISSISI" long_name="Dissolved Inorganic Silicon Content"       unit="mmolSi/m2"   />
+       <field id= "INTALK"     long_name="Dissolved Alkalinity Content"              unit="meq/m2"      />
+       <field id= "O2min"      long_name="Oxygen Minimum Concentration"              unit="mmolO2/m3"   />
+       <field id= "ZO2min"     long_name="Depth of Oxygen Minimum Concentration"     unit="m"           />
+
+       <field id= "TPP3"       long_name="Total primary production 3D"               unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "DETFLUX3"   long_name="Total detrital flux 3D"                    unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMIN3N"    long_name="Total remin flux N 3D"                     unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PH3"        long_name="Ocean pH 3D"                               unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "OM_CAL3"    long_name="Omega calcite 3D"                          unit="-"             grid_ref="grid_T_3D"  />
+
+       <!-- AXY (08/11/16): add new 3D CMIP6 diagnostics -->
+       <field id= "TPPD3"      long_name="Diatom primary production 3D"              unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTALK3"   long_name="Change of Alkalinity due to Biology"       unit="meq/m3/d"      grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIC3"   long_name="Change of DI Carbon due to Biology"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTIFE3"   long_name="Change of DI Iron due to Biology"          unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "BDDTDIN3"   long_name="Change of DI Nitrogen due to Biology"      unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "BDDTDISI3"  long_name="Change of DI Silicon due to Biology"       unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_NIT3"    long_name="Fast sinking detrital nitrogen"            unit="mmolN/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_SIL3"    long_name="Fast sinking detrital silicon"             unit="mmolSi/m2/d"   grid_ref="grid_T_3D"  />
+       <field id= "FD_CAR3"    long_name="Fast sinking detrital carbon"              unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "FD_CAL3"    long_name="Fast sinking detrital calcium carbonate"   unit="mmolC/m2/d"    grid_ref="grid_T_3D"  />
+       <field id= "CO33"       long_name="Carbonate ion concentration"               unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATARG3" long_name="Carbonate aragonite saturation conc"       unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "CO3SATCAL3" long_name="Carbonate calcite saturation conc"         unit="mmolC/m3"      grid_ref="grid_T_3D"  />
+       <field id= "DCALC3"     long_name="Calcite dissolution"                       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPC3"      long_name="Downward Flux of Particulate Org Carbon"   unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "EXPN3"      long_name="Downward Flux of Particulate Org Nitrogen" unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "FEDISS3"    long_name="Particle Source of Dissolved Iron"         unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "FESCAV3"    long_name="Nonbiogenic Iron Scavenging"               unit="mmolFe/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZP3"   long_name="Microzooplankton grazing on phytoplankton" unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MIGRAZD3"   long_name="Microzooplankton grazing on detritus"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZP3"   long_name="Mesozooplankton grazing on phytoplankton"  unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZD3"   long_name="Mesozooplankton grazing on detritus"       unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "MEGRAZZ3"   long_name="Mesozooplankton grazing on microzoop"      unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "O2SAT3"     long_name="Dissolved Oxygen Saturation Concentration" unit="mmolO2/m3"     grid_ref="grid_T_3D"  />
+       <field id= "PBSI3"      long_name="Biogenic Silica Production"                unit="mmolSi/m3/d"   grid_ref="grid_T_3D"  />
+       <field id= "PCAL3"      long_name="Biogenic Calcite Production"               unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMOC3"     long_name="Remineralization of Organic Carbon"        unit="mmolC/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PNLIMJ3"    long_name="Irradiance limitation of non-diatoms"      unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMN3"    long_name="Nitrogen limitation of non-diatoms"        unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PNLIMFE3"   long_name="Iron limitation of non-diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMJ3"    long_name="Irradiance limitation of diatoms"          unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMN3"    long_name="Nitrogen limitation of diatoms"            unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMFE3"   long_name="Iron limitation of diatoms"                unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "PDLIMSI3"   long_name="Silicon limitation of diatoms"             unit="-"             grid_ref="grid_T_3D"  />
+
+     </field_group>
+
+     <field_group id="PISCES_scalar"  domain_ref="1point" >
+       <field id="pno3tot"         long_name="global mean nitrate concentration"                  unit="mol/m3"   />
+       <field id="ppo4tot"         long_name="global mean phosphorus concentration"               unit="mol/m3"   />
+       <field id="psiltot"         long_name="global mean silicate concentration"                 unit="mol/m3"   />
+       <field id="palktot"         long_name="global mean alkalinity concentration"               unit="mol/m3"   />
+       <field id="pfertot"         long_name="global mean iron concentration"                     unit="mol/m3"   />
+       <field id="tcflx"           long_name="total Flux of Carbon out of the ocean"              unit="mol/s"   />
+       <field id="tcflxcum"        long_name="cumulative total Flux of Carbon out of the ocean"   unit="mol/s"   />
+       <field id="tcexp"           long_name="total Carbon export at 100m"                        unit="mol/s"   />
+       <field id="tintpp"          long_name="global total integrated primary production"         unit="mol/s"   />
+       <field id="tnfix"           long_name="global total nitrogen fixation"                     unit="mol/s"   />
+       <field id="tdenit"          long_name="Total denitrification"                              unit="mol/s"   />
+     </field_group>
+
+    <!-- 
+============================================================================================================
+                                        Definitions for iodef_demo.xml
+============================================================================================================
+    -->
+
+    <field_group id="groupMEDUSA" >
+      <field field_ref="CHN"   name="CHN"   />
+      <field field_ref="CHD"   name="CHD"   />
+      <field field_ref="PHN"   name="PHN"   />
+      <field field_ref="PHD"   name="PHD"   />
+      <field field_ref="ZMI"   name="ZMI"   />
+      <field field_ref="ZME"   name="ZME"   />
+      <field field_ref="DIN"   name="DIN"   />
+      <field field_ref="SIL"   name="SIL"   />
+      <field field_ref="FER"   name="FER"   />
+      <field field_ref="DET"   name="DET"   />
+      <field field_ref="PDS"   name="PDS"   />
+      <field field_ref="DTC"   name="DTC"   />
+      <field field_ref="DiC"   name="DIC"   />
+      <field field_ref="ALK"   name="ALK"   />
+      <field field_ref="OXY"   name="OXY"   />
+      </field_group>
+
+    <field_group id="groupIDTRA" >
+      <field field_ref="IDTRA" name="IDTRA" />
+    </field_group>
+
+    <field_group id="groupIDTRA_dia" >
+      <field field_ref="qtrIDTRA"    name="qtrIDTRA"  />
+      <field field_ref="qintIDTRA"   name="qintIDTRA" />
+      <field field_ref="invIDTRA"    name="invIDTRA"  />
+    </field_group>
+
+    <field_group id="groupCFC" >
+      <field field_ref="CFC11" name="CFC11" />
+    </field_group>
+
+    <field_group id="groupCFC_dia" >
+      <field field_ref="qtrCFC11"    name="qtrCFC11"   />
+      <field field_ref="qintCFC11"   name="qintCFC11"  />
+    </field_group>
+
+    <field_group id="groupAGE" >
+      <field field_ref="Age" name="Age" />
+    </field_group>
+
+    <field_group id="groupMEDUSA_dia" >
+      <field field_ref= "INVTN"      name="INVTN"      />
+      <field field_ref= "INVTSI"     name="INVTSI"     />
+      <field field_ref= "INVTFE"     name="INVTFE"     />
+      <field field_ref= "PRN"        name="PRN"        />
+      <field field_ref= "MPN"        name="MPN"        />
+      <field field_ref= "PRD"        name="PRD"        />
+      <field field_ref= "MPD"        name="MPD"        />
+      <field field_ref= "OPAL"       name="OPAL"       />
+      <field field_ref= "OPALDISS"   name="OPALDISS"   />
+      <field field_ref= "GMIPn"      name="GMIPn"      />
+      <field field_ref= "GMID"       name="GMID"       />
+      <field field_ref= "MZMI"       name="MZMI"       />
+      <field field_ref= "GMEPN"      name="GMEPN"      />
+      <field field_ref= "GMEPD"      name="GMEPD"      />
+      <field field_ref= "GMEZMI"     name="GMEZMI"     />
+      <field field_ref= "GMED"       name="GMED"       />
+      <field field_ref= "MZME"       name="MZME"       />
+      <field field_ref= "DETN"       name="DETN"       />
+      <field field_ref= "MDET"       name="MDET"       />
+      <field field_ref= "AEOLIAN"    name="AEOLIAN"    />
+      <field field_ref= "BENTHIC"    name="BENTHIC"    />
+      <field field_ref= "SCAVENGE"   name="SCAVENGE"   />
+      <field field_ref= "PN_JLIM"    name="PN_JLIM"    />
+      <field field_ref= "PN_NLIM"    name="PN_NLIM"    />
+      <field field_ref= "PN_FELIM"   name="PN_FELIM"   />
+      <field field_ref= "PD_JLIM"    name="PD_JLIM"    />
+      <field field_ref= "PD_NLIM"    name="PD_NLIM"    />
+      <field field_ref= "PD_FELIM"   name="PD_FELIM"   />
+      <field field_ref= "PD_SILIM"   name="PD_SILIM"   />
+      <field field_ref= "PDSILIM2"   name="PDSILIM2"   />
+      <field field_ref= "SDT__100"   name="SDT__100"   />
+      <field field_ref= "SDT__200"   name="SDT__200"   />
+      <field field_ref= "SDT__500"   name="SDT__500"   />
+      <field field_ref= "SDT_1000"   name="SDT_1000"   />
+      <field field_ref= "TOTREG_N"   name="TOTREG_N"   />
+      <field field_ref= "TOTRG_SI"   name="TOTRG_SI"   />
+      <field field_ref= "REG__100"   name="REG__100"   />
+      <field field_ref= "REG__200"   name="REG__200"   />
+      <field field_ref= "REG__500"   name="REG__500"   />
+      <field field_ref= "REG_1000"   name="REG_1000"   />
+      <field field_ref= "FASTN"      name="FASTN"      />
+      <field field_ref= "FASTSI"     name="FASTSI"     />
+      <field field_ref= "FASTFE"     name="FASTFE"     />
+      <field field_ref= "FASTC"      name="FASTC"      />
+      <field field_ref= "FASTCA"     name="FASTCA"     />
+      <field field_ref= "FDT__100"   name="FDT__100"   />
+      <field field_ref= "FDT__200"   name="FDT__200"   />
+      <field field_ref= "FDT__500"   name="FDT__500"   />
+      <field field_ref= "FDT_1000"   name="FDT_1000"   /> 
+      <field field_ref= "RG__100F"   name="RG__100F"   />
+      <field field_ref= "RG__200F"   name="RG__200F"   />
+      <field field_ref= "RG__500F"   name="RG__500F"   />
+      <field field_ref= "RG_1000F"   name="RG_1000F"   />
+      <field field_ref= "FDS__100"   name="FDS__100"   />
+      <field field_ref= "FDS__200"   name="FDS__200"   />
+      <field field_ref= "FDS__500"   name="FDS__500"   />
+      <field field_ref= "FDS_1000"   name="FDS_1000"   />
+      <field field_ref= "RGS_100F"   name="RGS_100F"   />
+      <field field_ref= "RGS_200F"   name="RGS_200F"   />
+      <field field_ref= "RGS_500F"   name="RGS_500F"   />
+      <field field_ref= "RGS1000F"   name="RGS1000F"   />
+      <field field_ref= "REMINN"     name="REMINN"     />
+      <field field_ref= "REMINSI"    name="REMINSI"    />
+      <field field_ref= "REMINFE"    name="REMINFE"    />
+      <field field_ref= "SEAFLRN"    name="SEAFLRN"    /> 
+      <field field_ref= "SEAFLRSI"   name="SEAFLRSI"   />
+      <field field_ref= "SEAFLRFE"   name="SEAFLRFE"   />
+      <field field_ref= "SEAFLRC"    name="SEAFLRC"    />
+      <field field_ref= "SEAFLRCA"   name="SEAFLRCA"   />
+      <field field_ref= "MED_QSR"    name="MED_QSR"    />
+      <field field_ref= "MED_XPAR"   name="MED_XPAR"   />
+      <field field_ref= "INTFLX_N"   name="INTFLX_N"   />
+      <field field_ref= "INTFLX_SI"  name="INTFLX_SI"  />
+      <field field_ref= "INTFLX_FE"  name="INTFLX_FE"  />
+      <field field_ref= "INT_PN"     name="INT_PN"     />
+      <field field_ref= "INT_PD"     name="INT_PD"     />
+      <field field_ref= "ML_PRN"     name="ML_PRN"     />
+      <field field_ref= "ML_PRD"     name="ML_PRD"     />
+      <field field_ref= "OCAL_CCD"   name="OCAL_CCD"   />
+      <field field_ref= "OCAL_LVL"   name="OCAL_LVL"   />
+      <field field_ref= "FE_0000"    name="FE_0000"    />
+      <field field_ref= "FE_0100"    name="FE_0100"    />
+      <field field_ref= "FE_0200"    name="FE_0200"    /> 
+      <field field_ref= "FE_0500"    name="FE_0500"    />
+      <field field_ref= "FE_1000"    name="FE_1000"    />
+      <field field_ref= "MED_XZE"    name="MED_XZE"    />
+      <field field_ref= "WIND"       name="WIND"       />
+      <field field_ref= "ATM_PCO2"   name="ATM_PCO2"   />
+      <field field_ref= "OCN_PH"     name="OCN_PH"     />
+      <field field_ref= "OCN_PCO2"   name="OCN_PCO2"   />
+      <field field_ref= "OCNH2CO3"   name="OCNH2CO3"   />
+      <field field_ref= "OCN_HCO3"   name="OCN_HCO3"   />
+      <field field_ref= "OCN_CO3"    name="OCN_CO3"    />
+      <field field_ref= "CO2FLUX"    name="CO2FLUX"    />
+      <field field_ref= "OM_CAL"     name="OM_CAL"     />
+      <field field_ref= "OM_ARG"     name="OM_ARG"     />
+      <field field_ref= "TCO2"       name="TCO2"       />
+      <field field_ref= "TALK"       name="TALK"       />
+      <field field_ref= "KW660"      name="KW660"      />
+      <field field_ref= "ATM_PP0"    name="ATM_PP0"    />
+      <field field_ref= "O2FLUX"     name="O2FLUX"     />
+      <field field_ref= "O2SAT"      name="O2SAT"      />
+      <field field_ref= "CAL_CCD"    name="CAL_CCD"    />
+      <field field_ref= "ARG_CCD"    name="ARG_CCD"    />
+      <field field_ref= "SFR_OCAL"   name="SFR_OCAL"   />
+      <field field_ref= "SFR_OARG"   name="SFR_OARG"   />
+      <field field_ref= "N_PROD"     name="N_PROD"     />
+      <field field_ref= "N_CONS"     name="N_CONS"     />
+      <field field_ref= "C_PROD"     name="C_PROD"     />
+      <field field_ref= "C_CONS"     name="C_CONS"     />
+      <field field_ref= "O2_PROD"    name="O2_PROD"    />
+      <field field_ref= "O2_CONS"    name="O2_CONS"    />
+      <field field_ref= "O2_ANOX"    name="O2_ANOX"    />
+      <field field_ref= "RR_0100"    name="RR_0100"    />
+      <field field_ref= "RR_0500"    name="RR_0500"    />
+      <field field_ref= "RR_1000"    name="RR_1000"    />
+      <field field_ref= "IBEN_N"     name="IBEN_N"     />
+      <field field_ref= "IBEN_FE"    name="IBEN_FE"    />
+      <field field_ref= "IBEN_C"     name="IBEN_C"     />
+      <field field_ref= "IBEN_SI"    name="IBEN_SI"    />
+      <field field_ref= "IBEN_CA"    name="IBEN_CA"    />
+      <field field_ref= "OBEN_N"     name="OBEN_N"     />
+      <field field_ref= "OBEN_FE"    name="OBEN_FE"    />
+      <field field_ref= "OBEN_C"     name="OBEN_C"     />
+      <field field_ref= "OBEN_SI"    name="OBEN_SI"    />
+      <field field_ref= "OBEN_CA"    name="OBEN_CA"    />
+      <field field_ref= "BEN_N"      name="BEN_N"      />
+      <field field_ref= "BEN_FE"     name="BEN_FE"     />
+      <field field_ref= "BEN_C"      name="BEN_C"      />
+      <field field_ref= "BEN_SI"     name="BEN_SI"     />
+      <field field_ref= "BEN_CA"     name="BEN_CA"     />
+      <field field_ref= "DETC"       name="DETC"       />
+      <field field_ref= "SDC__100"   name="SDC__100"   />
+      <field field_ref= "SDC__200"   name="SDC__200"   />
+      <field field_ref= "SDC__500"   name="SDC__500"   />
+      <field field_ref= "SDC_1000"   name="SDC_1000"   />
+      <field field_ref= "INVTC"      name="INVTC"      />
+      <field field_ref= "INVTALK"    name="INVTALK"    />
+      <field field_ref= "INVTO2"     name="INVTO2"     />
+      <field field_ref= "LYSO_CA"    name="LYSO_CA"    />
+      <field field_ref= "COM_RESP"   name="COM_RESP"   />
+      <field field_ref= "PN_LLOSS"   name="PN_LLOSS"   />
+      <field field_ref= "PD_LLOSS"   name="PD_LLOSS"   />
+      <field field_ref= "ZI_LLOSS"   name="ZI_LLOSS"   />
+      <field field_ref= "ZE_LLOSS"   name="ZE_LLOSS"   />
+      <field field_ref= "ZI_MES_N"   name="ZI_MES_N"   />
+      <field field_ref= "ZI_MES_D"   name="ZI_MES_D"   />
+      <field field_ref= "ZI_MES_C"   name="ZI_MES_C"   />
+      <field field_ref= "ZI_MESDC"   name="ZI_MESDC"   />
+      <field field_ref= "ZI_EXCR"    name="ZI_EXCR"    />
+      <field field_ref= "ZI_RESP"    name="ZI_RESP"    />
+      <field field_ref= "ZI_GROW"    name="ZI_GROW"    />
+      <field field_ref= "ZE_MES_N"   name="ZE_MES_N"   />
+      <field field_ref= "ZE_MES_D"   name="ZE_MES_D"   />
+      <field field_ref= "ZE_MES_C"   name="ZE_MES_C"   />
+      <field field_ref= "ZE_MESDC"   name="ZE_MESDC"   />
+      <field field_ref= "ZE_EXCR"    name="ZE_EXCR"    />
+      <field field_ref= "ZE_RESP"    name="ZE_RESP"    />
+      <field field_ref= "ZE_GROW"    name="ZE_GROW"    />
+      <field field_ref= "MDETC"      name="MDETC"      />
+      <field field_ref= "GMIDC"      name="GMIDC"      />
+      <field field_ref= "GMEDC"      name="GMEDC"      />
+      <field field_ref= "INT_ZMI"    name="INT_ZMI"    />
+      <field field_ref= "INT_ZME"    name="INT_ZME"    />
+      <field field_ref= "INT_DET"    name="INT_DET"    />
+      <field field_ref= "INT_DTC"    name="INT_DTC"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_3dd" >
+      <field field_ref= "TPP3"       name="TPP3"       />
+      <field field_ref= "DETFLUX3"   name="DETFLUX3"   />
+      <field field_ref= "REMIN3N"    name="REMIN3N"    />
+      <field field_ref= "PH3"        name="PH3"        />
+      <field field_ref= "OM_CAL3"    name="OM_CAL3"    /> 
+    </field_group>
+
+    <field_group id="groupMEDUSA_dms" >
+      <field field_ref= "DMS_SURF"   name="DMS_SURF"   />
+      <field field_ref= "DMS_ANDR"   name="DMS_ANDR"   />
+      <field field_ref= "DMS_SIMO"   name="DMS_SIMO"   />
+      <field field_ref= "DMS_ARAN"   name="DMS_ARAN"   />
+      <field field_ref= "DMS_HALL"   name="DMS_HALL"   />
+    </field_group>
+
+    <field_group id="groupMEDUSA_riv" >
+      <field field_ref= "RUNOFF"     name="RUNOFF"     />
+      <field field_ref= "RIV_N"      name="RIV_N"      />
+      <field field_ref= "RIV_SI"     name="RIV_SI"     />
+      <field field_ref= "RIV_C"      name="RIV_C"      />
+      <field field_ref= "RIV_ALK"    name="RIV_ALK"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_cmip6" >
+      <field field_ref= "epC100"     name="epC100"     />
+      <field field_ref= "epCALC100"  name="epCALC100"  />
+      <field field_ref= "epN100"     name="epN100"     />
+      <field field_ref= "epSI100"    name="epSI100"    />
+      <field field_ref= "FGCO2"      name="FGCO2"      />
+      <field field_ref= "INTDISSIC"  name="INTDISSIC"  />
+      <field field_ref= "INTDISSIN"  name="INTDISSIN"  />
+      <field field_ref= "INTDISSISI" name="INTDISSISI" />
+      <field field_ref= "INTALK"     name="INTALK"     />
+      <field field_ref= "O2min"      name="O2min"      />
+      <field field_ref= "ZO2min"     name="ZO2min"     />
+      <field field_ref= "TPPD3"      name="TPPD3"      />
+      <field field_ref= "BDDTALK3"   name="BDDTALK3"   />
+      <field field_ref= "BDDTDIC3"   name="BDDTDIC3"   />
+      <field field_ref= "BDDTIFE3"   name="BDDTIFE3"   />
+      <field field_ref= "BDDTDIN3"   name="BDDTDIN3"   />
+      <field field_ref= "BDDTDISI3"  name="BDDTDISI3"  />
+      <field field_ref= "FD_NIT3"    name="FD_NIT3"    />
+      <field field_ref= "FD_SIL3"    name="FD_SIL3"    />
+      <field field_ref= "FD_CAR3"    name="FD_CAR3"    />
+      <field field_ref= "FD_CAL3"    name="FD_CAL3"    />
+      <field field_ref= "CO33"       name="CO33"       />
+      <field field_ref= "CO3SATARG3" name="CO3SATARG3" />
+      <field field_ref= "CO3SATCAL3" name="CO3SATCAL3" />
+      <field field_ref= "DCALC3"     name="DCALC3"     />
+      <field field_ref= "EXPC3"      name="EXPC3"      />
+      <field field_ref= "EXPN3"      name="EXPN3"      />
+      <field field_ref= "FEDISS3"    name="FEDISS3"    />
+      <field field_ref= "FESCAV3"    name="FESCAV3"    />
+      <field field_ref= "MIGRAZP3"   name="MIGRAZP3"   />
+      <field field_ref= "MIGRAZD3"   name="MIGRAZD3"   />
+      <field field_ref= "MEGRAZP3"   name="MEGRAZP3"   />
+      <field field_ref= "MEGRAZD3"   name="MEGRAZD3"   />
+      <field field_ref= "MEGRAZZ3"   name="MEGRAZZ3"   />
+      <field field_ref= "O2SAT3"     name="O2SAT3"     />
+      <field field_ref= "PBSI3"      name="PBSI3"      />
+      <field field_ref= "PCAL3"      name="PCAL3"      />
+      <field field_ref= "REMOC3"     name="REMOC3"     />
+      <field field_ref= "PNLIMJ3"    name="PNLIMJ3"    />
+      <field field_ref= "PNLIMN3"    name="PNLIMN3"    />
+      <field field_ref= "PNLIMFE3"   name="PNLIMFE3"   />
+      <field field_ref= "PDLIMJ3"    name="PDLIMJ3"    />
+      <field field_ref= "PDLIMN3"    name="PDLIMN3"    />
+      <field field_ref= "PDLIMFE3"   name="PDLIMFE3"   />
+      <field field_ref= "PDLIMSI3"   name="PDLIMSI3"   />
+    </field_group>
+
+</field_definition>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc_rev-7112.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc_rev-7112.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_bgc_rev-7112.xml	(revision 7693)
@@ -0,0 +1,776 @@
+<!--
+<?xml version="1.0"?>
+       -->
+ 
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+   <field_definition level="1" prec="8" operation="average" enabled=".TRUE." default_value="1.e20" > <!-- time step automaticaly defined -->
+
+    <!-- 
+============================================================================================================
+                                     Biogeochemistry model variables
+============================================================================================================
+    -->
+
+      <!-- ptrc on T grid -->
+
+     <field_group id="ptrc_T" grid_ref="grid_T_3D">
+       <field id="DIC"          long_name="Dissolved inorganic Concentration"        unit="mmol/m3" />
+       <field id="DIC_E3T"      long_name="DIC * E3T"                                unit="mmol/m2" > DIC * e3t </field >
+       <field id="Alkalini"     long_name="Total Alkalinity Concentration"           unit="mmol/m3" />
+       <field id="Alkalini_E3T" long_name="Alkalini * E3T"                           unit="mmol/m2"  > Alkalini * e3t </field >
+       <field id="O2"           long_name="Oxygen Concentration"                     unit="mmol/m3" />
+       <field id="O2_E3T"       long_name="O2 * E3T"                                 unit="mmol/m2"  > O2 * e3t </field >
+       <field id="CaCO3"        long_name="Calcite Concentration"                    unit="mmol/m3" />
+       <field id="CaCO3_E3T"    long_name="CaCO3 * E3T"                              unit="mmol/m2"  > CaCO3 * e3t </field >
+       <field id="PO4"          long_name="Phosphate Concentration"                  unit="mmol/m3" />
+       <field id="PO4_E3T"      long_name="PO4 * E3T"                                unit="mmol/m2"  > PO4 * e3t </field >
+       <field id="POC"          long_name="Small organic carbon Concentration"       unit="mmol/m3" />
+       <field id="POC_E3T"      long_name="POC * E3T"                                unit="mmol/m2"  > POC * e3t </field >
+       <field id="Si"           long_name="Silicate Concentration"                   unit="mmol/m3" />
+       <field id="Si_E3T"       long_name="Si * E3T"                                 unit="mmol/m2"  > Si * e3t </field >
+       <field id="PHY"          long_name="(Nano)Phytoplankton Concentration"        unit="mmol/m3" />
+       <field id="PHY_E3T"      long_name="PHY * E3T"                                unit="mmol/m2"  > PHY * e3t </field >
+       <field id="ZOO"          long_name="(Micro)Zooplankton Concentration"         unit="mmol/m3" />
+       <field id="ZOO_E3T"      long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO * e3t </field >
+       <field id="DOC"          long_name="Dissolved organic Concentration"          unit="mmol/m3" />
+       <field id="DOC_E3T"      long_name="DOC * E3T"                                unit="mmol/m2"  > DOC * e3t </field >
+       <field id="PHY2"         long_name="Diatoms Concentration"                    unit="mmol/m3" />
+       <field id="PHY2_E3T"     long_name="PHY2 * E3T"                               unit="mmol/m2"  > PHY2 * e3t </field >
+       <field id="ZOO2"         long_name="Mesozooplankton Concentration"            unit="mmol/m3" />
+       <field id="ZOO2_E3T"     long_name="ZOO2 * E3T"                               unit="mmol/m2"  > ZOO2 * e3t </field >
+       <field id="DSi"          long_name="Diatoms Silicate Concentration"           unit="mmol/m3" />
+       <field id="DSi_E3T"      long_name="Dsi * E3T"                                unit="mmol/m2"  > DSi * e3t </field >
+       <field id="Fer"          long_name="Dissolved Iron Concentration"             unit="mmol/m3" />
+       <field id="Fer_E3T"      long_name="Fer * E3T"                                unit="mmol/m2"  > Fer * e3t </field >
+       <field id="BFe"          long_name="Big iron particles Concentration"         unit="mmol/m3" />
+       <field id="BFe_E3T"      long_name="BFe * E3T"                                unit="mmol/m2"  > BFe * e3t </field >
+       <field id="GOC"          long_name="Big organic carbon Concentration"         unit="mmol/m3" />
+       <field id="GOC_E3T"      long_name="GOC * E3T"                                unit="mmol/m2"  > GOC * e3t </field >
+       <field id="SFe"          long_name="Small iron particles Concentration"       unit="mmol/m3" />
+       <field id="SFe_E3T"      long_name="SFe * E3T"                                unit="mmol/m2"  > SFe * e3t </field >
+       <field id="DFe"          long_name="Diatoms iron  Concentration"              unit="mmol/m3" />
+       <field id="DFe_E3T"      long_name="DFe * E3T"                                unit="mmol/m2"  > DFe * e3t </field >
+       <field id="GSi"          long_name="Sinking biogenic Silicate Concentration"  unit="mmol/m3" />
+       <field id="GSi_E3T"      long_name="GSi * E3T"                                unit="mmol/m2"  > GSi * e3t </field >
+       <field id="NFe"          long_name="Nano iron Concentration"                  unit="mmol/m3" />
+       <field id="NFe_E3T"      long_name="NFe * E3T"                                unit="mmol/m2"  > NFe * e3t </field >
+       <field id="NCHL"         long_name="Nano chlorophyl Concentration"            unit="mg/m3"   />
+       <field id="NCHL_E3T"     long_name="NCHL * E3T"                               unit="mmol/m2"  > NCHL * e3t </field >
+       <field id="DCHL"         long_name="Diatoms chlorophyl Concentration"         unit="mg/m3"   />
+       <field id="DCHL_E3T"     long_name="DCHL * E3T"                               unit="mmol/m2"  > DCHL * e3t </field >
+       <field id="NO3"          long_name="Nitrate Concentration"                    unit="mmol/m3" />
+       <field id="NO3_E3T"      long_name="NO3 * E3T"                                unit="mmol/m2"  > NO3 * e3t </field >
+       <field id="NH4"          long_name="Ammonium Concentration"                   unit="mmol/m3" />
+       <field id="NH4_E3T"      long_name="NH4 * E3T"                                unit="mmol/m2"  > NH4 * e3t </field >
+
+      <!-- MEDUSA : variables available with key_medusa -->
+       <field id="CHN"      long_name="Chl-a concentration in non-diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="CHD"      long_name="Chl-a concentration in     diatom phytoplankton"   unit="mg Chl/m3" />
+       <field id="PHN"      long_name="non-diatom phytoplankton"                          unit="mmol-N/m3" />
+       <field id="PHD"      long_name="diatom phytoplankton"                              unit="mmol-N/m3" />
+       <field id="ZMI"      long_name="micro zooplankton"                                 unit="mmol-N/m3" />
+       <field id="ZME"      long_name="meso  zooplankton"                                 unit="mmol-N/m3" />
+       <field id="DIN"      long_name="dissolved inorganic nitrogen"                      unit="mmol-N/m3" />
+       <field id="SIL"      long_name="silicate"                                          unit="mmolSi/m3" />
+       <field id="FER"      long_name="dissolved iron"                                    unit="mmolFe/m3" />
+       <field id="DET"      long_name="detrital nitrogen"                                 unit="mmol-N/m3" />
+       <field id="PDS"      long_name="biogenic silicon in diatom phytoplankton"          unit="mmolSi/m3" />
+       <field id="DTC"      long_name="detrital carbon"                                   unit="mmol-C/m3" />
+       <field id="DiC"      long_name="dissolved inorganic carbon"                        unit="mmol-C/m3" />
+       <field id="ALK"      long_name="alkalinity"                                        unit="meq/m3"    />
+       <field id="OXY"      long_name="dissolved oxygen"                                  unit="mmolO2/m3" />
+
+      <!-- Ideal traceurs : variables available with key_idtra -->
+       <field id="IDTRA"    long_name="Ideal traceur concentration "                      unit="mmol/m3"    />
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="Num"         long_name="Number of organic particles"              unit="1" />
+       <field id="Num_E3T"     long_name="Num * E3T"                                unit="m"  > Num * e3t </field >
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="DET"         long_name="Detritus"                                 unit="mmol-N/m3" />
+       <field id="DET_E3T"     long_name="DET * E3T"                                unit="mmol-N/m2"  > DET * e3t </field >
+       <field id="DOM"         long_name="Dissolved Organic Matter"                 unit="mmol-N/m3" />
+       <field id="DOM_E3T"     long_name="DOM * E3T"                                unit="mmol-N/m2"  > DOM * e3t </field >
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="CFC11"       long_name="CFC-11 Concentration"                     unit="umol/m3" />
+       <field id="CFC11_E3T"   long_name="CFC11 * E3T"                              unit="umol/m2"  > CFC11 * e3t </field >
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="C14B"        long_name="Bomb C14 Concentration"                   unit="1"         />
+       <field id="C14B_E3T"    long_name="C14B * E3T"                               unit="m"  > C14B * e3t </field >
+       <!-- AGE : variables available with key_age -->
+       <field id="Age"        long_name="Sea Water Age Since Surface contact" standard_name="sea_water_age_since_surface_contact"  unit="yr"         />
+       <field id="Age_e3t"    long_name="Age * e3t"                                 unit="yr * m"  > Age * e3t </field >
+     </field_group>
+
+     <!-- PISCES additional diagnostics on T grid  -->
+
+     <field_group id="diad_T" grid_ref="grid_T_2D">
+       <field id="PH"          long_name="PH"                                      unit="1"          grid_ref="grid_T_3D" />
+       <field id="CO3"         long_name="Bicarbonates"                            unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="CO3sat"      long_name="CO3 saturation"                          unit="mol/m3"     grid_ref="grid_T_3D" />
+       <field id="PAR"         long_name="Photosynthetically Available Radiation"  unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PARDM"       long_name="Daily mean PAR"                          unit="W/m2"       grid_ref="grid_T_3D" />
+       <field id="PPPHY"       long_name="Primary production of nanophyto"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPPHY2"      long_name="Primary production of diatoms"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWN"      long_name="New Primary production of nanophyto"     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PPNEWD"      long_name="New Primary production of diatoms"       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PBSi"        long_name="Primary production of Si diatoms"        unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeN"        long_name="Primary production of nano iron"         unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="PFeD"        long_name="Primary production of diatoms iron"      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="xfracal"     long_name="Calcifying fraction"                     unit="1"          grid_ref="grid_T_3D" />
+       <field id="PCAL"        long_name="Calcite production"                      unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DCAL"        long_name="Calcite dissolution"                     unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ1"       long_name="Grazing by microzooplankton"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="GRAZ2"       long_name="Grazing by mesozooplankton"              unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="REMIN"       long_name="Oxic remineralization of OM"             unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="DENIT"       long_name="Anoxic remineralization of OM"           unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Nfix"        long_name="Nitrogen fixation"                       unit="mol/m3/s"   grid_ref="grid_T_3D" />
+       <field id="Mumax"       long_name="Maximum growth rate"                     unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuN"         long_name="Realized growth rate for nanophyto"      unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="MuD"         long_name="Realized growth rate for diatomes"       unit="s-1"        grid_ref="grid_T_3D" />
+       <field id="LNnut"       long_name="Nutrient limitation term in Nanophyto"   unit=""           grid_ref="grid_T_3D" />
+       <field id="LDnut"       long_name="Nutrient limitation term in Diatoms"     unit=""           grid_ref="grid_T_3D" />
+       <field id="LNFe"        long_name="Iron limitation term in Nanophyto"       unit=""           grid_ref="grid_T_3D" />
+       <field id="LDFe"        long_name="Iron limitation term in Diatoms"         unit=""           grid_ref="grid_T_3D" />
+       <field id="LNlight"     long_name="Light limitation term in Nanophyto"      unit=""           grid_ref="grid_T_3D" />
+       <field id="LDlight"     long_name="Light limitation term in Diatoms"        unit=""           grid_ref="grid_T_3D" />
+       <field id="Fe2"         long_name="Iron II concentration"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Fe3"         long_name="Iron III concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL1"        long_name="Complexed Iron concentration with L1"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeL2"        long_name="Complexed Iron concentration with L2"    unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="FeP"         long_name="Precipitated Iron III"                   unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL1"         long_name="Total L1 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="TL2"         long_name="Total L2 concentration"                  unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="pdust"       long_name="dust concentration"                      unit="g/m3"                            />
+       <field id="Totlig"      long_name="Total ligand concentation"               unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Biron"       long_name="Bioavailable iron"                       unit="nmol/m3"    grid_ref="grid_T_3D" />
+       <field id="Sdenit"      long_name="Nitrate reduction in the sediments"      unit="mol/m2/s"                        />
+       <field id="Ironice"     long_name="Iron input/uptake due to sea ice"        unit="mol/m2/s"                        />
+       <field id="HYDR"        long_name="Iron input from hydrothemal vents"       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EPC100"      long_name="Export of carbon particles at 100 m"     unit="mol/m2/s"                        />
+       <field id="EPFE100"     long_name="Export of biogenic iron at 100 m"        unit="mol/m2/s"                        />
+       <field id="EPSI100"     long_name="Export of Silicate at 100 m"             unit="mol/m2/s"                        />
+       <field id="EPCAL100"    long_name="Export of Calcite at 100 m"              unit="mol/m2/s"                        />
+       <field id="EXPC"        long_name="Export of carbon"                        unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPFE"       long_name="Export of biogenic iron"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPSI"       long_name="Export of Silicate"                      unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="EXPCAL"      long_name="Export of Calcite"                       unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="Cflx"        long_name="DIC flux"                                unit="mol/m2/s"                        />
+       <field id="Oflx"        long_name="Oxygen flux"                             unit="mol/m2/s"                        />
+       <field id="Kg"          long_name="Gas transfer"                            unit="mol/m2/s/uatm"                   />
+       <field id="Dpco2"       long_name="Delta CO2"                               unit="uatm"                            />
+       <field id="Dpo2"        long_name="Delta O2"                                unit="uatm"                            />
+       <field id="Heup"        long_name="Euphotic layer depth"                    unit="m"                               />
+       <field id="Irondep"     long_name="Iron deposition from dust"               unit="mol/m2/s"                        />
+       <field id="Ironsed"     long_name="Iron deposition from sediment"           unit="mol/m2/s"   grid_ref="grid_T_3D" />
+
+
+       <!-- PISCES with Kriest parametisation : variables available with key_kriest -->
+       <field id="EPN100"      long_name="Particulate number flux at 100 m"        unit="mol/m2/s"                        />
+       <field id="EXPN"        long_name="Particulate number flux"                 unit="mol/m2/s"   grid_ref="grid_T_3D" />
+       <field id="XNUM"        long_name="Number of particles in aggregats"        unit="1"          grid_ref="grid_T_3D" />
+       <field id="WSC"         long_name="sinking speed of mass flux"              unit="m2/s"       grid_ref="grid_T_3D" />
+       <field id="WSN"         long_name="sinking speed of number flux"            unit="m2/s"       grid_ref="grid_T_3D" />
+
+       <!-- dbio_T on T grid : variables available with key_diaar5 -->
+       <field id="TPP"         long_name="Total Primary production of phyto"                   unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPNEW"       long_name="New Primary production of phyto"                     unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="TPBFE"       long_name="Total biogenic iron production"                      unit="mol/m3/s"  grid_ref="grid_T_3D" />
+       <field id="INTDIC"      long_name="DIC content"                                         unit="kg/m2"                          />
+       <field id="O2MIN"       long_name="Oxygen minimum concentration"                        unit="mol/m3"                          />
+       <field id="ZO2MIN"      long_name="Depth of oxygen minimum concentration"               unit="m"                              />
+       <field id="INTNFIX"     long_name="Nitrogen fixation rate : vert. integrated"           unit="mol/m2/s"                       />
+       <field id="INTPPPHY"    long_name="Vertically integrated primary production by nanophy" unit="mol/m2/s"                       />
+       <field id="INTPPPHY2"   long_name="Vertically integrated primary production by diatom"  unit="mol/m2/s"                       />
+       <field id="INTPP"       long_name="Vertically integrated primary production by phyto"   unit="mol/m2/s"                       />
+       <field id="INTPNEW"     long_name="Vertically integrated new primary production"        unit="mol/m2/s"                       />
+       <field id="INTPBFE"     long_name="Vertically integrated of biogenic iron production"   unit="mol/m2/s"                       />
+       <field id="INTPBSI"     long_name="Vertically integrated of biogenic Si production"     unit="mol/m2/s"                       />
+       <field id="INTPCAL"     long_name="Vertically integrated of calcite production"         unit="mol/m2/s"                       />
+
+       <!-- PISCES light : variables available with key_pisces_reduced -->
+       <field id="FNO3PHY"     long_name="FNO3PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4PHY"     long_name="FNH4PHY"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="FNH4NO3"     long_name="FNH4NO3"                                 unit=""          grid_ref="grid_T_3D" /> 
+       <field id="TNO3PHY"     long_name="TNO3PHY"                                 unit=""  /> 
+       <field id="TNH4PHY"     long_name="TNH4PHY"                                 unit=""  /> 
+       <field id="TPHYDOM"     long_name="TPHYDOM"                                 unit=""  /> 
+       <field id="TPHYNH4"     long_name="TPHYNH4"                                 unit=""  /> 
+       <field id="TPHYZOO"     long_name="TPHYZOO"                                 unit=""  /> 
+       <field id="TPHYDET"     long_name="TPHYDET"                                 unit=""  /> 
+       <field id="TDETZOO"     long_name="TDETZOO"                                 unit=""  /> 
+       <field id="TZOODET"     long_name="TZOODET"                                 unit=""  /> 
+       <field id="TZOOBOD"     long_name="TZOOBOD"                                 unit=""  /> 
+       <field id="TZOONH4"     long_name="TZOONH4"                                 unit=""  /> 
+       <field id="TZOODOM"     long_name="TZOODOM"                                 unit=""  /> 
+       <field id="TNH4NO3"     long_name="TNH4NO3"                                 unit=""  /> 
+       <field id="TDOMNH4"     long_name="TDOMNH4"                                 unit=""  /> 
+       <field id="TDETNH4"     long_name="TDETNH4"                                 unit=""  /> 
+       <field id="TPHYTOT"     long_name="TPHYTOT"                                 unit=""  /> 
+       <field id="TZOOTOT"     long_name="TZOOTOT"                                 unit=""  /> 
+       <field id="SEDPOC"      long_name="SEDPOC"                                  unit=""  /> 
+       <field id="TDETSED"     long_name="TDETSED"                                 unit=""  /> 
+
+       <!-- CFC11 : variables available with key_cfc -->
+       <field id="qtrCFC11"    long_name="Air-sea flux of CFC-11"                  unit="mol/m2/s"   />
+       <field id="qintCFC11"   long_name="Cumulative air-sea flux of CFC-11"       unit="mol/m2"     />
+
+       <!-- Bomb C14 : variables available with key_c14b -->
+       <field id="qtrC14b"     long_name="Air-sea flux of Bomb C14"                unit="mol/m2/s"   />
+       <field id="qintC14b"    long_name="Cumulative air-sea flux of Bomb C14"     unit="mol/m2"     />
+       <field id="fdecay"      long_name="Radiactive decay of Bomb C14"            unit="mol/m3"  grid_ref="grid_T_3D"  />
+
+       <!-- IDTRA : variables available with key_idtra -->
+       <field id="qtrIDTRA"    long_name="Air-sea flux of Ideal Tracer"             unit="mol/m2/s"   />
+       <field id="qintIDTRA"   long_name="Cumulative air-sea flux of Ideal Tracer"  unit="mol/m2"     />
+       <field id="invIDTRA"    long_name="Vertical inventory"                       unit="mol/m2"     />
+
+       <!-- MEDUSA additional diagnostics on T grid  -->
+       <field id= "INVTN"      long_name="Column N inventory"                        unit="mmolN/m2"    />
+       <field id= "INVTSI"     long_name="Column Si inventory"                       unit="mmolSi/m2"   />
+       <field id= "INVTFE"     long_name="Column Fe inventory"                       unit="mmolFe/m2"   />
+       <field id= "PRN"        long_name="Non-diatom primary production"             unit="mmolN/m2/d"  />
+       <field id= "MPN"        long_name="Non-diatom non-grazing losses"             unit="mmolN/m2/d"  />
+       <field id= "PRD"        long_name="Diatom primary production"                 unit="mmolN/m2/d"  />
+       <field id= "MPD"        long_name="Diatom non-grazing losses"                 unit="mmolN/m2/d"  />
+       <field id= "DSED"       long_name="Gravitational sinking of Detritus"         unit="mmolN/m2/d"  />
+       <field id= "OPAL"       long_name="Diatom biogenic opal production"           unit="mmolSi/m2/d" />
+       <field id= "OPALDISS"   long_name="Diatom biogenic opal dissolution"          unit="mmolSi/m2/d" />
+       <field id= "GMIPn"      long_name="Microzoo grazing on non-diatoms"           unit="mmolN/m2/d"  />
+       <field id= "GMID"       long_name="Microzoo grazing on detritus"              unit="mmolN/m2/d"  />
+       <field id= "MZMI"       long_name="Microzoo non-grazing losses"               unit="mmolN/m2/d"  />
+       <field id= "GMEPN"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEPD"      long_name="Mesozoo grazing on non-diatoms"            unit="mmolN/m2/d"  />
+       <field id= "GMEZMI"     long_name="Mesozoo grazing on microzoo"               unit="mmolN/m2/d"  />
+       <field id= "GMED"       long_name="Mesozoo grazing on detritus"               unit="mmolN/m2/d"  />
+       <field id= "MZME"       long_name="Mesozoo non-grazing losses"                unit="mmolN/m2/d"  />
+       <field id= "DEXP"       long_name="Detritus export"                           unit="mmolN/m2/d"  />
+       <field id= "DETN"       long_name="Slow detritus creation"                    unit="mmolN/m2/d"  />
+       <field id= "MDET"       long_name="Detritus non-grazing losses"               unit="MmolN/m2/d"  />
+       <field id= "AEOLIAN"    long_name="Aeolian deposition of iron"                unit="mmolFe/m2/d" />
+       <field id= "BENTHIC"    long_name="Benthic supply of iron"                    unit="mmolFe/m2/d" />
+       <field id= "SCAVENGE"   long_name="Scavenged iron"                            unit="mmolFe/m2/d" />
+       <field id= "PN_JLIM"    long_name="Non-diatom light limitation"               unit="-"           />
+       <field id= "PN_NLIM"    long_name="Non-diatom N limitation"                   unit="-"           />
+       <field id= "PN_FELIM"   long_name="Non-diatom Fe limitation"                  unit="-"           />
+       <field id= "PD_JLIM"    long_name="Diatom light limitation"                   unit="-"           />
+       <field id= "PD_NLIM"    long_name="Diatom N limitation"                       unit="-"           />
+       <field id= "PD_FELIM"   long_name="Diatom Fe limitation"                      unit="-"           />
+       <field id= "PD_SILIM"   long_name="Diatom Si limitation"                      unit="-"           />
+       <field id= "PDSILIM2"   long_name="Diatom Si uptake limitation"               unit="-"           />
+       <field id= "SDT__100"   long_name="Slow detrital flux at  100 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__200"   long_name="Slow detrital flux at  200 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT__500"   long_name="Slow detrital flux at  500 m"              unit="mmolN/m2/d"  />
+       <field id= "SDT_1000"   long_name="Slow detrital flux at 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "TOTREG_N"   long_name="Full column regenerated N"                 unit="mmolN/m2/d"  />
+       <field id= "TOTRG_SI"   long_name="Full column regenerated Si"                unit="mmolSi/m2/d" />
+       <field id= "REG__100"   long_name="Regenerated N to  100 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__200"   long_name="Regenerated N to  200 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG__500"   long_name="Regenerated N to  500 m"                   unit="mmolN/m2/d"  />
+       <field id= "REG_1000"   long_name="Regenerated N to 1000 m"                   unit="mmolN/m2/d"  />
+       <field id= "FASTN"      long_name="Fast-sinking flux N"                       unit="mmolN/m2/d"  />
+       <field id= "FASTSI"     long_name="Fast-sinking flux Si"                      unit="mmolSi/m2/d" />
+       <field id= "FASTFE"     long_name="Fast-sinking flux Fe"                      unit="mmolFe/m2/d" />
+       <field id= "FASTC"      long_name="Fast-sinking flux C"                       unit="mmolC/m2/d"  />
+       <field id= "FASTCA"     long_name="Fast-sinking flux CaCO3"                   unit="mmolC/m2/d"  />
+       <field id= "FDT__100"   long_name="Fast detrital N flux at  100 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__200"   long_name="Fast detrital N flux at  200 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT__500"   long_name="Fast detrital N flux at  500 m"            unit="mmolN/m2/d"  />
+       <field id= "FDT_1000"   long_name="Fast detrital N flux at 1000 m"            unit="mmolN/m2/d"  />
+       <field id= "RG__100F"   long_name="Regenerated fast N to  100 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__200F"   long_name="Regenerated fast N to  200 m"              unit="mmolN/m2/d"  />
+       <field id= "RG__500F"   long_name="Regenerated fast N to  500 m"              unit="mmolN/m2/d"  />
+       <field id= "RG_1000F"   long_name="Regenerated fast N to 1000 m"              unit="mmolN/m2/d"  />
+       <field id= "FDS__100"   long_name="Fast detrital Si flux at  100 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__200"   long_name="Fast detrital Si flux at  200 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS__500"   long_name="Fast detrital Si flux at  500 m"           unit="mmolSi/m2/d" />
+       <field id= "FDS_1000"   long_name="Fast detrital Si flux at 1000 m"           unit="mmolSi/m2/d" />
+       <field id= "RGS_100F"   long_name="Regenerated fast Si to  100 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_200F"   long_name="Regenerated fast Si to  200 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS_500F"   long_name="Regenerated fast Si to  500 m"             unit="mmolSi/m2/d" />
+       <field id= "RGS1000F"   long_name="Regenerated fast Si to 1000 m"             unit="mmolSi/m2/d" />
+       <field id= "REMINN"     long_name="Fast-sinking remin flux N"                 unit="mmolN/m2/d"  />
+       <field id= "REMINSI"    long_name="Fast-sinking remin flux Si"                unit="mmolSi/m2/d" />
+       <field id= "REMINFE"    long_name="Fast-sinking remin flux Fe"                unit="mmolFe/m2/d" />
+       <field id= "REMINC"     long_name="Fast-sinking remin flux C"                 unit="mmolC/m2/d"  />
+       <field id= "REMINCA"    long_name="Fast-sinking remin flux CaCO3"             unit="mmolC/m2/d"  />
+       <field id= "SEAFLRN"    long_name="Seafloor flux of N"                        unit="mmolN/m2/d"  />
+       <field id= "SEAFLRSI"   long_name="Seafloor flux of Si"                       unit="mmolSi/m2/d" />
+       <field id= "SEAFLRFE"   long_name="Seafloor flux of Fe"                       unit="mmolFe/m2/d" />
+       <field id= "SEAFLRC"    long_name="Seafloor flux of C"                        unit="mmolC/m2/d"  />
+       <field id= "SEAFLRCA"   long_name="Seafloor flux of CaCO3"                    unit="mmolC/m2/d"  />
+       <field id= "MED_QSR"    long_name="Sea surface radiation"                     unit="W/m2"        />
+       <field id= "MED_XPAR"   long_name="Top level radiation"                       unit="W/m2"        />
+       <field id= "INTFLX_N"   long_name="Integrated N  cycle fluxes"                unit="mmolN/m2/d"  />
+       <field id= "INTFLX_SI"  long_name="Integrated Si cycle fluxes"                unit="mmolSi/m2/d" />
+       <field id= "INTFLX_FE"  long_name="Integrated Fe cycle fluxes"                unit="mmolFe/m2/d" />
+       <field id= "INT_PN"     long_name="Vertically integrated Pn"                  unit="mmolN/m2"    />
+       <field id= "INT_PD"     long_name="Vertically integrated Pd"                  unit="mmolN/m2"    />
+       <field id= "ML_PRN"     long_name="Non-diatom mixed layer PP"                 unit="mmolN/m2/d"  />
+       <field id= "ML_PRD"     long_name="Diatom mixed layer PP"                     unit="mmolN/m2/d"  />
+       <field id= "OCAL_CCD"   long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "OCAL_LVL"   long_name="Calcite CCD level"                         unit="-"           />
+       <field id= "FE_0000"    long_name="Free iron at    0m"                        unit="-"           />
+       <field id= "FE_0100"    long_name="Free iron at  100m"                        unit="-"           />
+       <field id= "FE_0200"    long_name="Free iron at  200m"                        unit="-"           />
+       <field id= "FE_0500"    long_name="Free iron at  500m"                        unit="-"           />
+       <field id= "FE_1000"    long_name="Free iron at 1000m"                        unit="-"           />
+       <field id= "MED_XZE"    long_name="Euphotic depth"                            unit="m"           />
+       <field id= "WIND"       long_name="Surface scalar wind"                       unit="m/s"         />
+       <field id= "ATM_PCO2"   long_name="Atmospheric pCO2"                          unit="ppmv"        />
+       <field id= "OCN_PH"     long_name="Surface ocean pH"                          unit="-"           />
+       <field id= "OCN_PCO2"   long_name="Surface ocean pCO2"                        unit="ppmv"        />
+       <field id= "OCNH2CO3"   long_name="Surface ocean H2CO3 conc"                  unit="mmolC/m3"    />
+       <field id= "OCN_HCO3"   long_name="Surface ocean HCO3 conc"                   unit="mmolC/m3"    />
+       <field id= "OCN_CO3"    long_name="Surface ocean CO3 conc"                    unit="mmolC/m3"    />
+       <field id= "CO2FLUX"    long_name="Air-sea CO2 flux"                          unit="mmolC/m2/d"  />
+       <field id= "OM_CAL"     long_name="Omega calcite"                             unit="-"           />
+       <field id= "OM_ARG"     long_name="Omega aragonite"                           unit="-"           />
+       <field id= "TCO2"       long_name="Total CO2"                                 unit="umol/kg"     />
+       <field id= "TALK"       long_name="Total alkalinity"                          unit="ueq/kg"      />
+       <field id= "KW660"      long_name="Piston velocity"                           unit="m/s"         />
+       <field id= "ATM_PP0"    long_name="Atmospheric pressure"                      unit="bar"         />
+       <field id= "O2FLUX"     long_name="Air-sea O2 flux"                           unit="mmolO2/m2/d" />
+       <field id= "O2SAT"      long_name="Surface ocean O2 saturation"               unit="mmolO2/m3"   />
+       <field id= "CAL_CCD"    long_name="Calcite CCD depth"                         unit="m"           />
+       <field id= "ARG_CCD"    long_name="Aragonite CCD depth"                       unit="m"           />
+       <field id= "SFR_OCAL"   long_name="Seafloor omega calcite"                    unit="-"           />
+       <field id= "SFR_OARG"   long_name="Seafloor omega aragonite"                  unit="-"           />
+       <field id= "N_PROD"     long_name="Nitrogen production"                       unit="mmolN/m2/d"  />
+       <field id= "N_CONS"     long_name="Nitrogen consumption"                      unit="mmolN/m2/d"  />
+       <field id= "C_PROD"     long_name="Carbon production"                         unit="mmolC/m2/d"  />
+       <field id= "C_CONS"     long_name="Carbon consumption"                        unit="mmolC/m2/d"  />
+       <field id= "O2_PROD"    long_name="Oxygen production"                         unit="mmolO2/m2/d" />
+       <field id= "O2_CONS"    long_name="Oxygen consumption"                        unit="mmolO2/m2/d" />
+       <field id= "O2_ANOX"    long_name="Unrealised oxygen consumption"             unit="mmolO2/m2/d" />
+       <field id= "RR_0100"    long_name="Rain ratio at  100m"                       unit="molC/molC"   />
+       <field id= "RR_0500"    long_name="Rain ratio at  500m"                       unit="molC/molC"   />
+       <field id= "RR_1000"    long_name="Rain ratio at 1000m"                       unit="molC/molC"   />
+       <field id= "IBEN_N"     long_name="Benthic input nitrogen"                    unit="mmolN/m2/d"  />
+       <field id= "IBEN_FE"    long_name="Benthic input iron"                        unit="mmolFe/m2/d" />
+       <field id= "IBEN_C"     long_name="Benthic input carbon"                      unit="mmolC/m2/d"  />
+       <field id= "IBEN_SI"    long_name="Benthic input silicon"                     unit="mmolSi/m2/d" />
+       <field id= "IBEN_CA"    long_name="Benthic input CaCO3"                       unit="mmolC/m2/d"  />
+       <field id= "OBEN_N"     long_name="Benthic output nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "OBEN_FE"    long_name="Benthic output iron"                       unit="mmolFe/m2/d" />
+       <field id= "OBEN_C"     long_name="Benthic output carbon"                     unit="mmolC/m2/d"  />
+       <field id= "OBEN_SI"    long_name="Benthic output silicon"                    unit="mmolSi/m2/d" />
+       <field id= "OBEN_CA"    long_name="Benthic output CaCO3"                      unit="mmolC/m2/d"  />
+       <field id= "BEN_N"      long_name="Benthic nitrogen"                          unit="mmolN/m2"    />
+       <field id= "BEN_FE"     long_name="Benthic iron"                              unit="mmolFe/m2"   />
+       <field id= "BEN_C"      long_name="Benthic carbon"                            unit="mmolC/m2"    />
+       <field id= "BEN_SI"     long_name="Benthic silicon"                           unit="mmolSi/m2"   />
+       <field id= "BEN_CA"     long_name="Benthic CaCO3"                             unit="mmolC/m2"    />
+       <field id= "RUNOFF"     long_name="River runoff"                              unit="m/d"         />
+       <field id= "RIV_N"      long_name="Riverine input nitrogen"                   unit="mmolN/m2/d"  />
+       <field id= "RIV_SI"     long_name="Riverine input silicon"                    unit="mmolSi/m2/d" />
+       <field id= "RIV_C"      long_name="Riverine input carbon"                     unit="mmolSi/m2/d" />
+       <field id= "RIV_ALK"    long_name="Riverine input alkalinity"                 unit="meq/m2/d"    />
+       <field id= "DETC"       long_name="Slow detritus C creation"                  unit="mmolC/m2/d"  />
+       <field id= "SDC__100"   long_name="Slow detrital C flux at  100 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__200"   long_name="Slow detrital C flux at  200 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC__500"   long_name="Slow detrital C flux at  500 m"            unit="mmolC/m2/d"  />
+       <field id= "SDC_1000"   long_name="Slow detrital C flux at 1000 m"            unit="mmolC/m2/d"  />
+       <field id= "INVTC"      long_name="Column C inventory"                        unit="mmolC/m2"    />
+       <field id= "INVTALK"    long_name="Column alkalinity inventory"               unit="meq/m2"      />
+       <field id= "INVTO2"     long_name="Column O2 inventory"                       unit="mmolO2/m2"   />
+       <field id= "LYSO_CA"    long_name="Incorrect benthic output CaCO3"            unit="mmolC/m2/d"  />
+       <field id= "COM_RESP"   long_name="Community respiration"                     unit="mmolC/m2/d"  />
+       <field id= "PN_LLOSS"   long_name="Non-diatom linear losses"                  unit="mmolN/m2/d"  />
+       <field id= "PD_LLOSS"   long_name="Diatom linear losses"                      unit="mmolN/m2/d"  />
+       <field id= "ZI_LLOSS"   long_name="Microzooplankton linear losses"            unit="mmolN/m2/d"  />
+       <field id= "ZE_LLOSS"   long_name="Mesozooplankton linear losses"             unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_N"   long_name="Microzoo messy feeding loss to N"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_D"   long_name="Microzoo messy feeding loss to D"          unit="mmolN/m2/d"  />
+       <field id= "ZI_MES_C"   long_name="Microzoo messy feeding loss to C"          unit="mmolC/m2/d"  />
+       <field id= "ZI_MESDC"   long_name="Microzoo messy feeding loss to Dc"         unit="mmolC/m2/d"  />
+       <field id= "ZI_EXCR"    long_name="Microzoo excretion"                        unit="mmolN/m2/d"  />
+       <field id= "ZI_RESP"    long_name="Microzoo respiration"                      unit="mmolC/m2/d"  />
+       <field id= "ZI_GROW"    long_name="Microzoo growth"                           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_N"   long_name="Mesozoo messy feeding loss to N"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_D"   long_name="Mesozoo messy feeding loss to D"           unit="mmolN/m2/d"  />
+       <field id= "ZE_MES_C"   long_name="Mesozoo messy feeding loss to C"           unit="mmolC/m2/d"  />
+       <field id= "ZE_MESDC"   long_name="Mesozoo messy feeding loss to Dc"          unit="mmolC/m2/d"  />
+       <field id= "ZE_EXCR"    long_name="Mesozoo excretion"                         unit="mmolN/m2/d"  />
+       <field id= "ZE_RESP"    long_name="Mesozoo respiration"                       unit="mmolC/m2/d"  />
+       <field id= "ZE_GROW"    long_name="Mesozoo growth"                            unit="mmolN/m2/d"  />
+       <field id= "MDETC"      long_name="Detritus non-grazing losses, carbon"       unit="mmolC/m2/d"  />
+       <field id= "GMIDC"      long_name="Microzoo grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "GMEDC"      long_name="Mesozoo  grazing on detritus, carbon"      unit="mmolC/m2/d"  />
+       <field id= "BASIN_01"   long_name="Non-diatom primary production, 150m"       unit="mmolN/m2/d"  />
+       <field id= "BASIN_02"   long_name="Non-diatom linear loss, 150m"              unit="mmolN/m2/d"  />
+       <field id= "BASIN_03"   long_name="Non-diatom non-linear loss, 150m"          unit="mmolN/m2/d"  />
+       <field id= "BASIN_04"   long_name="Non-diatom loss to microzoo, 150m"         unit="mmolN/m2/d"  />
+       <field id= "BASIN_05"   long_name="Non-diatom loss to mesozoo, 150m"          unit="mmolN/m2/d"  />
+       <field id= "BASIN_06"   long_name="Diatom primary production, 150m"           unit="mmolN/m2/d"  />
+       <field id= "BASIN_07"   long_name="Diatom linear loss, 150m"                  unit="mmolN/m2/d"  />
+       <field id= "BASIN_08"   long_name="Diatom non-linear loss, 150m"              unit="mmolN/m2/d"  />
+       <field id= "BASIN_09"   long_name="Diatom loss to mesozoo, 150m"              unit="mmolN/m2/d"  />
+       <field id= "BASIN_10"   long_name="Microzoo grazing on slow detritus N, 150m" unit="mmolN/m2/d"  />
+       <field id= "BASIN_11"   long_name="Microzoo grazing on slow detritus C, 150m" unit="mmolC/m2/d"  />
+       <field id= "BASIN_12"   long_name="Microzoo messy feeding loss to N, 150m"    unit="mmolN/m2/d"  />
+       <field id= "BASIN_13"   long_name="Microzoo messy feeding loss to D, 150m"    unit="mmolC/m2/d"  />
+       <field id= "BASIN_14"   long_name="Microzoo messy feeding loss to C, 150m"    unit="mmolN/m2/d"  />
+       <field id= "BASIN_15"   long_name="Microzoo messy feeding loss to Dc, 150m"   unit="mmolC/m2/d"  />
+       <field id= "BASIN_16"   long_name="Microzoo excretion, 150m"                  unit="mmolN/m2/d"  />
+       <field id= "BASIN_17"   long_name="Microzoo respiration, 150m"                unit="mmolC/m2/d"  />
+       <field id= "BASIN_18"   long_name="Microzoo growth, 150m"                     unit="mmolN/m2/d"  />
+       <field id= "BASIN_19"   long_name="Microzoo linear loss, 150m"                unit="mmolN/m2/d"  />
+       <field id= "BASIN_20"   long_name="Microzoo non-linear loss, 150m"            unit="mmolN/m2/d"  />
+       <field id= "BASIN_21"   long_name="Microzoo grazing loss to mesozoo, 150m"    unit="mmolN/m2/d"  />
+       <field id= "BASIN_22"   long_name="Mesozoo grazing on slow detritus N, 150m"  unit="mmolN/m2/d"  />
+       <field id= "BASIN_23"   long_name="Mesozoo grazing on slow detritus C, 150m"  unit="mmolC/m2/d"  />
+       <field id= "BASIN_24"   long_name="Mesozoo messy feeding loss to N, 150m"     unit="mmolN/m2/d"  />
+       <field id= "BASIN_25"   long_name="Mesozoo messy feeding loss to D, 150m"     unit="mmolC/m2/d"  />
+       <field id= "BASIN_26"   long_name="Mesozoo messy feeding loss to C, 150m"     unit="mmolN/m2/d"  />
+       <field id= "BASIN_27"   long_name="Mesozoo messy feeding loss to Dc, 150m"    unit="mmolC/m2/d"  />
+       <field id= "BASIN_28"   long_name="Mesozoo excretion, 150m"                   unit="mmolN/m2/d"  />
+       <field id= "BASIN_29"   long_name="Mesozoo respiration, 150m"                 unit="mmolC/m2/d"  />
+       <field id= "BASIN_30"   long_name="Mesozoo growth, 150m"                      unit="mmolN/m2/d"  />
+       <field id= "BASIN_31"   long_name="Mesozoo linear loss, 150m"                 unit="mmolN/m2/d"  />
+       <field id= "BASIN_32"   long_name="Mesozoo non-linear loss, 150m"             unit="mmolN/m2/d"  />
+       <field id= "BASIN_33"   long_name="Slow detritus production, N, 150m"         unit="mmolN/m2/d"  />
+       <field id= "BASIN_34"   long_name="Slow detritus remineralisation, N, 150m"   unit="mmolN/m2/d"  />
+       <field id= "BASIN_35"   long_name="Slow detritus production, C, 150m"         unit="mmolC/m2/d"  />
+       <field id= "BASIN_36"   long_name="Slow detritus remineralisation, C, 150m"   unit="mmolC/m2/d"  />
+       <field id= "BASIN_37"   long_name="Fast detritus production, N, 150m"         unit="mmolN/m2/d"  />
+       <field id= "BASIN_38"   long_name="Fast detritus remineralisation, N, 150m"   unit="mmolN/m2/d"  />
+       <field id= "BASIN_39"   long_name="Fast detritus production, C, 150m"         unit="mmolC/m2/d"  />
+       <field id= "BASIN_40"   long_name="Fast detritus remineralisation, C, 150m"   unit="mmolC/m2/d"  />
+       <field id= "BASIN_41"   long_name="Fast detritus remineralisation, C, 150m"   unit="mmolC/m2/d"  />
+       <field id= "BASIN_42"   long_name="Slow detritus sinking flux, N, 150m"       unit="mmolN/m2/d"  />
+       <field id= "BASIN_43"   long_name="Slow detritus sinking flux, C, 150m"       unit="mmolC/m2/d"  />
+       <field id= "BASIN_44"   long_name="Fast detritus sinking flux, N, 150m"       unit="mmolN/m2/d"  />
+       <field id= "BASIN_45"   long_name="Fast detritus sinking flux, C, 150m"       unit="mmolC/m2/d"  />
+       <field id= "INT_ZMI"    long_name="Vertically integrated Zmi"                 unit="mmolN/m2"    />
+       <field id= "INT_ZME"    long_name="Vertically integrated Zme"                 unit="mmolN/m2"    />
+       <field id= "INT_DET"    long_name="Vertically integrated Det"                 unit="mmolN/m2"    />
+       <field id= "INT_DTC"    long_name="Vertically integrated Dtc"                 unit="mmolC/m2"    />
+       <field id= "DMS_SURF"   long_name="DMS Surface Concentration"                 unit="nmol/L"      />
+       <field id= "DMS_ANDR"   long_name="DMS Surface Concentration, Anderson"       unit="nmol/L"      />
+       <field id= "DMS_SIMO"   long_name="DMS Surface Concentration, SimoDach"       unit="nmol/L"      />
+       <field id= "DMS_ARAN"   long_name="DMS Surface Concentration, AranamiT"       unit="nmol/L"      />
+       <field id= "DMS_HALL"   long_name="DMS Surface Concentration, Halloran"       unit="nmol/L"      />
+
+       <field id= "TPP3"       long_name="Total primary production 3D"               unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "DETFLUX3"   long_name="Total detrital flux 3D"                    unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "REMIN3N"    long_name="Total remin flux N 3D"                     unit="mmolN/m3/d"    grid_ref="grid_T_3D"  />
+       <field id= "PH3"        long_name="Ocean pH 3D"                               unit="-"             grid_ref="grid_T_3D"  />
+       <field id= "OM_CAL3"    long_name="Omega calcite 3D"                          unit="-"             grid_ref="grid_T_3D"  />
+
+     </field_group>
+
+     <field_group id="PISCES_scalar"  domain_ref="1point" >
+       <field id="pno3tot"         long_name="global mean nitrate concentration"                  unit="mol/m3"   />
+       <field id="ppo4tot"         long_name="global mean phosphorus concentration"               unit="mol/m3"   />
+       <field id="psiltot"         long_name="global mean silicate concentration"                 unit="mol/m3"   />
+       <field id="palktot"         long_name="global mean alkalinity concentration"               unit="mol/m3"   />
+       <field id="pfertot"         long_name="global mean iron concentration"                     unit="mol/m3"   />
+       <field id="tcflx"           long_name="total Flux of Carbon out of the ocean"              unit="mol/s"   />
+       <field id="tcflxcum"        long_name="cumulative total Flux of Carbon out of the ocean"   unit="mol/s"   />
+       <field id="tcexp"           long_name="total Carbon export at 100m"                        unit="mol/s"   />
+       <field id="tintpp"          long_name="global total integrated primary production"         unit="mol/s"   />
+       <field id="tnfix"           long_name="global total nitrogen fixation"                     unit="mol/s"   />
+       <field id="tdenit"          long_name="Total denitrification"                              unit="mol/s"   />
+     </field_group>
+
+    <!-- 
+============================================================================================================
+                                        Definitions for iodef_demo.xml
+============================================================================================================
+    -->
+
+    <field_group id="groupMEDUSA" >
+      <field field_ref="CHN"   name="CHN"   />
+      <field field_ref="CHD"   name="CHD"   />
+      <field field_ref="PHN"   name="PHN"   />
+      <field field_ref="PHD"   name="PHD"   />
+      <field field_ref="ZMI"   name="ZMI"   />
+      <field field_ref="ZME"   name="ZME"   />
+      <field field_ref="DIN"   name="DIN"   />
+      <field field_ref="SIL"   name="SIL"   />
+      <field field_ref="FER"   name="FER"   />
+      <field field_ref="DET"   name="DET"   />
+      <field field_ref="PDS"   name="PDS"   />
+      <field field_ref="DTC"   name="DTC"   />
+      <field field_ref="DiC"   name="DIC"   />
+      <field field_ref="ALK"   name="ALK"   />
+      <field field_ref="OXY"   name="OXY"   />
+      </field_group>
+
+    <field_group id="groupIDTRA" >
+      <field field_ref="IDTRA" name="IDTRA" />
+    </field_group>
+
+    <field_group id="groupIDTRA_dia" >
+      <field field_ref="qtrIDTRA"    name="qtrIDTRA"  />
+      <field field_ref="qintIDTRA"   name="qintIDTRA" />
+      <field field_ref="invIDTRA"    name="invIDTRA"  />
+    </field_group>
+
+    <field_group id="groupCFC" >
+      <field field_ref="CFC11" name="CFC11" />
+    </field_group>
+
+    <field_group id="groupCFC_dia" >
+      <field field_ref="qtrCFC11"    name="qtrCFC11"   />
+      <field field_ref="qintCFC11"   name="qintCFC11"  />
+    </field_group>
+
+    <field_group id="groupAGE" >
+      <field field_ref="Age" name="Age" />
+    </field_group>
+
+    <field_group id="groupMEDUSA_dia" >
+      <field field_ref= "INVTN"      name="INVTN"      />
+      <field field_ref= "INVTSI"     name="INVTSI"     />
+      <field field_ref= "INVTFE"     name="INVTFE"     />
+      <field field_ref= "PRN"        name="PRN"        />
+      <field field_ref= "MPN"        name="MPN"        />
+      <field field_ref= "PRD"        name="PRD"        />
+      <field field_ref= "MPD"        name="MPD"        />
+      <field field_ref= "OPAL"       name="OPAL"       />
+      <field field_ref= "OPALDISS"   name="OPALDISS"   />
+      <field field_ref= "GMIPn"      name="GMIPn"      />
+      <field field_ref= "GMID"       name="GMID"       />
+      <field field_ref= "MZMI"       name="MZMI"       />
+      <field field_ref= "GMEPN"      name="GMEPN"      />
+      <field field_ref= "GMEPD"      name="GMEPD"      />
+      <field field_ref= "GMEZMI"     name="GMEZMI"     />
+      <field field_ref= "GMED"       name="GMED"       />
+      <field field_ref= "MZME"       name="MZME"       />
+      <field field_ref= "DETN"       name="DETN"       />
+      <field field_ref= "MDET"       name="MDET"       />
+      <field field_ref= "AEOLIAN"    name="AEOLIAN"    />
+      <field field_ref= "BENTHIC"    name="BENTHIC"    />
+      <field field_ref= "SCAVENGE"   name="SCAVENGE"   />
+      <field field_ref= "PN_JLIM"    name="PN_JLIM"    />
+      <field field_ref= "PN_NLIM"    name="PN_NLIM"    />
+      <field field_ref= "PN_FELIM"   name="PN_FELIM"   />
+      <field field_ref= "PD_JLIM"    name="PD_JLIM"    />
+      <field field_ref= "PD_NLIM"    name="PD_NLIM"    />
+      <field field_ref= "PD_FELIM"   name="PD_FELIM"   />
+      <field field_ref= "PD_SILIM"   name="PD_SILIM"   />
+      <field field_ref= "PDSILIM2"   name="PDSILIM2"   />
+      <field field_ref= "SDT__100"   name="SDT__100"   />
+      <field field_ref= "SDT__200"   name="SDT__200"   />
+      <field field_ref= "SDT__500"   name="SDT__500"   />
+      <field field_ref= "SDT_1000"   name="SDT_1000"   />
+      <field field_ref= "TOTREG_N"   name="TOTREG_N"   />
+      <field field_ref= "TOTRG_SI"   name="TOTRG_SI"   />
+      <field field_ref= "REG__100"   name="REG__100"   />
+      <field field_ref= "REG__200"   name="REG__200"   />
+      <field field_ref= "REG__500"   name="REG__500"   />
+      <field field_ref= "REG_1000"   name="REG_1000"   />
+      <field field_ref= "FASTN"      name="FASTN"      />
+      <field field_ref= "FASTSI"     name="FASTSI"     />
+      <field field_ref= "FASTFE"     name="FASTFE"     />
+      <field field_ref= "FASTC"      name="FASTC"      />
+      <field field_ref= "FASTCA"     name="FASTCA"     />
+      <field field_ref= "FDT__100"   name="FDT__100"   />
+      <field field_ref= "FDT__200"   name="FDT__200"   />
+      <field field_ref= "FDT__500"   name="FDT__500"   />
+      <field field_ref= "FDT_1000"   name="FDT_1000"   /> 
+      <field field_ref= "RG__100F"   name="RG__100F"   />
+      <field field_ref= "RG__200F"   name="RG__200F"   />
+      <field field_ref= "RG__500F"   name="RG__500F"   />
+      <field field_ref= "RG_1000F"   name="RG_1000F"   />
+      <field field_ref= "FDS__100"   name="FDS__100"   />
+      <field field_ref= "FDS__200"   name="FDS__200"   />
+      <field field_ref= "FDS__500"   name="FDS__500"   />
+      <field field_ref= "FDS_1000"   name="FDS_1000"   />
+      <field field_ref= "RGS_100F"   name="RGS_100F"   />
+      <field field_ref= "RGS_200F"   name="RGS_200F"   />
+      <field field_ref= "RGS_500F"   name="RGS_500F"   />
+      <field field_ref= "RGS1000F"   name="RGS1000F"   />
+      <field field_ref= "REMINN"     name="REMINN"     />
+      <field field_ref= "REMINSI"    name="REMINSI"    />
+      <field field_ref= "REMINFE"    name="REMINFE"    />
+      <field field_ref= "SEAFLRN"    name="SEAFLRN"    /> 
+      <field field_ref= "SEAFLRSI"   name="SEAFLRSI"   />
+      <field field_ref= "SEAFLRFE"   name="SEAFLRFE"   />
+      <field field_ref= "SEAFLRC"    name="SEAFLRC"    />
+      <field field_ref= "SEAFLRCA"   name="SEAFLRCA"   />
+      <field field_ref= "MED_QSR"    name="MED_QSR"    />
+      <field field_ref= "MED_XPAR"   name="MED_XPAR"   />
+      <field field_ref= "INTFLX_N"   name="INTFLX_N"   />
+      <field field_ref= "INTFLX_SI"  name="INTFLX_SI"  />
+      <field field_ref= "INTFLX_FE"  name="INTFLX_FE"  />
+      <field field_ref= "INT_PN"     name="INT_PN"     />
+      <field field_ref= "INT_PD"     name="INT_PD"     />
+      <field field_ref= "ML_PRN"     name="ML_PRN"     />
+      <field field_ref= "ML_PRD"     name="ML_PRD"     />
+      <field field_ref= "OCAL_CCD"   name="OCAL_CCD"   />
+      <field field_ref= "OCAL_LVL"   name="OCAL_LVL"   />
+      <field field_ref= "FE_0000"    name="FE_0000"    />
+      <field field_ref= "FE_0100"    name="FE_0100"    />
+      <field field_ref= "FE_0200"    name="FE_0200"    /> 
+      <field field_ref= "FE_0500"    name="FE_0500"    />
+      <field field_ref= "FE_1000"    name="FE_1000"    />
+      <field field_ref= "MED_XZE"    name="MED_XZE"    />
+      <field field_ref= "WIND"       name="WIND"       />
+      <field field_ref= "ATM_PCO2"   name="ATM_PCO2"   />
+      <field field_ref= "OCN_PH"     name="OCN_PH"     />
+      <field field_ref= "OCN_PCO2"   name="OCN_PCO2"   />
+      <field field_ref= "OCNH2CO3"   name="OCNH2CO3"   />
+      <field field_ref= "OCN_HCO3"   name="OCN_HCO3"   />
+      <field field_ref= "OCN_CO3"    name="OCN_CO3"    />
+      <field field_ref= "CO2FLUX"    name="CO2FLUX"    />
+      <field field_ref= "OM_CAL"     name="OM_CAL"     />
+      <field field_ref= "OM_ARG"     name="OM_ARG"     />
+      <field field_ref= "TCO2"       name="TCO2"       />
+      <field field_ref= "TALK"       name="TALK"       />
+      <field field_ref= "KW660"      name="KW660"      />
+      <field field_ref= "ATM_PP0"    name="ATM_PP0"    />
+      <field field_ref= "O2FLUX"     name="O2FLUX"     />
+      <field field_ref= "O2SAT"      name="O2SAT"      />
+      <field field_ref= "CAL_CCD"    name="CAL_CCD"    />
+      <field field_ref= "ARG_CCD"    name="ARG_CCD"    />
+      <field field_ref= "SFR_OCAL"   name="SFR_OCAL"   />
+      <field field_ref= "SFR_OARG"   name="SFR_OARG"   />
+      <field field_ref= "N_PROD"     name="N_PROD"     />
+      <field field_ref= "N_CONS"     name="N_CONS"     />
+      <field field_ref= "C_PROD"     name="C_PROD"     />
+      <field field_ref= "C_CONS"     name="C_CONS"     />
+      <field field_ref= "O2_PROD"    name="O2_PROD"    />
+      <field field_ref= "O2_CONS"    name="O2_CONS"    />
+      <field field_ref= "O2_ANOX"    name="O2_ANOX"    />
+      <field field_ref= "RR_0100"    name="RR_0100"    />
+      <field field_ref= "RR_0500"    name="RR_0500"    />
+      <field field_ref= "RR_1000"    name="RR_1000"    />
+      <field field_ref= "IBEN_N"     name="IBEN_N"     />
+      <field field_ref= "IBEN_FE"    name="IBEN_FE"    />
+      <field field_ref= "IBEN_C"     name="IBEN_C"     />
+      <field field_ref= "IBEN_SI"    name="IBEN_SI"    />
+      <field field_ref= "IBEN_CA"    name="IBEN_CA"    />
+      <field field_ref= "OBEN_N"     name="OBEN_N"     />
+      <field field_ref= "OBEN_FE"    name="OBEN_FE"    />
+      <field field_ref= "OBEN_C"     name="OBEN_C"     />
+      <field field_ref= "OBEN_SI"    name="OBEN_SI"    />
+      <field field_ref= "OBEN_CA"    name="OBEN_CA"    />
+      <field field_ref= "BEN_N"      name="BEN_N"      />
+      <field field_ref= "BEN_FE"     name="BEN_FE"     />
+      <field field_ref= "BEN_C"      name="BEN_C"      />
+      <field field_ref= "BEN_SI"     name="BEN_SI"     />
+      <field field_ref= "BEN_CA"     name="BEN_CA"     />
+      <field field_ref= "DETC"       name="DETC"       />
+      <field field_ref= "SDC__100"   name="SDC__100"   />
+      <field field_ref= "SDC__200"   name="SDC__200"   />
+      <field field_ref= "SDC__500"   name="SDC__500"   />
+      <field field_ref= "SDC_1000"   name="SDC_1000"   />
+      <field field_ref= "INVTC"      name="INVTC"      />
+      <field field_ref= "INVTALK"    name="INVTALK"    />
+      <field field_ref= "INVTO2"     name="INVTO2"     />
+      <field field_ref= "LYSO_CA"    name="LYSO_CA"    />
+      <field field_ref= "COM_RESP"   name="COM_RESP"   />
+      <field field_ref= "PN_LLOSS"   name="PN_LLOSS"   />
+      <field field_ref= "PD_LLOSS"   name="PD_LLOSS"   />
+      <field field_ref= "ZI_LLOSS"   name="ZI_LLOSS"   />
+      <field field_ref= "ZE_LLOSS"   name="ZE_LLOSS"   />
+      <field field_ref= "ZI_MES_N"   name="ZI_MES_N"   />
+      <field field_ref= "ZI_MES_D"   name="ZI_MES_D"   />
+      <field field_ref= "ZI_MES_C"   name="ZI_MES_C"   />
+      <field field_ref= "ZI_MESDC"   name="ZI_MESDC"   />
+      <field field_ref= "ZI_EXCR"    name="ZI_EXCR"    />
+      <field field_ref= "ZI_RESP"    name="ZI_RESP"    />
+      <field field_ref= "ZI_GROW"    name="ZI_GROW"    />
+      <field field_ref= "ZE_MES_N"   name="ZE_MES_N"   />
+      <field field_ref= "ZE_MES_D"   name="ZE_MES_D"   />
+      <field field_ref= "ZE_MES_C"   name="ZE_MES_C"   />
+      <field field_ref= "ZE_MESDC"   name="ZE_MESDC"   />
+      <field field_ref= "ZE_EXCR"    name="ZE_EXCR"    />
+      <field field_ref= "ZE_RESP"    name="ZE_RESP"    />
+      <field field_ref= "ZE_GROW"    name="ZE_GROW"    />
+      <field field_ref= "MDETC"      name="MDETC"      />
+      <field field_ref= "GMIDC"      name="GMIDC"      />
+      <field field_ref= "GMEDC"      name="GMEDC"      />
+      <field field_ref= "INT_ZMI"    name="INT_ZMI"    />
+      <field field_ref= "INT_ZME"    name="INT_ZME"    />
+      <field field_ref= "INT_DET"    name="INT_DET"    />
+      <field field_ref= "INT_DTC"    name="INT_DTC"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_3dd" >
+      <field field_ref= "TPP3"       name="TPP3"       />
+      <field field_ref= "DETFLUX3"   name="DETFLUX3"   />
+      <field field_ref= "REMIN3N"    name="REMIN3N"    />
+      <field field_ref= "PH3"        name="PH3"        />
+      <field field_ref= "OM_CAL3"    name="OM_CAL3"    /> 
+    </field_group>
+
+    <field_group id="groupMEDUSA_dms" >
+      <field field_ref= "DMS_SURF"   name="DMS_SURF"   />
+      <field field_ref= "DMS_ANDR"   name="DMS_ANDR"   />
+      <field field_ref= "DMS_SIMO"   name="DMS_SIMO"   />
+      <field field_ref= "DMS_ARAN"   name="DMS_ARAN"   />
+      <field field_ref= "DMS_HALL"   name="DMS_HALL"   />
+    </field_group>
+
+    <field_group id="groupMEDUSA_riv" >
+      <field field_ref= "RUNOFF"     name="RUNOFF"     />
+      <field field_ref= "RIV_N"      name="RIV_N"      />
+      <field field_ref= "RIV_SI"     name="RIV_SI"     />
+      <field field_ref= "RIV_C"      name="RIV_C"      />
+      <field field_ref= "RIV_ALK"    name="RIV_ALK"    />
+    </field_group>
+
+    <field_group id="groupMEDUSA_bas" >
+     <field field_ref= "BASIN_01"   name= "BASIN_01"   />
+     <field field_ref= "BASIN_02"   name= "BASIN_02"   />
+     <field field_ref= "BASIN_03"   name= "BASIN_03"   />
+     <field field_ref= "BASIN_04"   name= "BASIN_04"   />
+     <field field_ref= "BASIN_05"   name= "BASIN_05"   />
+     <field field_ref= "BASIN_06"   name= "BASIN_06"   />
+     <field field_ref= "BASIN_07"   name= "BASIN_07"   />
+     <field field_ref= "BASIN_08"   name= "BASIN_08"   />
+     <field field_ref= "BASIN_09"   name= "BASIN_09"   />
+     <field field_ref= "BASIN_10"   name= "BASIN_10"   />
+     <field field_ref= "BASIN_11"   name= "BASIN_11"   />
+     <field field_ref= "BASIN_12"   name= "BASIN_12"   />
+     <field field_ref= "BASIN_13"   name= "BASIN_13"   />
+     <field field_ref= "BASIN_14"   name= "BASIN_14"   />
+     <field field_ref= "BASIN_15"   name= "BASIN_15"   />
+     <field field_ref= "BASIN_16"   name= "BASIN_16"   />
+     <field field_ref= "BASIN_17"   name= "BASIN_17"   />
+     <field field_ref= "BASIN_18"   name= "BASIN_18"   />
+     <field field_ref= "BASIN_19"   name= "BASIN_19"   />
+     <field field_ref= "BASIN_20"   name= "BASIN_20"   />
+     <field field_ref= "BASIN_21"   name= "BASIN_21"   />
+     <field field_ref= "BASIN_22"   name= "BASIN_22"   />
+     <field field_ref= "BASIN_23"   name= "BASIN_23"   />
+     <field field_ref= "BASIN_24"   name= "BASIN_24"   />
+     <field field_ref= "BASIN_25"   name= "BASIN_25"   />
+     <field field_ref= "BASIN_26"   name= "BASIN_26"   />
+     <field field_ref= "BASIN_27"   name= "BASIN_27"   />
+     <field field_ref= "BASIN_28"   name= "BASIN_28"   />
+     <field field_ref= "BASIN_29"   name= "BASIN_29"   />
+     <field field_ref= "BASIN_30"   name= "BASIN_30"   />
+     <field field_ref= "BASIN_31"   name= "BASIN_31"   />
+     <field field_ref= "BASIN_32"   name= "BASIN_32"   />
+     <field field_ref= "BASIN_33"   name= "BASIN_33"   />
+     <field field_ref= "BASIN_34"   name= "BASIN_34"   />
+     <field field_ref= "BASIN_35"   name= "BASIN_35"   />
+     <field field_ref= "BASIN_36"   name= "BASIN_36"   />
+     <field field_ref= "BASIN_37"   name= "BASIN_37"   />
+     <field field_ref= "BASIN_38"   name= "BASIN_38"   />
+     <field field_ref= "BASIN_39"   name= "BASIN_39"   />
+     <field field_ref= "BASIN_40"   name= "BASIN_40"   />
+     <field field_ref= "BASIN_41"   name= "BASIN_41"   />
+     <field field_ref= "BASIN_42"   name= "BASIN_42"   />
+     <field field_ref= "BASIN_43"   name= "BASIN_43"   />
+     <field field_ref= "BASIN_44"   name= "BASIN_44"   />
+     <field field_ref= "BASIN_45"   name= "BASIN_45"   />
+    </field_group>
+
+
+</field_definition>
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_dyn.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_dyn.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_dyn.xml	(revision 7693)
@@ -0,0 +1,1208 @@
+<!--
+< GO6.0 version of the XIOS namelist >
+< XIOS2 version namelist >
+
+<?xml version="1.0"?>
+       -->
+ 
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+   <field_definition level="1" prec="4" operation="average" enabled=".TRUE." default_value="1.e20" detect_missing_value="true"> <!-- time step automaticaly defined -->
+
+    <!-- 
+         ============================================================================================================
+                                  Physical ocean and ice model variables
+============================================================================================================
+    -->
+
+      <!-- T grid -->
+
+      <field_group id="grid_T" grid_ref="grid_T_2D" >
+         <field id="e3t"          long_name="Ocean Model cell Thickness"   standard_name="cell_thickness"   unit="m"   grid_ref="grid_T_3D"/>
+         <field id="e3t_surf"     field_ref="e3t"  long_name="T-cell thickness: surface layer"   standard_name="cell_thickness"   unit="m"  grid_ref="grid_T_surface_extract"/>
+         <field id="e3t_0"        long_name="Initial T-cell thickness"   standard_name="ref_cell_thickness"   unit="m"   grid_ref="grid_T_3D"/>
+
+         <field id="toce"         long_name="Sea Water Potential Temperature"         standard_name="sea_water_potential_temperature"   unit="degree_C"     grid_ref="grid_T_3D"/>
+         <field id="toce_e3t"     long_name="temperature * e3t"                                                     unit="degree_C*m"   grid_ref="grid_T_3D" > toce * e3t </field >
+         <field id="toce2_e3t"    long_name="temperature squared * e3t"                                             unit="degC*degC*m"   grid_ref="grid_T_3D" > toce * toce * e3t </field >
+         <field id="soce"         long_name="Sea Water Salinity"            standard_name="sea_water_salinity"      unit="0.001"     grid_ref="grid_T_3D"/>
+         <field id="soce_e3t"     long_name="salinity * e3t"                                                        unit="0.001*m"   grid_ref="grid_T_3D" > soce * e3t </field >
+         <field id="soce2_e3t"    long_name="salinity squared * e3t"                                                unit="1e-3*1e-3*m"   grid_ref="grid_T_3D" > soce * soce * e3t </field >
+         <field id="toce_e3t_vsum" field_ref="toce_e3t" grid_ref="vert_sum" />
+         <field id="e3t_vsum" field_ref="e3t" grid_ref="vert_sum" />
+         <field id="toce_vmean" field_ref="toce_e3t_vsum" grid_ref="vert_sum"> toce_e3t_vsum/e3t_vsum </field>
+         <field id="toce_e3t_300" field_ref="toce_e3t"  unit="degree_C*m"   grid_ref="zoom_300" />
+         <field id="e3t_300" field_ref="e3t"  unit="degree_C*m"   grid_ref="zoom_300" />
+         <field id="toce_e3t_vsum300" field_ref="toce_e3t_300" grid_ref="zoom_300_sum" />
+         <field id="e3t_vsum300" field_ref="e3t_300" grid_ref="zoom_300_sum" />
+         <field id="toce_vmean300" field_ref="toce_e3t_vsum300" grid_ref="zoom_300_sum"> toce_e3t_vsum300/e3t_vsum300 </field>
+
+         <field id="sst"          long_name="Sea Surface Temperature"             standard_name="sea_surface_temperature"             unit="degree_C"     />
+         <field id="sst2"         long_name="Square of Sea Surface Temperature"   standard_name="square_of_sea_surface_temperature"   unit="degree_C2"     > sst * sst </field >
+         <field id="sstmax"       long_name="max of sea surface temperature"   field_ref="sst"   operation="maximum"                                  />
+         <field id="sstmin"       long_name="min of sea surface temperature"   field_ref="sst"   operation="minimum"                                  />
+         <field id="sstgrad"      long_name="module of sst gradient"                                                                  unit="degree_C/m"   />
+         <field id="sstgrad2"     long_name="square of module of sst gradient"                                                        unit="degree_C2/m2" />
+         <field id="sbt"          long_name="sea bottom temperature"                                                                  unit="degree_C"     />
+         <field id="tosmint"      long_name="vertical integral of temperature times density"   standard_name="integral_wrt_depth_of_product_of_density_and_potential_temperature"  unit="(kg m2) degree_C" />
+
+         <field id="sss"          long_name="Sea Surface Salinity"             standard_name="sea_surface_salinity"   unit="0.001" />
+         <field id="sss2"         long_name="square of sea surface salinity"                                          unit="1e-6"  > sss * sss </field >
+         <field id="sssmax"       long_name="max of sea surface salinity"   field_ref="sss"   operation="maximum"                 />
+         <field id="sssmin"       long_name="min of sea surface salinity"   field_ref="sss"   operation="minimum"                 />
+         <field id="sbs"          long_name="sea bottom salinity"                                                     unit="0.001" />
+         <field id="somint"       long_name="vertical integral of salinity times density"   standard_name="integral_wrt_depth_of_product_of_density_and_salinity"  unit="(kg m2) x (1e-3)" />
+
+         <field id="taubot"       long_name="bottom stress module"                                                    unit="N/m2" />              
+
+         <field id="ssh"          long_name="sea surface height"             standard_name="sea_surface_height_above_geoid"             unit="m" />
+         <field id="ssh2"         long_name="square of sea surface height"   standard_name="square_of_sea_surface_height_above_geoid"   unit="m2" > ssh * ssh </field >
+         <field id="sshmax"       long_name="max of sea surface height"   field_ref="ssh"   operation="maximum"                                  />
+
+         <field id="mldkz5"       long_name="Turbocline depth (Kz = 5e-4)"                       standard_name="ocean_mixed_layer_thickness_defined_by_vertical_tracer_diffusivity"                unit="m"          />
+         <field id="mldr10_1"     long_name="Mixed Layer Depth (dsigma = 0.01 wrt 10m)"          standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"          />
+         <field id="mldr10_1max"  long_name="Max of Mixed Layer Depth (dsigma = 0.01 wrt 10m)"   field_ref="mldr10_1"   operation="maximum"                                                                          />
+         <field id="mldr10_1min"  long_name="Min of Mixed Layer Depth (dsigma = 0.01 wrt 10m)"   field_ref="mldr10_1"   operation="minimum"                                                                          />
+         <field id="mldzint_1"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_2"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_3"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_4"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_5"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldhtc_1"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_2"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_3"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_4"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_5"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="heatc"        long_name="Heat content vertically integrated"                 standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="saltc"        long_name="Salt content vertically integrated"                                                                                                                   unit="0.001*kg/m2" />
+
+         <!-- EOS -->
+         <field id="alpha"        long_name="thermal expansion"                                                         unit="degree_C-1" grid_ref="grid_T_3D" />
+         <field id="beta"         long_name="haline contraction"                                                        unit="1e3"    grid_ref="grid_T_3D" />
+         <field id="rhop"         long_name="potential density (sigma0)"        standard_name="sea_water_sigma_theta"   unit="kg/m3"  grid_ref="grid_T_3D" />
+
+         <!-- Energy - horizontal divergence -->
+         <field id="eken"         long_name="kinetic energy"          standard_name="specific_kinetic_energy_of_sea_water"   unit="m2/s2"  grid_ref="grid_T_3D" />
+         <field id="hdiv"         long_name="horizontal divergence"                                                          unit="s-1"    grid_ref="grid_T_3D" />
+
+         <!-- variables available with MLE -->
+         <field id="Lf_NHpf"      long_name="MLE: Lf = N H / f"   unit="m" />
+
+         <!-- next variables available with key_diahth -->
+         <field id="mlddzt"       long_name="Thermocline Depth (depth of max dT/dz)"         standard_name="depth_at_maximum_upward_derivative_of_sea_water_potential_temperature"             unit="m"    />
+         <field id="mldr10_3"     long_name="Mixed Layer Depth (dsigma = 0.03 wrt 10m)"      standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"    />
+         <field id="mldr0_1"      long_name="Mixed Layer Depth (dsigma = 0.01 wrt sfc)"      standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"    />
+         <field id="mldr0_3"      long_name="Mixed Layer Depth (dsigma = 0.03 wrt sfc)"      standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"    />
+         <field id="mld_dt02"     long_name="Mixed Layer Depth (|dT| = 0.2 wrt 10m)"         standard_name="ocean_mixed_layer_thickness_defined_by_temperature"                                unit="m"    />
+         <field id="topthdep"     long_name="Top of Thermocline Depth (dT = -0.2 wrt 10m)"   standard_name="ocean_mixed_layer_thickness_defined_by_temperature"                                unit="m"    />
+         <field id="pycndep"      long_name="Pycnocline Depth (dsigma[dT=-0.2] wrt 10m)"     standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"    />
+         <field id="BLT"          long_name="Barrier Layer Thickness"                                                                                                                          unit="m"    > topthdep - pycndep </field>
+         <field id="tinv"         long_name="Max of vertical invertion of temperature"                                                                                                         unit="degree_C"                      />
+         <field id="depti"        long_name="Depth of max. vert. inv. of temperature"                                                                                                          unit="m"                         />
+         <field id="20d"          long_name="Depth of 20C isotherm"                          standard_name="depth_of_isosurface_of_sea_water_potential_temperature"                            unit="m"      axis_ref="iax_20C" />
+         <field id="28d"          long_name="Depth of 28C isotherm"                          standard_name="depth_of_isosurface_of_sea_water_potential_temperature"                            unit="m"      axis_ref="iax_28C" />
+         <field id="hc300"        long_name="Heat content 0-300m"                            standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"                      />
+
+         <!-- variables available with key_diaar5 -->
+         <field id="botpres"      long_name="Sea Water Pressure at Sea Floor"   standard_name="sea_water_pressure_at_sea_floor"   unit="dbar" />
+         <field id="sshdyn"       long_name="dynamic sea surface height"     standard_name="dynamic_sea_surface_height_above_geoid"     unit="m" />
+         <field id="sshdyn2"      long_name="square of dynamic sea surface height"     standard_name="dynamic_sea_surface_height_above_geoid_squared"     unit="m2" > sshdyn * sshdyn </field>
+
+         <!-- variables available with key_vvl -->
+         <field id="tpt_dep"      long_name="T-point depth"                  standard_name="depth_below_geoid"   unit="m"   grid_ref="grid_T_3D" />
+         <field id="e3tdef"       long_name="T-cell thickness deformation"                                       unit="%"   grid_ref="grid_T_3D" />
+      </field_group>
+
+      <!-- Tides -->
+
+      <field_group id="Tides_T" grid_ref="grid_T_2D" operation="once" >
+         <!-- tidal composante -->
+         <field id="M2x"          long_name="M2 Elevation harmonic real part "                             unit="m"        />
+         <field id="M2y"          long_name="M2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="S2x"          long_name="S2 Elevation harmonic real part "                             unit="m"        />
+         <field id="S2y"          long_name="S2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="N2x"          long_name="N2 Elevation harmonic real part "                             unit="m"        />
+         <field id="N2y"          long_name="N2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="K1x"          long_name="K1 Elevation harmonic real part "                             unit="m"        />
+         <field id="K1y"          long_name="K1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="O1x"          long_name="O1 Elevation harmonic real part "                             unit="m"        />
+         <field id="O1y"          long_name="O1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="Q1x"          long_name="Q1 Elevation harmonic real part "                             unit="m"        />
+         <field id="Q1y"          long_name="Q1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="M4x"          long_name="M4 Elevation harmonic real part "                             unit="m"        />
+         <field id="M4y"          long_name="M4 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="K2x"          long_name="K2 Elevation harmonic real part "                             unit="m"        />
+         <field id="K2y"          long_name="K2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="P1x"          long_name="P1 Elevation harmonic real part "                             unit="m"        />
+         <field id="P1y"          long_name="P1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="Mfx"          long_name="Mf Elevation harmonic real part "                             unit="m"        />
+         <field id="Mfy"          long_name="Mf Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="Mmx"          long_name="Mm Elevation harmonic real part "                             unit="m"        />
+         <field id="Mmy"          long_name="Mm Elevation harmonic imaginary part"                         unit="m"        />
+      </field_group>
+
+      <field_group id="Tides_U" grid_ref="grid_U_2D" operation="once" >
+         <field id="M2x_u"        long_name="M2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="M2y_u"        long_name="M2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="S2x_u"        long_name="S2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="S2y_u"        long_name="S2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="N2x_u"        long_name="N2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="N2y_u"        long_name="N2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K1x_u"        long_name="K1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="K1y_u"        long_name="K1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="O1x_u"        long_name="O1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="O1y_u"        long_name="O1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Q1x_u"        long_name="Q1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="Q1y_u"        long_name="Q1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="M4x_u"        long_name="M4 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="M4y_u"        long_name="M4 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K2x_u"        long_name="K2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="K2y_u"        long_name="K2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="P1x_u"        long_name="P1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="P1y_u"        long_name="P1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mfx_u"        long_name="Mf current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="Mfy_u"        long_name="Mf current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mmx_u"        long_name="Mm current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="Mmy_u"        long_name="Mm current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+      </field_group>
+
+      <field_group id="Tides_V" grid_ref="grid_V_2D" operation="once" >
+         <field id="M2x_v"        long_name="M2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="M2y_v"        long_name="M2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="S2x_v"        long_name="S2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="S2y_v"        long_name="S2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="N2x_v"        long_name="N2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="N2y_v"        long_name="N2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K1x_v"        long_name="K1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="K1y_v"        long_name="K1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="O1x_v"        long_name="O1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="O1y_v"        long_name="O1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Q1x_v"        long_name="Q1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="Q1y_v"        long_name="Q1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="M4x_v"        long_name="M4 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="M4y_v"        long_name="M4 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K2x_v"        long_name="K2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="K2y_v"        long_name="K2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="P1x_v"        long_name="P1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="P1y_v"        long_name="P1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mfx_v"        long_name="Mf current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="Mfy_v"        long_name="Mf current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mmx_v"        long_name="Mm current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="Mmy_v"        long_name="Mm current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+      </field_group>
+
+      <!-- SBC -->
+
+      <field_group id="SBC" grid_ref="grid_T_2D" > <!-- time step automaticaly defined based on nn_fsbc -->
+         <field id="empmr"        long_name="Net Upward Water Flux"                standard_name="water_flux_out_of_sea_ice_and_sea_water"                              unit="kg/m2/s"   />
+         <field id="empbmr"       long_name="Net Upward Water Flux at pre. tstep"  standard_name="water_flux_out_of_sea_ice_and_sea_water"                              unit="kg/m2/s"   />
+         <field id="emp_oce"      long_name="Evap minus Precip over ocean"         standard_name="evap_minus_precip_over_sea_water"                                     unit="kg/m2/s"   />
+         <field id="emp_ice"      long_name="Evap minus Precip over ice"           standard_name="evap_minus_precip_over_sea_ice"                                       unit="kg/m2/s"   />
+         <field id="saltflx"      long_name="Downward salt flux"                                                                                                        unit="0.001/m2/s" />
+         <field id="fmmflx"       long_name="Water flux due to freezing/melting"                                                                                        unit="kg/m2/s"   />
+         <field id="snowpre"      long_name="Snow precipitation"                   standard_name="snowfall_flux"                                                        unit="kg/m2/s"   />
+         <field id="runoffs"      long_name="Water Flux into Sea Water From Rivers" standard_name="water_flux_into_sea_water_from_rivers"                                unit="kg/m2/s"   />
+         <field id="precip"       long_name="Total precipitation"                  standard_name="precipitation_flux"                                                   unit="kg/m2/s"   />
+
+         <field id="qt"           long_name="Net Downward Heat Flux"                standard_name="surface_downward_heat_flux_in_sea_water"                              unit="W/m2"                           />
+         <field id="qns"          long_name="non solar Downward Heat Flux"                                                                                               unit="W/m2"                           />
+         <field id="qsr"          long_name="Shortwave Radiation"                   standard_name="net_downward_shortwave_flux_at_sea_water_surface"                     unit="W/m2"                           />
+         <field id="qsr3d"        long_name="Shortwave Radiation 3D distribution"   standard_name="downwelling_shortwave_flux_in_sea_water"                              unit="W/m2"      grid_ref="grid_T_3D" />
+         <field id="qrp"          long_name="Surface Heat Flux: Damping"            standard_name="heat_flux_into_sea_water_due_to_newtonian_relaxation"                 unit="W/m2"                           />
+         <field id="erp"          long_name="Surface Water Flux: Damping"           standard_name="water_flux_out_of_sea_water_due_to_newtonian_relaxation"              unit="kg/m2/s"                        />
+         <field id="taum"         long_name="wind stress module"                    standard_name="magnitude_of_surface_downward_stress"                                 unit="N/m2"                           />
+         <field id="wspd"         long_name="wind speed module"                     standard_name="wind_speed"                                                           unit="m/s"                            />
+
+         <!-- * variable relative to atmospheric pressure forcing : available with ln_apr_dyn -->
+         <field id="ssh_ib"       long_name="Inverse barometer sea surface height"  standard_name="sea_surface_height_correction_due_to_air_pressure_at_low_frequency"   unit="m"        />
+
+         <!-- * variable related to ice shelf forcing * -->
+         <field id="berg_calve"   long_name="Iceberg calving"                               unit="kg/m2/s"  />
+         <field id="fwfisf"       long_name="Ice shelf melting"                             unit="kg/m2/s"  />
+         <field id="fwfisf3d"     long_name="Ice shelf melting"                             unit="kg/m2/s"  grid_ref="grid_T_3D" />
+         <field id="qlatisf"      long_name="Ice shelf latent heat flux"                    unit="W/m2"     />
+         <field id="qlatisf3d"    long_name="Ice shelf latent heat flux"                    unit="W/m2"     grid_ref="grid_T_3D" />
+         <field id="qhcisf"       long_name="Ice shelf heat content flux"                   unit="W/m2"     />
+         <field id="qhcisf3d"     long_name="Ice shelf heat content flux"                   unit="W/m2"     grid_ref="grid_T_3D" />
+         <field id="isfgammat"    long_name="transfert coefficient for isf (temperature)"   unit="m/s"      />
+         <field id="isfgammas"    long_name="transfert coefficient for isf (salinity)"      unit="m/s"      />
+         <field id="stbl"         long_name="salinity in the Losh tbl"                      unit="0.001"     />
+         <field id="ttbl"         long_name="temperature in the Losh tbl"                   unit="degree_C"     />
+
+         <!-- *_oce variables available with ln_blk_clio or ln_blk_core -->
+         <field id="qlw_oce"      long_name="Longwave Downward Heat Flux over open ocean"  standard_name="surface_net_downward_longwave_flux"   unit="W/m2"  />
+         <field id="qsb_oce"      long_name="Sensible Downward Heat Flux over open ocean"  standard_name="surface_downward_sensible_heat_flux"  unit="W/m2"  />
+         <field id="qla_oce"      long_name="Latent Downward Heat Flux over open ocean"    standard_name="surface_downward_latent_heat_flux"    unit="W/m2"  />
+         <field id="qemp_oce"     long_name="Downward Heat Flux from E-P over open ocean"                                                       unit="W/m2"  />
+         <field id="taum_oce"     long_name="wind stress module over open ocean"           standard_name="magnitude_of_surface_downward_stress" unit="N/m2"  />
+
+         <!-- available key_oasis3 -->
+         <field id="snow_ao_cea"  long_name="Snow over ice-free ocean (cell average)"   standard_name="snowfall_flux"                             unit="kg/m2/s"  />
+         <field id="snow_ai_cea"  long_name="Snow over sea-ice (cell average)"          standard_name="snowfall_flux"                             unit="kg/m2/s"  />
+         <field id="subl_ai_cea"  long_name="Sublimation over sea-ice (cell average)"   standard_name="surface_snow_and_ice_sublimation_flux"     unit="kg/m2/s"  />
+         <field id="icealb_cea"   long_name="Ice albedo (cell average)"                 standard_name="sea_ice_albedo"                            unit="1"        />
+         <field id="calving_cea"  long_name="Calving"                                   standard_name="water_flux_into_sea_water_from_icebergs"   unit="kg/m2/s"  />
+
+         <!-- available if key_oasis3 + conservative method -->
+         <field id="rain"          long_name="Liquid precipitation"                                     standard_name="rainfall_flux"                                                                 unit="kg/m2/s"  />
+         <field id="rain_ao_cea"   long_name="Liquid precipitation over ice-free ocean (cell average)"  standard_name="rainfall_flux"                                                                 unit="kg/m2/s"  />
+         <field id="evap_ao_cea"   long_name="Evaporation over ice-free ocean (cell average)"           standard_name="water_evaporation_flux"                                                        unit="kg/m2/s"  />
+         <field id="isnwmlt_cea"   long_name="Snow over Ice melting (cell average)"                     standard_name="surface_snow_melt_flux"                                                        unit="kg/m2/s"  />
+         <field id="fsal_virt_cea" long_name="Virtual salt flux due to ice formation (cell average)"    standard_name="virtual_salt_flux_into_sea_water_due_to_sea_ice_thermodynamics"                unit="kg/m2/s"  />
+         <field id="fsal_real_cea" long_name="Real salt flux due to ice formation (cell average)"       standard_name="downward_sea_ice_basal_salt_flux"                                              unit="kg/m2/s"  />
+         <field id="hflx_rain_cea" long_name="heat flux due to rainfall"                                standard_name="temperature_flux_due_to_rainfall_expressed_as_heat_flux_into_sea_water"        unit="W/m2"     />
+         <field id="hflx_prec_cea" long_name="heat flux due to precipitation"                           standard_name="temperature_flux_due_to_precipitation_expressed_as_heat_flux_into_sea_water"        unit="W/m2"     />
+         <field id="hflx_evap_cea" long_name="heat flux due to evaporation"                             standard_name="temperature_flux_due_to_evaporation_expressed_as_heat_flux_out_of_sea_water"   unit="W/m2"     />
+         <field id="hflx_snow_cea" long_name="heat flux due to snow falling over ice-free ocean"        standard_name="heat_flux_into_sea_water_due_to_snow_thermodynamics"                           unit="W/m2"     />
+         <field id="hflx_ice_cea"  long_name="heat flux due to ice thermodynamics"                      standard_name="heat_flux_into_sea_water_due_to_sea_ice_thermodynamics"                        unit="W/m2"     />
+         <field id="hflx_rnf_cea"  long_name="heat flux due to runoffs"                                 standard_name="temperature_flux_due_to_runoff_expressed_as_heat_flux_into_sea_water"          unit="W/m2"     />
+         <field id="hflx_cal_cea"  long_name="heat flux due to calving"                                 standard_name="heat_flux_into_sea_water_due_to_iceberg_thermodynamics"                        unit="W/m2"     />
+         <field id="bicemel_cea"   long_name="Rate of Melt at Sea Ice Base (cell average)"              standard_name="tendency_of_sea_ice_amount_due_to_basal_melting"                               unit="kg/m2/s"  />
+         <field id="licepro_cea"   long_name="Lateral Sea Ice Growth Rate (cell average)"               standard_name="tendency_of_sea_ice_amount_due_to_lateral_growth_of_ice_floes"                 unit="kg/m2/s"  />
+         <field id="snowmel_cea"   long_name="Snow Melt Rate (cell average)"                            standard_name="surface_snow_melt_flux"                                                        unit="kg/m2/s"  />
+         <field id="sntoice_cea"   long_name="Snow-Ice Formation Rate (cell average)"                   standard_name="tendency_of_sea_ice_amount_due_to_snow_conversion"                             unit="kg/m2/s"  />
+         <field id="ticemel_cea"   long_name="Rate of Melt at Upper Surface of Sea Ice (cell average)"  standard_name="tendency_of_sea_ice_amount_due_to_surface_melting"                             unit="kg/m2/s"  />
+
+         <!-- ice fields -->
+         <field id="ice_cover"    long_name="Ice fraction"                                                 standard_name="sea_ice_area_fraction"                              unit="1"            />
+
+         <field id="qsr_ai_cea"   long_name="Air-Ice downward solar heat flux (cell average)"              standard_name="surface_downwelling_shortwave_flux_in_air"          unit="W/m2"         />
+         <field id="qns_ai_cea"   long_name="Air-Ice downward non-solar heat flux (cell average)"                                                                             unit="W/m2"         />
+         <field id="qla_ai_cea"   long_name="Air-Ice downward Latent heat flux (cell average)"             standard_name="surface_downward_latent_heat_flux"                  unit="W/m2"         />
+
+         <field id="qsr_io_cea"   long_name="Ice-Oce downward solar heat flux (cell average)"              standard_name="net_downward_shortwave_flux_at_sea_water_surface"   unit="W/m2"         />
+         <field id="qns_io_cea"   long_name="Ice-Oce downward non-solar heat flux (cell average)"                                                                             unit="W/m2"         />
+
+         <field id="snowthic_cea" long_name="Snow thickness (cell average)"                                standard_name="surface_snow_thickness"                             unit="m"            />
+         <field id="icethic_cea"  long_name="Ice thickness (cell average)"                                 standard_name="sea_ice_thickness"                                  unit="m"            />
+         <field id="iceprod_cea"  long_name="Ice production (cell average)"                                                                                                   unit="m/s"          />
+         <field id="iiceconc"     long_name="Ice concentration"                                            standard_name="sea_ice_area_fraction"                              unit="1"            />
+
+         <field id="ice_pres"     long_name="Ice presence"                                                                                                                    unit=""             />
+         <field id="ist_cea"      long_name="Ice surface temperature (cell average)"                       standard_name="surface_temperature"                                unit="degree_C"         />
+         <field id="ist_ipa"      long_name="Ice surface temperature (ice presence average)"               standard_name="surface_temperature"                                unit="degree_C"         />
+         <field id="uice_ipa"     long_name="Ice velocity along i-axis at I-point (ice presence average)"  standard_name="sea_ice_x_velocity"                                 unit="m/s"          />
+         <field id="vice_ipa"     long_name="Ice velocity along j-axis at I-point (ice presence average)"  standard_name="sea_ice_y_velocity"                                 unit="m/s"          />
+
+         <field id="utau_ice"     long_name="Wind stress along i-axis over the ice at i-point"             standard_name="surface_downward_x_stress"                          unit="N/m2"         />
+         <field id="vtau_ice"     long_name="Wind stress along j-axis over the ice at i-point"             standard_name="surface_downward_y_stress"                          unit="N/m2"         />
+
+         <field id="u_imasstr"    long_name="Sea-ice mass transport along i-axis"                          standard_name="sea_ice_x_transport"                                unit="kg/s"         />
+         <field id="v_imasstr"    long_name="Sea-ice mass transport along j-axis"                          standard_name="sea_ice_y_transport"                                unit="kg/s"         />
+         <field id="emp_x_sst"    long_name="Concentration/Dilution term on SST"                                                                                              unit="kg*degree_C/m2/s" />
+         <field id="emp_x_sss"    long_name="Concentration/Dilution term on SSS"                                                                                              unit="kg*0.001/m2/s" />
+
+         <field id="iceconc"      long_name="ice concentration"                                            standard_name="sea_ice_area_fraction"                              unit="%"            />
+         <field id="isst"         long_name="sea surface temperature"                                      standard_name="sea_surface_temperature"                            unit="degree_C"         />
+         <field id="isss"         long_name="sea surface salinity"                                         standard_name="sea_surface_salinity"                               unit="0.001"         />
+         <field id="qt_oce"       long_name="total flux at ocean surface"                                  standard_name="surface_downward_heat_flux_in_sea_water"            unit="W/m2"         />
+         <field id="qsr_oce"      long_name="solar heat flux at ocean surface"                             standard_name="net_downward_shortwave_flux_at_sea_water_surface"   unit="W/m2"         />
+         <field id="qns_oce"      long_name="non-solar heat flux at ocean surface"                                                                                            unit="W/m2"         />
+         <field id="qt_ice"       long_name="total heat flux at ice surface: sum over categories"          standard_name="surface_downward_heat_flux_in_air"                  unit="W/m2"         />
+         <field id="qsr_ice"      long_name="solar heat flux at ice surface: sum over categories"          standard_name="surface_downwelling_shortwave_flux_in_air"          unit="W/m2"         />
+         <field id="qns_ice"      long_name="non-solar heat flux at ice surface: sum over categories"                                                                         unit="W/m2"         />
+         <field id="qtr_ice"      long_name="solar heat flux transmitted through ice: sum over categories"                                                                    unit="W/m2"         />
+         <field id="qemp_ice"     long_name="Downward Heat Flux from E-P over ice"                                                                                            unit="W/m2"         />
+         <field id="micesalt"     long_name="Mean ice salinity"                                                                                                               unit="0.001"         />
+         <field id="miceage"      long_name="Mean ice age"                                                                                                                    unit="years"        />
+         <field id="alb_ice"      long_name="Mean albedo over sea ice"                                                                                                        unit=""             />
+         <field id="albedo"       long_name="Mean albedo over sea ice and ocean"                                                                                              unit=""             />
+
+         <field id="iceage_cat"   long_name="Ice age for categories"                                       unit="days"   axis_ref="ncatice" />
+         <field id="iceconc_cat"  long_name="Ice concentration for categories"                             unit="%"      axis_ref="ncatice" />
+         <field id="icethic_cat"  long_name="Ice thickness for categories"                                 unit="m"      axis_ref="ncatice" />
+         <field id="snowthic_cat" long_name="Snow thicknessi for categories"                               unit="m"      axis_ref="ncatice" />
+         <field id="salinity_cat" long_name="Sea-Ice Bulk salinity for categories"                         unit="g/kg"   axis_ref="ncatice" />
+         <field id="brinevol_cat" long_name="Brine volume for categories"                                  unit="%"      axis_ref="ncatice" />
+         <field id="icetemp_cat"  long_name="Ice temperature for categories"                               unit="degree_C"   axis_ref="ncatice" />
+         <field id="snwtemp_cat"  long_name="Snow temperature for categories"                              unit="degree_C"   axis_ref="ncatice" />
+
+         <field id="micet"        long_name="Mean ice temperature"                                         unit="degree_C"     />
+         <field id="icehc"        long_name="ice total heat content"                                       unit="10^9J"    />
+         <field id="isnowhc"      long_name="snow total heat content"                                      unit="10^9J"    />
+         <field id="icest"        long_name="ice surface temperature"                                      unit="degree_C"     />
+         <field id="ibrinv"       long_name="brine volume"                                                 unit="%"        />
+         <field id="icecolf"      long_name="frazil ice collection thickness"                              unit="m"        />
+         <field id="icestr"       long_name="ice strength"                                                 unit="N/m"      />
+         <field id="icevel"       long_name="ice velocity"                                                 unit="m/s"      />
+         <field id="idive"        long_name="divergence"                                                   unit="1e-8s-1"  />
+         <field id="ishear"       long_name="shear"                                                        unit="1e-8s-1"  />
+         <field id="icevolu"      long_name="ice volume"                                                   unit="m"        />
+         <field id="snowvol"      long_name="snow volume"                                                  unit="m"        />
+
+         <field id="icetrp"       long_name="ice volume transport"                                         unit="m/day"          />
+         <field id="snwtrp"       long_name="snw volume transport"                                         unit="m/day"          />
+         <field id="saltrp"       long_name="salt content transport"                                       unit="0.001*kg/m2/day" />
+         <field id="deitrp"       long_name="advected ice enthalpy"                                        unit="W/m2"           />
+         <field id="destrp"       long_name="advected snw enthalpy"                                        unit="W/m2"           />
+
+         <field id="sfxbri"       long_name="brine salt flux"                                              unit="0.001*kg/m2/day" />
+         <field id="sfxdyn"       long_name="salt flux from ridging rafting"                               unit="0.001*kg/m2/day" />
+         <field id="sfxres"       long_name="salt flux from lipupdate (resultant)"                         unit="0.001*kg/m2/day" />
+         <field id="sfxbog"       long_name="salt flux from bot growth"                                    unit="0.001*kg/m2/day" />
+         <field id="sfxbom"       long_name="salt flux from bot melt"                                      unit="0.001*kg/m2/day" />
+         <field id="sfxsum"       long_name="salt flux from surf melt"                                     unit="0.001*kg/m2/day" />
+         <field id="sfxsni"       long_name="salt flux from snow-ice formation"                            unit="0.001*kg/m2/day" />
+         <field id="sfxopw"       long_name="salt flux from open water ice formation"                      unit="0.001*kg/m2/day" />
+         <field id="sfxsub"       long_name="salt flux from sublimation"                                   unit="0.001*kg/m2/day" />
+         <field id="sfx"          long_name="salt flux total"                                              unit="0.001*kg/m2/day" />
+
+         <field id="vfxbog"       long_name="daily bottom thermo ice prod."                                unit="m/day"   />
+         <field id="vfxdyn"       long_name="daily  dynamic ice prod."                                     unit="m/day"   />
+         <field id="vfxopw"       long_name="daily lateral thermo ice prod."                               unit="m/day"   />
+         <field id="vfxsni"       long_name="daily snowice ice prod."                                      unit="m/day"   />
+         <field id="vfxsum"       long_name="surface melt"                                                 unit="m/day"   />
+         <field id="vfxbom"       long_name="bottom melt"                                                  unit="m/day"   />
+         <field id="vfxres"       long_name="daily resultant ice prod./melting from limupdate"             unit="m/day"   />
+         <field id="vfxice"       long_name="ice melt/growth"                                              unit="m/day"   />
+         <field id="vfxsnw"       long_name="snw melt/growth"                                              unit="m/day"   />
+         <field id="vfxsub"       long_name="snw sublimation"                                              unit="m/day"   />
+         <field id="vfxspr"       long_name="snw precipitation on ice"                                     unit="m/day"   />
+         <field id="vfxthin"      long_name="daily thermo ice prod. for thin ice(<20cm) + open water"      unit="m/day"   />
+
+         <field id="afxtot"       long_name="area tendency (total)"                                        unit="day-1"   />
+         <field id="afxdyn"       long_name="area tendency (dynamics)"                                     unit="day-1"   />
+         <field id="afxthd"       long_name="area tendency (thermo)"                                       unit="day-1"   />
+
+         <field id="hfxsum"       long_name="heat fluxes causing surface ice melt"                         unit="W/m2"  />
+         <field id="hfxbom"       long_name="heat fluxes causing bottom ice melt"                          unit="W/m2"  />
+         <field id="hfxbog"       long_name="heat fluxes causing bottom ice growth"                        unit="W/m2"  />
+         <field id="hfxdif"       long_name="heat fluxes causing ice temperature change"                   unit="W/m2"  />
+         <field id="hfxopw"       long_name="heat fluxes causing open water ice formation"                 unit="W/m2"  />
+         <field id="hfxsnw"       long_name="heat fluxes causing snow melt"                                unit="W/m2"  />
+         <field id="hfxerr"       long_name="heat fluxes error after heat diffusion"                       unit="W/m2"  />
+         <field id="hfxerr_rem"   long_name="heat fluxes error after remapping"                            unit="W/m2"  />
+         <field id="hfxout"       long_name="total heat fluxes received by the ocean"                      unit="W/m2"  />
+         <field id="hfxin"        long_name="total heat fluxes at the ice/ocean surface"                   unit="W/m2"  />
+
+         <!-- heat flux associated with mass exchange -->
+         <field id="hfxthd"       long_name="heat fluxes from ice-ocean mass exchange during thermo"       unit="W/m2"  />
+         <field id="hfxdyn"       long_name="heat fluxes from ice-ocean mass exchange during dynamic"      unit="W/m2"  />
+         <field id="hfxres"       long_name="heat fluxes from ice-ocean mass exchange during resultant"    unit="W/m2"  />
+         <field id="hfxsub"       long_name="heat fluxes from ice-atm. mass exchange during sublimation"   unit="W/m2"  />
+         <field id="hfxspr"       long_name="heat fluxes from ice-atm. mass exchange during snow precip"   unit="W/m2"  />
+
+         <!-- diags -->
+         <field id="hfxdhc"       long_name="Heat content variation in snow and ice"                       unit="W/m2" />
+         <field id="hfxtur"       long_name="turbulent heat flux at the ice base"                          unit="W/m2" />
+         <!-- sbcssm variables -->
+         <field id="sst_m"    unit="degree_C" />
+         <field id="sss_m"    unit="psu"  />
+         <field id="ssu_m"    unit="m/s"  />
+         <field id="ssv_m"    unit="m/s"  />
+         <field id="ssh_m"    unit="m"    />
+         <field id="e3t_m"    unit="m"    />
+         <field id="frq_m"    unit="-"    />
+
+      </field_group>
+
+      <!-- U grid -->
+
+      <field_group id="grid_U"   grid_ref="grid_U_2D">
+         <field id="e3u"          long_name="U-cell thickness"                                       standard_name="cell_thickness"              unit="m"          grid_ref="grid_U_3D" />
+         <field id="e3u_0"        long_name="Initial U-cell thickness"                               standard_name="ref_cell_thickness"          unit="m"          grid_ref="grid_U_3D"/>
+         <field id="utau"         long_name="Surface Downward X Stress"                               standard_name="surface_downward_x_stress"   unit="N/m2"                            />
+         <field id="uoce"         long_name="Sea Water X Velocity"                             standard_name="sea_water_x_velocity"        unit="m/s"        grid_ref="grid_U_3D" />
+         <field id="uoce_e3u"     long_name="ocean current along i-axis * e3u"                                                                   unit="m2/s"       grid_ref="grid_U_3D"  > uoce * e3u </field>
+         <field id="uoce2_e3u"    long_name="ocean current along i-axis squared * e3u"                                                           unit="m3/s2"      grid_ref="grid_U_3D"  > uoce * uoce * e3u </field>
+         <field id="ssu"          long_name="ocean surface current along i-axis"                                                                 unit="m/s"                             />
+         <field id="sbu"          long_name="ocean bottom current along i-axis"                                                                  unit="m/s"                             />
+         <field id="ubar"         long_name="ocean barotropic current along i-axis"                                                              unit="m/s"                             />
+         <field id="uocetr_eff"   long_name="Effective ocean transport along i-axis"                 standard_name="ocean_volume_x_transport"    unit="m3/s"       grid_ref="grid_U_3D" />
+         <field id="uocet"        long_name="ocean transport along i-axis times temperature (CRS)"                                               unit="degree_C*m/s"   grid_ref="grid_U_3D" />
+         <field id="uoces"        long_name="ocean transport along i-axis times salinity (CRS)"                                                  unit="0.001*m/s"   grid_ref="grid_U_3D" />
+
+         <!-- variables available with MLE -->
+         <field id="psiu_mle"     long_name="MLE streamfunction along i-axis"   unit="m3/s"   grid_ref="grid_U_3D" />
+
+         <!-- uoce_eiv: available with key_traldf_eiv and key_diaeiv -->
+         <field id="uoce_eiv"      long_name="EIV ocean current along i-axis"   standard_name="bolus_sea_water_x_velocity"   unit="m/s"   grid_ref="grid_U_3D" />
+         <field id="ueiv_masstr"   long_name="EIV Ocean Mass X Transport"    standard_name="bolus_ocean_mass_x_transport"                          unit="kg/s"        grid_ref="grid_U_3D" />
+         <field id="ueiv_heattr3d" long_name="ocean bolus heat transport along i-axis"    standard_name="ocean_heat_x_transport_due_to_bolus_advection"   unit="W"    grid_ref="grid_U_3D" />
+         <field id="ueiv_salttr3d" long_name="ocean bolus salt transport along i-axis"    standard_name="ocean_salt_x_transport_due_to_bolus_advection"   unit="kg"   grid_ref="grid_U_3D" />
+         <field id="ueiv_masstr"  long_name="EIV Ocean Mass X Transport"    standard_name="bolus_ocean_mass_x_transport"                          unit="kg/s"        grid_ref="grid_U_3D" />
+
+         <!-- uoce_eiv: available with key_trabbl -->
+         <field id="uoce_bbl"     long_name="BBL ocean current along i-axis"    unit="m/s"  />
+         <field id="ahu_bbl"      long_name="BBL diffusive flux along i-axis"   unit="m3/s" />
+
+         <!-- variable for ice shelves -->
+         <field id="utbl"         long_name="zonal current in the Losh tbl"     unit="m/s" />
+
+         <!-- variables available with key_diaar5 -->
+         <field id="u_masstr"     long_name="Ocean Mass X Transport"    standard_name="ocean_mass_x_transport"                          unit="kg/s"        grid_ref="grid_U_3D" />
+         <field id="u_masstr_vint" long_name="vertical integral of ocean eulerian mass transport along i-axis"    standard_name="vertical_integral_of_ocean_mass_x_transport"  unit="kg/s" />
+         <field id="u_heattr"     long_name="ocean eulerian heat transport along i-axis"    standard_name="ocean_heat_x_transport"                          unit="W"                                />
+         <field id="uadv_heattr"  long_name="ocean advective heat transport along i-axis"    standard_name="advectice_ocean_heat_x_transport"                          unit="W"                                />
+         <field id="u_salttr"     long_name="ocean eulerian salt transport along i-axis"    standard_name="ocean_salt_x_transport"                          unit="0.001*kg/s"                        />
+         <field id="ueiv_heattr"  long_name="ocean bolus heat transport along i-axis"       standard_name="ocean_heat_x_transport_due_to_bolus_advection"   unit="W"                                />
+         <field id="ueiv_salttr"  long_name="ocean bolus salt transport along i-axis"       standard_name="ocean_salt_x_transport_due_to_bolus_advection"   unit="W"                                />
+         <field id="udiff_heattr" long_name="ocean diffusion heat transport along i-axis"   standard_name="ocean_heat_x_transport_due_to_diffusion"         unit="W"                                />
+      </field_group>
+
+      <!-- V grid -->
+
+      <field_group id="grid_V"   grid_ref="grid_V_2D">
+         <field id="e3v"          long_name="V-cell thickness"                                       standard_name="cell_thickness"              unit="m"          grid_ref="grid_V_3D" />
+         <field id="e3v_0"        long_name="Initial V-cell thickness"                               standard_name="ref_cell_thickness"          unit="m"          grid_ref="grid_V_3D"/>
+         <field id="vtau"         long_name="Surface Downward Y Stress"                               standard_name="surface_downward_y_stress"   unit="N/m2"                            />
+         <field id="voce"         long_name="Sea Water Y Velocity"                             standard_name="sea_water_y_velocity"        unit="m/s"        grid_ref="grid_V_3D" />
+         <field id="voce_e3v"     long_name="ocean current along j-axis * e3v"                                                                   unit="m2/s"       grid_ref="grid_V_3D"  > voce * e3v </field>
+         <field id="voce2_e3v"    long_name="ocean current along j-axis squared * e3v"                                                           unit="m3/s2"      grid_ref="grid_V_3D"  > voce * voce * e3v </field>
+         <field id="ssv"          long_name="ocean surface current along j-axis"                                                                 unit="m/s"                             />
+         <field id="sbv"          long_name="ocean bottom current along j-axis"                                                                  unit="m/s"                             />
+         <field id="vbar"         long_name="ocean barotropic current along j-axis"                                                              unit="m/s"                             />
+         <field id="vocetr_eff"   long_name="Effective ocean transport along j-axis"                 standard_name="ocean_volume_y_transport"    unit="m3/s"       grid_ref="grid_V_3D" />
+         <field id="vocet"        long_name="ocean transport along j-axis times temperature (CRS)"                                               unit="degree_C*m/s"   grid_ref="grid_V_3D" />
+         <field id="voces"        long_name="ocean transport along j-axis times salinity (CRS)"                                                  unit="0.001*m/s"   grid_ref="grid_V_3D" />
+
+         <!-- variables available with MLE -->
+         <field id="psiv_mle"     long_name="MLE streamfunction along j-axis"   unit="m3/s"   grid_ref="grid_V_3D" />
+
+         <!-- voce_eiv: available with key_traldf_eiv and key_diaeiv -->
+         <field id="voce_eiv"     long_name="EIV ocean current along j-axis"   standard_name="bolus_sea_water_y_velocity"   unit="m/s"   grid_ref="grid_V_3D" />
+         <field id="veiv_masstr"   long_name="EIV Ocean Mass Y Transport"    standard_name="bolus_ocean_mass_y_transport"                          unit="kg/s"        grid_ref="grid_V_3D" />
+         <field id="veiv_heattr3d" long_name="ocean bolus heat transport along j-axis"    standard_name="ocean_heat_y_transport_due_to_bolus_advection"   unit="W"    grid_ref="grid_V_3D" />
+         <field id="veiv_salttr3d" long_name="ocean bolus salt transport along j-axis"    standard_name="ocean_salt_y_transport_due_to_bolus_advection"   unit="kg"   grid_ref="grid_U_3D" />
+
+         <!-- voce_eiv: available with key_trabbl -->
+         <field id="voce_bbl"     long_name="BBL ocean current along j-axis"    unit="m/s"  />
+         <field id="ahv_bbl"      long_name="BBL diffusive flux along j-axis"   unit="m3/s" />
+
+         <!-- variable for ice shelves -->
+         <field id="vtbl"         long_name="meridional current in the Losh tbl"   unit="m/s" />
+
+         <!-- variables available with key_diaar5 -->
+         <field id="v_masstr"     long_name="Ocean Mass Y Transport"    standard_name="ocean_mass_y_transport"                          unit="kg/s"        grid_ref="grid_V_3D" />
+         <field id="v_heattr"     long_name="Ocean Heat X Transport"    standard_name="ocean_heat_y_transport"                          unit="W"                                />
+         <field id="vadv_heattr"  long_name="ocean advective heat transport along j-axis"    standard_name="advectice_ocean_heat_y_transport"                          unit="W"                                />
+         <field id="v_salttr"     long_name="ocean eulerian salt transport along i-axis"    standard_name="ocean_salt_y_transport"                          unit="0.001*kg/s"                        />
+         <field id="veiv_heattr"  long_name="ocean bolus heat transport along j-axis"       standard_name="ocean_heat_y_transport_due_to_bolus_advection"   unit="W"                                />
+         <field id="veiv_salttr"  long_name="ocean bolus salt transport along j-axis"       standard_name="ocean_salt_y_transport_due_to_bolus_advection"   unit="W"                                />
+         <field id="vdiff_heattr" long_name="ocean diffusion heat transport along j-axis"   standard_name="ocean_heat_y_transport_due_to_diffusion"         unit="W"                                />
+      </field_group>
+
+      <!-- W grid -->
+
+      <field_group id="grid_W" grid_ref="grid_W_3D">
+        <field id="e3w"          long_name="W-cell thickness"                     standard_name="cell_thickness"              unit="m"    />
+        <field id="woce"         long_name="ocean vertical velocity"              standard_name="upward_sea_water_velocity"   unit="m/s"  />
+        <field id="wocetr_eff"   long_name="effective ocean vertical transport"                                               unit="m3/s" />
+
+        <!-- woce_eiv: available with key_traldf_eiv and key_diaeiv -->
+        <field id="woce_eiv"     long_name="EIV ocean vertical velocity"   standard_name="bolus_upward_sea_water_velocity"   unit="m/s" />
+        <field id="weiv_masstr"  long_name="EIV Upward Ocean Mass Transport"  standard_name="bolus_upward_ocean_mass_transport"             unit="kg/s"   />
+        <field id="weiv_heattr3d" long_name="ocean bolus heat transport along k-axis"    standard_name="ocean_heat_z_transport_due_to_bolus_advection"   unit="W" />
+        <field id="weiv_salttr3d" long_name="ocean bolus salt transport along k-axis"    standard_name="ocean_salt_z_transport_due_to_bolus_advection"   unit="kg"   grid_ref="grid_U_3D" />
+
+        <field id="avt"          long_name="vertical eddy diffusivity"   standard_name="ocean_vertical_heat_diffusivity"       unit="m2/s" />
+        <field id="logavt"       long_name="logarithm of vertical eddy diffusivity"   standard_name="ocean_vertical_heat_diffusivity"       unit="m2/s" />
+        <field id="avm"          long_name="vertical eddy viscosity"     standard_name="ocean_vertical_momentum_diffusivity"   unit="m2/s" />
+
+        <!-- avs: available with key_zdfddm -->
+        <field id="avs"          long_name="salt vertical eddy diffusivity"   standard_name="ocean_vertical_salt_diffusivity"   unit="m2/s" />
+        <field id="logavs"       long_name="logarithm of salt vertical eddy diffusivity"   standard_name="ocean_vertical_heat_diffusivity"       unit="m2/s" />
+
+        <!-- avt_evd and avm_evd: available with ln_zdfevd -->
+        <field id="avt_evd"      long_name="convective enhancement to vertical diffusivity"   standard_name="ocean_vertical_tracer_diffusivity_due_to_convection"     unit="m2/s" />
+        <field id="avm_evd"      long_name="convective enhancement to vertical viscosity"     standard_name="ocean_vertical_momentum_diffusivity_due_to_convection"   unit="m2/s" />
+
+        <!-- avt_tide: available with key_zdftmx -->
+        <field id="av_tide"      long_name="tidal vertical diffusivity"   standard_name="ocean_vertical_tracer_diffusivity_due_to_tides"   unit="m2/s" />
+
+       <!-- variables available with key_zdftmx_new -->
+        <field id="av_ratio"     long_name="S over T diffusivity ratio"            standard_name="salinity_over_temperature_diffusivity_ratio"                     unit="1"    />
+        <field id="av_wave"      long_name="wave-induced vertical diffusivity"     standard_name="ocean_vertical_tracer_diffusivity_due_to_internal_waves"         unit="m2/s" />
+        <field id="bflx_tmx"     long_name="wave-induced buoyancy flux"            standard_name="buoyancy_flux_due_to_internal_waves"                             unit="W/kg" />
+        <field id="pcmap_tmx"    long_name="power consumed by wave-driven mixing"  standard_name="vertically_integrated_power_consumption_by_wave_driven_mixing"   unit="W/m2"      grid_ref="grid_W_2D" />
+        <field id="emix_tmx"     long_name="power density available for mixing"    standard_name="power_available_for_mixing_from_breaking_internal_waves"         unit="W/kg" />
+
+        <!-- variables available with key_diaar5 -->
+        <field id="w_masstr"     long_name="Upward Ocean Mass Transport"             standard_name="upward_ocean_mass_transport"             unit="kg/s"   />
+        <field id="w_masstr2"    long_name="square of vertical mass transport"   standard_name="square_of_upward_ocean_mass_transport"   unit="kg2/s2" />
+
+        <!-- aht2d and  aht2d_eiv: available with key_traldf_eiv and key_traldf_c2d -->
+        <field id="aht2d"        long_name="lateral eddy diffusivity"       standard_name="ocean_tracer_xy_laplacian_diffusivity"      unit="m2/s"   grid_ref="grid_W_2D" />
+        <field id="aht2d_eiv"    long_name="EIV lateral eddy diffusivity"   standard_name="ocean_tracer_bolus_laplacian_diffusivity"   unit="m2/s"   grid_ref="grid_W_2D" />
+        <!-- variables added for nn_etau revision testing -->
+        <field id="htau"         long_name="e-decay length scale of nn_etau TKE"       unit="m"        grid_ref="grid_W_2D" />
+        <field id="tke"          long_name="Turbulent Kinetic Energy"                  unit="m2/s2"    />
+        <field id="tke_niw"      long_name="Turbulent Kinetic Energy due to near-inertial wave breaking"  unit="m2/s2" />
+
+         <!-- Variable from eosbn2 -->
+         <field id="bn2"          long_name="Squared buoyancy frequency measuring ocean vertical stratification"        standard_name="square_of_brunt_vaisala_frequency_in_sea_water"   unit="1/s^2"  />
+      </field_group>
+
+      <!-- product fields -->
+      <field_group id="diaprod">
+        <field id="ut"           long_name="product_of_sea_water_x_velocity_and_potential_temperature"      unit="degree_C m/s"      grid_ref="grid_U_3D"   />
+        <field id="ut_e3u"       long_name="product_of_sea_water_x_velocity_and_potential_temperature * e3u"  unit="degree_C m2/s"   grid_ref="grid_U_3D" > ut * e3u </field >
+        <field id="us"           long_name="product_of_sea_water_x_velocity_and_salinity"                   unit="PSU m/s"       grid_ref="grid_U_3D"   />
+        <field id="us_e3u"       long_name="product_of_sea_water_x_velocity_and_salinity * e3u"             unit="PSU m2/s"      grid_ref="grid_U_3D" > us * e3u </field >
+        <field id="urhop"        long_name="product_of_sea_water_x_velocity_and_potential_density"          unit="(kg/m3).(m/s)" grid_ref="grid_U_3D"   />
+        <field id="urhop_e3u"    long_name="product_of_sea_water_x_velocity_and_potential_density * e3u"    unit="(kg/m3).(m2/s)"   grid_ref="grid_U_3D" > urhop * e3u </field >
+        <field id="vt"           long_name="product_of_sea_water_y_velocity_and_potential_temperature"      unit="degree_C m/s"      grid_ref="grid_V_3D"   />
+        <field id="vt_e3v"       long_name="product_of_sea_water_y_velocity_and_potential_temperature * e3v"  unit="degree_C m2/s"   grid_ref="grid_V_3D" > vt * e3v </field >
+        <field id="vs"           long_name="product_of_sea_water_y_velocity_and_salinity"                   unit="PSU m/s"       grid_ref="grid_V_3D"   />
+        <field id="vs_e3v"       long_name="product_of_sea_water_y_velocity_and_salinity * e3t"             unit="PSU m2/s"      grid_ref="grid_V_3D" > vs * e3v </field >
+        <field id="vrhop"        long_name="product_of_sea_water_y_velocity_and_potential_density"          unit="(kg/m3).(m/s)" grid_ref="grid_V_3D"   />
+        <field id="vrhop_e3v"    long_name="product_of_sea_water_y_velocity_and_potential_density * e3t"    unit="(kg/m3).(m2/s)"  grid_ref="grid_V_3D" > vrhop * e3v </field >
+        <field id="wt"           long_name="product_of_upward_sea_water_velocity_and_potential_temperature" unit="degree_C m/s"      grid_ref="grid_W_3D"   />
+        <field id="ws"           long_name="product_of_upward_sea_water_velocity_and_salinity"              unit="PSU m/s"       grid_ref="grid_W_3D"   />
+        <field id="wrhop"        long_name="product_of_upward_sea_water_velocity_and_potential_density"     unit="(kg/m3).(m/s)" grid_ref="grid_W_3D"   />
+      </field_group>
+
+      <!-- scalar variables available with key_diaar5 -->
+
+      <field_group id="scalar"  domain_ref="1point" >
+         <field id="voltot"     long_name="Sea Water Volume"                             standard_name="sea_water_volume"                               unit="m3"   />
+         <field id="sshtot"     long_name="global mean ssh"                              standard_name="global_average_sea_level_change"                unit="m"    />
+         <field id="sshsteric"  long_name="global mean ssh steric"                       standard_name="global_average_steric_sea_level_change"         unit="m"    />
+         <field id="sshthster"  long_name="Global Average Thermosteric Sea Level Change" standard_name="global_average_thermosteric_sea_level_change"   unit="m"    />
+         <field id="masstot"    long_name="global total mass"                            standard_name="sea_water_mass"                                 unit="kg"   />
+         <field id="temptot"    long_name="Global Average Sea Water Potential Temperature"      standard_name="sea_water_potential_temperature"         unit="degree_C" />
+         <field id="saltot"     long_name="Global Average Sea Water Salinity"                   standard_name="sea_water_salinity"                      unit="0.001" />
+         <field id="fram_trans" long_name="Sea Ice Mass Transport Through Fram Strait"   standard_name="sea_ice_transport_across_line"                  unit="kg/s" />
+
+         <!-- available with ln_diahsb -->
+         <field id="bgtemper"     long_name="drift in global mean temperature wrt timestep 1"                 standard_name="change_over_time_in_sea_water_potential_temperature"   unit="degree_C"     />
+         <field id="bgsaline"     long_name="drift in global mean salinity wrt timestep 1"                    standard_name="change_over_time_in_sea_water_practical_salinity"      unit="0.001"     />
+         <field id="bgheatco"     long_name="drift in global mean heat content wrt timestep 1"                                                                                      unit="10^9J"    />
+         <field id="bgsaltco"     long_name="drift in global mean salt content wrt timestep 1"                                                                                      unit="0.001*m3"  />
+         <field id="bgvolssh"     long_name="drift in global mean ssh volume wrt timestep 1"                                                                                        unit="km3"      />
+         <field id="bgvole3t"     long_name="drift in global mean volume variation (e3t) wrt timestep 1"                                                                            unit="km3"      />
+         <field id="bgvoltot"     long_name="drift in global mean volume wrt timestep 1"                                                                                            unit="km3"      />
+         <!-- NOTE: No matching iom_put call -->
+         <field id="bgsshtot"     long_name="drift in global mean ssh wrt timestep 1"                         standard_name="global_average_sea_level_change"                       unit="m"        />
+         <field id="bgfrcvol"     long_name="drift in global mean volume from forcing wrt timestep 1"                                                                               unit="km3"      />
+         <field id="bgfrctem"     long_name="drift in global mean heat content from forcing wrt timestep 1"                                                                         unit="10^9J"    />
+         <field id="bgfrcsal"     long_name="drift in global mean salt content from forcing wrt timestep 1"                                                                         unit="0.001*km3" />
+         <field id="bgmistem"     long_name="global mean temperature error due to free surface"                                                                                     unit="degree_C"     />
+         <field id="bgmissal"     long_name="global mean salinity error due to free surface"                                                                                        unit="0.001"     />
+      </field_group>
+
+      <!-- LIM3 scalar variables -->
+
+      <field_group id="SBC_scalar"  domain_ref="1point" >
+         <!-- available with ln_limdiaout -->
+         <field id="ibgvoltot"    long_name="global mean ice volume"                                 unit="km3"        />
+         <field id="sbgvoltot"    long_name="global mean snow volume"                                unit="km3"        />
+         <field id="ibgarea"      long_name="global mean ice area"                                   unit="km2"        />
+         <field id="ibgsaline"    long_name="global mean ice salinity"                               unit="0.001"       />
+         <field id="ibgtemper"    long_name="global mean ice temperature"                            unit="degree_C"       />
+         <field id="ibgheatco"    long_name="global mean ice heat content"                           unit="10^20J"     />
+         <field id="sbgheatco"    long_name="global mean snow heat content"                          unit="10^20J"     />
+         <field id="ibgsaltco"    long_name="global mean ice salt content"                           unit="0.001*km3"   />
+
+         <field id="ibgvfx"       long_name="global mean volume flux (emp)"                          unit="m/day"      />
+         <field id="ibgvfxbog"    long_name="global mean volume flux (bottom growth)"                unit="m/day"      />
+         <field id="ibgvfxopw"    long_name="global mean volume flux (open water growth)"            unit="m/day"      />
+         <field id="ibgvfxsni"    long_name="global mean volume flux (snow-ice growth)"              unit="m/day"      />
+         <field id="ibgvfxdyn"    long_name="global mean volume flux (dynamic growth)"               unit="m/day"      />
+         <field id="ibgvfxbom"    long_name="global mean volume flux (bottom melt)"                  unit="m/day"      />
+         <field id="ibgvfxsum"    long_name="global mean volume flux (surface melt)"                 unit="m/day"      />
+         <field id="ibgvfxres"    long_name="global mean volume flux (resultant)"                    unit="m/day"      />
+         <field id="ibgvfxspr"    long_name="global mean volume flux (snow precip)"                  unit="m/day"      />
+         <field id="ibgvfxsnw"    long_name="global mean volume flux (snow melt)"                    unit="m/day"      />
+         <field id="ibgvfxsub"    long_name="global mean volume flux (snow sublimation)"             unit="m/day"      />
+
+         <field id="ibgsfx"       long_name="global mean salt flux (total)"                          unit="0.001*m/day" />
+         <field id="ibgsfxbri"    long_name="global mean salt flux (brines)"                         unit="0.001*m/day" />
+         <field id="ibgsfxdyn"    long_name="global mean salt flux (dynamic)"                        unit="0.001*m/day" />
+         <field id="ibgsfxres"    long_name="global mean salt flux (resultant)"                      unit="0.001*m/day" />
+         <field id="ibgsfxbog"    long_name="global mean salt flux (thermo)"                         unit="0.001*m/day" />
+         <field id="ibgsfxopw"    long_name="global mean salt flux (thermo)"                         unit="0.001*m/day" />
+         <field id="ibgsfxsni"    long_name="global mean salt flux (thermo)"                         unit="0.001*m/day" />
+         <field id="ibgsfxbom"    long_name="global mean salt flux (thermo)"                         unit="0.001*m/day" />
+         <field id="ibgsfxsum"    long_name="global mean salt flux (thermo)"                         unit="0.001*m/day" />
+         <field id="ibgsfxsub"    long_name="global mean salt flux (thermo)"                         unit="0.001*m/day" />
+
+         <field id="ibghfxdhc"    long_name="Heat content variation in snow and ice"                 unit="W"          />
+         <field id="ibghfxspr"    long_name="Heat content of snow precip"                            unit="W"          />
+
+         <field id="ibghfxthd"    long_name="heat fluxes from ice-ocean exchange during thermo"      unit="W"          />
+         <field id="ibghfxsum"    long_name="heat fluxes causing surface ice melt"                   unit="W"          />
+         <field id="ibghfxbom"    long_name="heat fluxes causing bottom ice melt"                    unit="W"          />
+         <field id="ibghfxbog"    long_name="heat fluxes causing bottom ice growth"                  unit="W"          />
+         <field id="ibghfxdif"    long_name="heat fluxes causing ice temperature change"             unit="W"          />
+         <field id="ibghfxopw"    long_name="heat fluxes causing open water ice formation"           unit="W"          />
+         <field id="ibghfxdyn"    long_name="heat fluxes from ice-ocean exchange during dynamic"     unit="W"          />
+         <field id="ibghfxres"    long_name="heat fluxes from ice-ocean exchange during resultant"   unit="W"          />
+         <field id="ibghfxsub"    long_name="heat fluxes from sublimation"                           unit="W"          />
+         <field id="ibghfxsnw"    long_name="heat fluxes from snow-ocean exchange"                   unit="W"          />
+         <field id="ibghfxout"    long_name="non solar heat fluxes received by the ocean"            unit="W"          />
+         <field id="ibghfxin"     long_name="total heat fluxes at the ice surface"                   unit="W"          />
+
+         <field id="ibgfrcvol"    long_name="global mean forcing volume (emp)"                       unit="km3"        />
+         <field id="ibgfrcsfx"    long_name="global mean forcing salt   (sfx)"                       unit="0.001*km3"   />
+         <field id="ibgvolgrm"    long_name="global mean ice growth+melt volume"                     unit="km3"        />
+      </field_group>
+
+      <!-- variables available with key_float -->
+
+      <field_group id="floatvar" domain_ref="1point" axis_ref="nfloat" operation="instant" >
+        <field id="traj_lon"      long_name="floats longitude"                                                           unit="degrees_east"  />
+        <field id="traj_lat"      long_name="floats latitude"                                                            unit="degrees_north" />
+        <field id="traj_dep"      long_name="floats depth"                                                               unit="m"             />
+        <field id="traj_temp"     long_name="floats temperature"       standard_name="sea_water_potential_temperature"   unit="degree_C"          />
+        <field id="traj_salt"     long_name="floats salinity"          standard_name="sea_water_practical_salinity"      unit="0.001"          />
+        <field id="traj_dens"     long_name="floats in-situ density"   standard_name="sea_water_density"                 unit="kg/m3"         />
+        <field id="traj_group"    long_name="floats group"                                                               unit="1"             />
+      </field_group>
+
+      <!-- variables available with iceberg trajectories -->
+
+      <field_group id="icbvar" grid_ref="grid_T_2D"  >
+        <field id="berg_total_melt"    long_name="icb melt rate 2 of icebergs"                     unit="kg/m2/s"                    />
+        <field id="berg_total_heat_flux"  long_name="icb latent heat of melting of icebergs"          unit="kg/m2/s"                    />
+        <field id="berg_melt"          long_name="icb melt rate of icebergs"                       unit="kg/m2/s"                    />
+        <field id="berg_buoy_melt"     long_name="icb buoyancy component of iceberg melt rate"     unit="kg/m2/s"                    />
+        <field id="berg_eros_melt"     long_name="icb erosion component of iceberg melt rate"      unit="kg/m2/s"                    />
+        <field id="berg_conv_melt"     long_name="icb convective component of iceberg melt rate"   unit="kg/m2/s"                    />
+        <field id="berg_virtual_area"  long_name="icb virtual coverage by icebergs"                unit="m2"                         />
+        <field id="bits_src"           long_name="icb mass source of bergy bits"                   unit="kg/m2/s"                    />
+        <field id="bits_melt"          long_name="icb melt rate of bergy bits"                     unit="kg/m2/s"                    />
+        <field id="bits_mass"          long_name="icb bergy bit density field"                     unit="kg/m2"                      />
+        <field id="berg_mass"          long_name="icb iceberg density field"                       unit="kg/m2"                      />
+        <field id="calving"            long_name="icb calving mass input"                          unit="kg/s"                       />
+        <field id="berg_floating_melt" long_name="icb melt rate of icebergs + bits"                unit="kg/m2/s"                    />
+        <field id="berg_real_calving"  long_name="icb calving into iceberg class"                  unit="kg/s"     axis_ref="icbcla" />
+        <field id="berg_stored_ice"    long_name="icb accumulated ice mass by class"               unit="kg"       axis_ref="icbcla" />
+      </field_group>
+
+      <!-- Poleward transport : ptr -->
+      <field_group id="diaptr">
+        <field id="zomsfglo"          long_name="Meridional Stream-Function: Global"           unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfatl"          long_name="Meridional Stream-Function: Atlantic"         unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfpac"          long_name="Meridional Stream-Function: Pacific"          unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfind"          long_name="Meridional Stream-Function: Indian"           unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfipc"          long_name="Meridional Stream-Function: Pacific+Indian"   unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zotemglo"          long_name="Zonal Mean Temperature : Global"              unit="degree_C"     grid_ref="gznl_T_3D" />
+        <field id="zotematl"          long_name="Zonal Mean Temperature : Atlantic"            unit="degree_C"     grid_ref="gznl_T_3D" />
+        <field id="zotempac"          long_name="Zonal Mean Temperature : Pacific"             unit="degree_C"     grid_ref="gznl_T_3D" />
+        <field id="zotemind"          long_name="Zonal Mean Temperature : Indian"              unit="degree_C"     grid_ref="gznl_T_3D" />
+        <field id="zotemipc"          long_name="Zonal Mean Temperature : Pacific+Indian"      unit="degree_C"     grid_ref="gznl_T_3D" />
+        <field id="zosalglo"          long_name="Zonal Mean Salinity : Global"                 unit="0.001"     grid_ref="gznl_T_3D" />
+        <field id="zosalatl"          long_name="Zonal Mean Salinity : Atlantic"               unit="0.001"     grid_ref="gznl_T_3D" />
+        <field id="zosalpac"          long_name="Zonal Mean Salinity : Pacific"                unit="0.001"     grid_ref="gznl_T_3D" />
+        <field id="zosalind"          long_name="Zonal Mean Salinity : Indian"                 unit="0.001"     grid_ref="gznl_T_3D" />
+        <field id="zosalipc"          long_name="Zonal Mean Salinity : Pacific+Indian"         unit="0.001"     grid_ref="gznl_T_3D" />
+        <field id="zosrfglo"          long_name="Zonal Mean Surface"                           unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfatl"          long_name="Zonal Mean Surface : Atlantic"                unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfpac"          long_name="Zonal Mean Surface : Pacific"                 unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfind"          long_name="Zonal Mean Surface : Indian"                  unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfipc"          long_name="Zonal Mean Surface : Pacific+Indian"          unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="sophtadv"          long_name="Advective Heat Transport"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtadv_atl"      long_name="Advective Heat Transport: Atlantic"           unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtadv_pac"      long_name="Advective Heat Transport: Pacific"            unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtadv_ind"      long_name="Advective Heat Transport: Indian"             unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtadv_ipc"      long_name="Advective Heat Transport: Pacific+Indian"     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtldf"          long_name="Diffusive Heat Transport"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtldf_atl"      long_name="Diffusive Heat Transport: Atlantic"           unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtldf_pac"      long_name="Diffusive Heat Transport: Pacific"            unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtldf_ind"      long_name="Diffusive Heat Transport: Indian"             unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtldf_ipc"      long_name="Diffusive Heat Transport: Pacific+Indian"     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtove"          long_name="Overturning Heat Transport"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtove_atl"      long_name="Overturning Heat Transport: Atlantic"           unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtove_pac"      long_name="Overturning Heat Transport: Pacific"            unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtove_ind"      long_name="Overturning Heat Transport: Indian"             unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtove_ipc"      long_name="Overturning Heat Transport: Pacific+Indian"     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtbtr"          long_name="Barotropic Heat Transport"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtbtr_atl"      long_name="Barotropic Heat Transport: Atlantic"           unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtbtr_pac"      long_name="Barotropic Heat Transport: Pacific"            unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtbtr_ind"      long_name="Barotropic Heat Transport: Indian"             unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtbtr_ipc"      long_name="Barotropic Heat Transport: Pacific+Indian"     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophteiv"          long_name="Heat Transport from mesoscale eddy oveection"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophteiv_atl"      long_name="Heat Transport from mesoscale eddy advection: Atlantic"           unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophteiv_pac"      long_name="Heat Transport from mesoscale eddy advection: Pacific"            unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophteiv_ind"      long_name="Heat Transport from mesoscale eddy advection: Indian"             unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophteiv_ipc"      long_name="Heat Transport from mesoscale eddy advection: Pacific+Indian"     unit="PW"       grid_ref="gznl_T_2D" />
+       <field id="sopstadv"          long_name="Advective Salt Transport"                     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstadv_atl"      long_name="Advective Salt Transport: Atlantic"           unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstadv_pac"      long_name="Advective Salt Transport: Pacific"            unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstadv_ind"      long_name="Advective Salt Transport: Indian"             unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstadv_ipc"      long_name="Advective Salt Transport: Pacific+Indian"     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstove"          long_name="Overturning Salt Transport"                     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstove_atl"      long_name="Overturning Salt Transport: Atlantic"           unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstove_pac"      long_name="Overturning Salt Transport: Pacific"            unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstove_ind"      long_name="Overturning Salt Transport: Indian"             unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstove_ipc"      long_name="Overturning Salt Transport: Pacific+Indian"     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstbtr"          long_name="Barotropic Salt Transport"                     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstbtr_atl"      long_name="Barotropic Salt Transport: Atlantic"           unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstbtr_pac"      long_name="Barotropic Salt Transport: Pacific"            unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstbtr_ind"      long_name="Barotropic Salt Transport: Indian"             unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstbtr_ipc"      long_name="Barotropic Salt Transport: Pacific+Indian"     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstldf"          long_name="Diffusive Salt Transport"                     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstldf_atl"      long_name="Diffusive Salt Transport: Atlantic"           unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstldf_pac"      long_name="Diffusive Salt Transport: Pacific"            unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstldf_ind"      long_name="Diffusive Salt Transport: Indian"             unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstldf_ipc"      long_name="Diffusive Salt Transport: Pacific+Indian"     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopsteiv"          long_name="Salt Transport from mesoscale eddy advection"                     unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopsteiv_atl"      long_name="Salt Transport from mesoscale eddy advection: Atlantic"           unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopsteiv_pac"      long_name="Salt Transport from mesoscale eddy advection: Pacific"            unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopsteiv_ind"      long_name="Salt Transport from mesoscale eddy advection: Indian"             unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopsteiv_ipc"      long_name="Salt Transport from mesoscale eddy advection: Pacific+Indian"     unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopht_vt"          long_name="Heat Transport"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sopht_vt_atl"      long_name="Heat Transport: Atlantic"           unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sopht_vt_ind"      long_name="Heat Transport: Indian"             unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sopht_vt_pac"      long_name="Heat Transport: Pacific"            unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sopht_vt_ipc"      long_name="Heat Transport: Indo-Pacific"       unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sopst_vs"          long_name="Salt Transport"                     unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopst_vs_atl"      long_name="Salt Transport: Atlantic"           unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopst_vs_ind"      long_name="Salt Transport: Indian"             unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopst_vs_pac"      long_name="Salt Transport: Pacific"            unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="sopst_vs_ipc"      long_name="Salt Transport: Indo-Pacific"       unit="Giga g/s"       grid_ref="gznl_T_2D" />
+        <field id="vsum" grid_ref="gznl_T_2D" unit="none" standard_name="none" />
+        <field id="tmean" grid_ref="gznl_T_2D" unit="none" standard_name="none" />
+        <field id="section_area" grid_ref="gznl_T_2D" unit="none" standard_name="none" />
+      </field_group>
+
+    <!-- 
+         ============================================================================================================
+                  Physical ocean model trend diagnostics : temperature, KE, PE, momentum
+============================================================================================================
+    -->
+
+    <field_group id="trendT" grid_ref="grid_T_3D">
+      <!-- variables available with ln_tra_trd -->
+      <field id="ttrd_xad"      long_name="temperature-trend: i-advection"                                                                                          unit="degC/s"                        />
+      <field id="strd_xad"      long_name="salinity   -trend: i-advection"                                                                                          unit="1e-3/s"                        />
+      <field id="ttrd_yad"      long_name="temperature-trend: j-advection"                                                                                          unit="degC/s"                        />
+      <field id="strd_yad"      long_name="salinity   -trend: j-advection"                                                                                          unit="1e-3/s"                        />
+      <field id="ttrd_zad"      long_name="temperature-trend: k-advection"                                                                                          unit="degC/s"                        />
+      <field id="strd_zad"      long_name="salinity   -trend: k-advection"                                                                                          unit="1e-3/s"                        />
+      <field id="ttrd_ad"       long_name="temperature-trend: advection"               standard_name="tendency_of_sea_water_temperature_due_to_advection"           unit="degC/s"                         > sqrt( ttrd_xad^2 + ttrd_yad^2 + ttrd_zad^2 ) </field>
+      <field id="strd_ad"       long_name="salinity   -trend: advection"               standard_name="tendency_of_sea_water_salinity_due_to_advection"              unit="1e-3/s"                         > sqrt( strd_xad^2 + strd_yad^2 + strd_zad^2 ) </field>
+      <field id="ttrd_totad"    long_name="temperature-trend: total advection"         standard_name="tendency_of_sea_water_salinity_due_to_advection"              unit="degC/s"                        />
+      <field id="strd_totad"    long_name="salinity   -trend: total advection"         standard_name="tendency_of_sea_water_salinity_due_to_advection"              unit="1e-3/s"                        />
+      <field id="ttrd_sad"      long_name="temperature-trend: surface adv. (no-vvl)"                                                                                unit="degC/s"   grid_ref="grid_T_2D" />
+      <field id="strd_sad"      long_name="salinity   -trend: surface adv. (no-vvl)"                                                                                unit="1e-3/s"   grid_ref="grid_T_2D" />
+      <field id="ttrd_ldf"      long_name="temperature-trend: lateral  diffusion"      standard_name="tendency_of_sea_water_temperature_due_to_horizontal_mixing"   unit="degC/s"                        />
+      <field id="strd_ldf"      long_name="salinity   -trend: lateral  diffusion"      standard_name="tendency_of_sea_water_salinity_due_to_horizontal_mixing"      unit="1e-3/s"                        />
+      <field id="ttrd_zdf"      long_name="temperature-trend: vertical diffusion"      standard_name="tendency_of_sea_water_temperature_due_to_vertical_mixing"     unit="degC/s"                        />
+      <field id="strd_zdf"      long_name="salinity   -trend: vertical diffusion"      standard_name="tendency_of_sea_water_salinity_due_to_vertical_mixing"        unit="1e-3/s"                        />
+      <field id="ttrd_evd"      long_name="temperature-trend: EVD convection"                                                                                       unit="degC/s"                        />
+      <field id="strd_evd"      long_name="salinity   -trend: EVD convection"                                                                                       unit="1e-3/s"                        />
+
+      <!-- ln_traldf_iso=T only (iso-neutral diffusion) -->
+      <field id="ttrd_iso_x"    long_name="temperature-trend: isopycnal diffusion x-component"                                                                      unit="degC/s"                        />
+      <field id="strd_iso_x"    long_name="salinity   -trend: isopycnal diffusion x-component"                                                                      unit="1e-3/s"                        />
+      <field id="ttrd_iso_y"    long_name="temperature-trend: isopycnal diffusion y-component"                                                                      unit="degC/s"                        />
+      <field id="strd_iso_y"    long_name="salinity   -trend: isopycnal diffusion y-component"                                                                      unit="1e-3/s"                        />
+      <field id="ttrd_iso_z1"   long_name="temperature-trend: isopycnal diffusion z-component part 1"                                                               unit="degC/s"                        />
+      <field id="strd_iso_z1"   long_name="salinity   -trend: isopycnal diffusion z-component part 1"                                                               unit="1e-3/s"                        />
+      <field id="ttrd_iso_z"    long_name="temperature-trend: isopycnal diffusion z-component"                 unit="degC/s" > ttrd_iso_z1 + ttrd_zdf - ttrd_zdfp </field>
+      <field id="strd_iso_z"    long_name="salinity   -trend: isopycnal diffusion z-component"                 unit="1e-3/s" > strd_iso_z1 + strd_zdf - strd_zdfp </field>
+      <field id="ttrd_iso"      long_name="temperature-trend: isopycnal diffusion"                             unit="degC/s" > ttrd_ldf + ttrd_zdf - ttrd_zdfp </field>
+      <field id="strd_iso"      long_name="salinity   -trend: isopycnal diffusion"                             unit="1e-3/s" > strd_ldf + strd_zdf - strd_zdfp </field>
+      <field id="ttrd_zdfp"     long_name="temperature-trend: pure vert. diffusion"   unit="degC/s" />
+      <field id="strd_zdfp"     long_name="salinity   -trend: pure vert. diffusion"   unit="1e-3/s" />
+
+      <!-- -->
+      <field id="ttrd_dmp"      long_name="temperature-trend: interior restoring"        unit="degree_C/s" />
+      <field id="strd_dmp"      long_name="salinity   -trend: interior restoring"        unit="0.001/s" />
+      <field id="ttrd_bbl"      long_name="temperature-trend: bottom boundary layer"     unit="degree_C/s" />
+      <field id="strd_bbl"      long_name="salinity   -trend: bottom boundary layer"     unit="0.001/s" />
+      <field id="ttrd_npc"      long_name="temperature-trend: non-penetrative conv."     unit="degree_C/s" />
+      <field id="strd_npc"      long_name="salinity   -trend: non-penetrative conv."     unit="0.001/s" />
+      <field id="ttrd_qns"      long_name="temperature-trend: non-solar flux + runoff"   unit="degC/s" grid_ref="grid_T_2D"/>
+      <field id="strd_cdt"      long_name="salinity   -trend: C/D term       + runoff"   unit="degC/s" grid_ref="grid_T_2D"/>
+      <field id="ttrd_qsr"      long_name="temperature-trend: solar penetr. heating"     unit="degree_C/s" />
+      <field id="ttrd_bbc"      long_name="temperature-trend: geothermal heating"        unit="degree_C/s" />
+      <field id="ttrd_atf"      long_name="temperature-trend: asselin time filter"       unit="degree_C/s" />
+      <field id="strd_atf"      long_name="salinity   -trend: asselin time filter"       unit="0.001/s" />
+      <field id="ttrd_tot"      long_name="temperature-trend: total model trend"         unit="degC/s" />
+      <field id="strd_tot"      long_name="salinity   -trend: total model trend"         unit="1e-3/s" />
+
+      <!-- Thickness weighted versions: -->
+      <field id="ttrd_xad_e3t"      unit="degC/s * m" >  ttrd_xad * e3t </field>
+      <field id="strd_xad_e3t"      unit="1e-3/s * m" >  strd_xad * e3t </field>
+      <field id="ttrd_yad_e3t"      unit="degC/s * m" >  ttrd_yad * e3t </field>
+      <field id="strd_yad_e3t"      unit="1e-3/s * m" >  strd_yad * e3t </field>
+      <field id="ttrd_zad_e3t"      unit="degC/s * m" >  ttrd_zad * e3t </field>
+      <field id="strd_zad_e3t"      unit="1e-3/s * m" >  strd_zad * e3t </field>
+      <field id="ttrd_ad_e3t"       unit="degC/s * m" >  ttrd_ad  * e3t </field>
+      <field id="strd_ad_e3t"       unit="1e-3/s * m" >  strd_ad  * e3t </field>
+      <field id="ttrd_totad_e3t"    unit="degC/s * m" >  ttrd_totad  * e3t </field>
+      <field id="strd_totad_e3t"    unit="1e-3/s * m" >  strd_totad  * e3t </field>
+      <field id="ttrd_ldf_e3t"      unit="degC/s * m" >  ttrd_ldf * e3t </field>
+      <field id="strd_ldf_e3t"      unit="1e-3/s * m" >  strd_ldf * e3t </field>
+      <field id="ttrd_zdf_e3t"      unit="degC/s * m" >  ttrd_zdf * e3t </field>
+      <field id="strd_zdf_e3t"      unit="1e-3/s * m" >  strd_zdf * e3t </field>
+      <field id="ttrd_evd_e3t"      unit="degC/s * m" >  ttrd_evd * e3t </field>
+      <field id="strd_evd_e3t"      unit="1e-3/s * m" >  strd_evd * e3t </field>
+
+      <!-- ln_traldf_iso=T only (iso-neutral diffusion) -->
+      <field id="ttrd_iso_x_e3t"    unit="degC/s * m"  >  ttrd_iso_x * e3t </field>
+      <field id="strd_iso_x_e3t"    unit="1e-3/s * m"  >  strd_iso_x * e3t </field>
+      <field id="ttrd_iso_y_e3t"    unit="degC/s * m"  >  ttrd_iso_y * e3t </field>
+      <field id="strd_iso_y_e3t"    unit="1e-3/s * m"  >  strd_iso_y * e3t </field>
+      <field id="ttrd_iso_z_e3t"    unit="degC/s * m"  >  ttrd_iso_z * e3t </field>
+      <field id="strd_iso_z_e3t"    unit="1e-3/s * m"  >  strd_iso_z * e3t </field>
+      <field id="ttrd_iso_e3t"      unit="degC/s * m"  >  ttrd_iso * e3t </field>
+      <field id="strd_iso_e3t"      unit="1e-3/s * m"  >  strd_iso * e3t </field>
+      <field id="ttrd_zdfp_e3t"     unit="degC/s * m"  >  ttrd_zdfp * e3t </field>
+      <field id="strd_zdfp_e3t"     unit="1e-3/s * m"  >  strd_zdfp * e3t </field>
+
+      <!-- -->
+      <field id="ttrd_dmp_e3t"      unit="degC/s * m"  >  ttrd_dmp * e3t </field>
+      <field id="strd_dmp_e3t"      unit="1e-3/s * m"  >  strd_dmp * e3t </field>
+      <field id="ttrd_bbl_e3t"      unit="degC/s * m"  >  ttrd_bbl * e3t </field>
+      <field id="strd_bbl_e3t"      unit="1e-3/s * m"  >  strd_bbl * e3t </field>
+      <field id="ttrd_npc_e3t"      unit="degC/s * m"  >  ttrd_npc * e3t </field>
+      <field id="strd_npc_e3t"      unit="1e-3/s * m"  >  strd_npc * e3t </field>
+      <field id="ttrd_qns_e3t"      unit="degC/s * m"  >  ttrd_qns * e3t_surf </field>
+      <field id="strd_cdt_e3t"      unit="degC/s * m"  >  strd_cdt * e3t_surf </field>
+      <field id="ttrd_qsr_e3t"      unit="degC/s * m"  >  ttrd_qsr * e3t </field>
+      <field id="ttrd_bbc_e3t"      unit="degC/s * m"  >  ttrd_bbc * e3t </field>
+      <field id="ttrd_atf_e3t"      unit="degC/s * m"  >  ttrd_atf * e3t </field>
+      <field id="strd_atf_e3t"      unit="1e-3/s * m"  >  strd_atf * e3t </field>
+      <field id="ttrd_tot_e3t"      unit="degC/s * m"  >  ttrd_tot * e3t </field>
+      <field id="strd_tot_e3t"      unit="1e-3/s * m"  >  strd_tot * e3t </field>
+
+      <!-- variables available with ln_KE_trd -->
+      <field id="ketrd_hpg"     long_name="ke-trend: hydrostatic pressure gradient"          unit="W/s^3"                        />
+      <field id="ketrd_spg"     long_name="ke-trend: surface     pressure gradient"          unit="W/s^3"                        />
+      <field id="ketrd_spgexp"  long_name="ke-trend: surface pressure gradient (explicit)"   unit="W/s^3"                        />
+      <field id="ketrd_spgflt"  long_name="ke-trend: surface pressure gradient (filter)"     unit="W/s^3"                        />
+      <field id="ssh_flt"       long_name="filtered contribution to ssh (dynspg_flt)"        unit="m"       grid_ref="grid_T_2D" />
+      <field id="w0"            long_name="surface vertical velocity"                        unit="m/s"     grid_ref="grid_T_2D" />
+      <field id="pw0_exp"       long_name="surface pressure flux due to ssh"                 unit="W/s^2"   grid_ref="grid_T_2D" />
+      <field id="pw0_flt"       long_name="surface pressure flux due to filtered ssh"        unit="W/s^2"   grid_ref="grid_T_2D" />
+      <field id="ketrd_keg"     long_name="ke-trend: KE gradient         or hor. adv."       unit="W/s^3"                        />
+      <field id="ketrd_rvo"     long_name="ke-trend: relative  vorticity or metric term"     unit="W/s^3"                        />
+      <field id="ketrd_pvo"     long_name="ke-trend: planetary vorticity"                    unit="W/s^3"                        />
+      <field id="ketrd_zad"     long_name="ke-trend: vertical  advection"                    unit="W/s^3"                        />
+      <field id="ketrd_udx"     long_name="ke-trend: U.dx[U]"                                unit="W/s^3"                        />
+      <field id="ketrd_ldf"     long_name="ke-trend: lateral   diffusion"                    unit="W/m^3"                        />
+      <field id="ketrd_ldf_e3t" field_ref="ketrd_ldf" long_name="ke-trend: lateral   diffusion * e3t" unit="W/m^2" >ketrd_ldf*e3t</field>
+      <field id="ketrd_ldf_vsum" field_ref="ketrd_ldf_e3t" long_name="ke-trend: lateral diffusion vertical integral" unit="W/m^2" grid_ref="vert_sum" />
+      <field id="ketrd_zdf"     long_name="ke-trend: vertical  diffusion"                    unit="W/s^3"                        />
+      <field id="ketrd_tau"     long_name="ke-trend: wind stress "                           unit="W/s^3"   grid_ref="grid_T_2D" />
+      <field id="ketrd_bfr"     long_name="ke-trend: bottom friction (explicit)"             unit="W/s^3"                        />
+      <field id="ketrd_bfri"    long_name="ke-trend: bottom friction (implicit)"             unit="W/s^3"                        />
+      <field id="ketrd_atf"     long_name="ke-trend: asselin time filter trend"              unit="W/s^3"                        />
+      <field id="ketrd_convP2K" long_name="ke-trend: conversion (potential to kinetic)"      unit="W/s^3"                        />
+      <field id="KE"            long_name="kinetic energy: u(n)*u(n+1)/2"                    unit="W/s^2"                        />
+      <field id="ketrd_eiv"     long_name="Kinetic energy trend from mesoscale eddy advection"   unit="W/s^2" grid_ref="grid_T_2D" />
+
+      <!-- variables available with ln_PE_trd -->
+      <field id="petrd_xad"     long_name="pe-trend: i-advection"                unit="W/m^3"                        />
+      <field id="petrd_yad"     long_name="pe-trend: j-advection"                unit="W/m^3"                        />
+      <field id="petrd_zad"     long_name="pe-trend: k-advection"                unit="W/m^3"                        />
+      <field id="petrd_sad"     long_name="pe-trend: surface adv. (no-vvl)"      unit="W/m^3"   grid_ref="grid_T_2D" />
+      <field id="petrd_ldf"     long_name="pe-trend: lateral  diffusion"         unit="W/m^3"                        />
+      <field id="petrd_zdf"     long_name="pe-trend: vertical diffusion"         unit="W/m^3"                        />
+      <field id="petrd_zdfp"    long_name="pe-trend: pure vert. diffusion"       unit="W/m^3"                        />
+      <field id="petrd_dmp"     long_name="pe-trend: interior restoring"         unit="W/m^3"                        />
+      <field id="petrd_bbl"     long_name="pe-trend: bottom boundary layer"      unit="W/m^3"                        />
+      <field id="petrd_npc"     long_name="pe-trend: non-penetrative conv."      unit="W/m^3"                        />
+      <field id="petrd_nsr"     long_name="pe-trend: surface forcing + runoff"   unit="W/m^3"                        />
+      <field id="petrd_qsr"     long_name="pe-trend: solar penetr. heating"      unit="W/m^3"                        />
+      <field id="petrd_bbc"     long_name="pe-trend: geothermal heating"         unit="W/m^3"                        />
+      <field id="petrd_atf"     long_name="pe-trend: asselin time filter"        unit="W/m^3"                        />
+      <field id="PEanom"        long_name="potential energy anomaly"             unit="1"                            />
+      <field id="alphaPE"       long_name="partial deriv. of PEanom wrt T"       unit="degree_C-1"                       />
+      <field id="betaPE"        long_name="partial deriv. of PEanom wrt S"       unit="1e3"                          />
+      <field id="petrd_zdfp_e3t"    unit="W/m^2" grid_ref="grid_T_3D"  > petrd_zdfp * e3t </field>
+      <field id="petrd_2d" field_ref="petrd_zdfp_e3t" grid_ref="vert_sum" />
+    </field_group>
+
+    <field_group id="trendU" grid_ref="grid_U_3D">
+     <!-- variables available with ln_dyn_trd -->
+     <field id="utrd_hpg"       long_name="i-trend: hydrostatic pressure gradient"          unit="m/s^2"                        />
+     <field id="utrd_spg"       long_name="i-trend: surface     pressure gradient"          unit="m/s^2"                        />
+     <field id="utrd_spgexp"    long_name="i-trend: surface pressure gradient (explicit)"   unit="m/s^2"                        />
+     <field id="utrd_spgflt"    long_name="i-trend: surface pressure gradient (filtered)"   unit="m/s^2"                        />
+     <field id="utrd_keg"       long_name="i-trend: KE gradient         or hor. adv."       unit="m/s^2"                        />
+     <field id="utrd_rvo"       long_name="i-trend: relative  vorticity or metric term"     unit="m/s^2"                        />
+     <field id="utrd_pvo"       long_name="i-trend: planetary vorticity"                    unit="m/s^2"                        />
+     <field id="utrd_zad"       long_name="i-trend: vertical  advection"                    unit="m/s^2"                        />
+     <field id="utrd_udx"       long_name="i-trend: U.dx[U]"                                unit="m/s^2"                        />
+     <field id="utrd_ldf"       long_name="i-trend: lateral   diffusion"                    unit="m/s^2"                        />
+     <field id="utrd_zdf"       long_name="i-trend: vertical  diffusion"                    unit="m/s^2"                        />
+     <field id="utrd_tau"       long_name="i-trend: wind stress "                           unit="m/s^2"   grid_ref="grid_U_2D" />
+     <field id="utrd_bfr"       long_name="i-trend: bottom friction (explicit)"             unit="m/s^2"                        />
+     <field id="utrd_bfri"      long_name="i-trend: bottom friction (implicit)"             unit="m/s^2"                        />
+     <field id="utrd_tot"       long_name="i-trend: total momentum trend before atf"        unit="m/s^2"                        />
+     <field id="utrd_atf"       long_name="i-trend: asselin time filter trend"              unit="m/s^2"                        />
+    </field_group>
+
+    <field_group id="trendV" grid_ref="grid_V_3D">
+     <!-- variables available with ln_dyn_trd -->
+     <field id="vtrd_hpg"       long_name="j-trend: hydrostatic pressure gradient"          unit="m/s^2"                        />
+     <field id="vtrd_spg"       long_name="j-trend: surface     pressure gradient"          unit="m/s^2"                        />
+     <field id="vtrd_spgexp"    long_name="j-trend: surface pressure gradient (explicit)"   unit="m/s^2"                        />
+     <field id="vtrd_spgflt"    long_name="j-trend: surface pressure gradient (filtered)"   unit="m/s^2"                        />
+     <field id="vtrd_keg"       long_name="j-trend: KE gradient         or hor. adv."       unit="m/s^2"                        />
+     <field id="vtrd_rvo"       long_name="j-trend: relative  vorticity or metric term"     unit="m/s^2"                        />
+     <field id="vtrd_pvo"       long_name="j-trend: planetary vorticity"                    unit="m/s^2"                        />
+     <field id="vtrd_zad"       long_name="j-trend: vertical  advection"                    unit="m/s^2"                        />
+     <field id="vtrd_vdy"       long_name="i-trend: V.dx[V]"                                unit="m/s^2"                        />
+     <field id="vtrd_ldf"       long_name="j-trend: lateral   diffusion"                    unit="m/s^2"                        />
+     <field id="vtrd_zdf"       long_name="j-trend: vertical  diffusion"                    unit="m/s^2"                        />
+     <field id="vtrd_tau"       long_name="j-trend: wind stress "                           unit="m/s^2"   grid_ref="grid_V_2D" />
+     <field id="vtrd_bfr"       long_name="j-trend: bottom friction (explicit)"             unit="m/s^2"                        />
+     <field id="vtrd_bfri"      long_name="j-trend: bottom friction (implicit)"             unit="m/s^2"                        />
+     <field id="vtrd_tot"       long_name="j-trend: total momentum trend before atf"        unit="m/s^2"                        />
+     <field id="vtrd_atf"       long_name="j-trend: asselin time filter trend"              unit="m/s^2"                        />
+    </field_group>
+
+
+    <!-- 
+============================================================================================================
+                                        Definitions for iodef_demo.xml
+============================================================================================================
+    -->
+
+    <field_group id="mooring" >
+      <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"      />
+      <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                   />
+      <field field_ref="uoce"         name="uo"       long_name="sea_water_x_velocity"                 />
+      <field field_ref="voce"         name="vo"       long_name="sea_water_y_velocity"                 />
+      <field field_ref="woce"         name="wo"       long_name="sea_water_z_velocity"                 />
+      <field field_ref="avt"          name="difvho"   long_name="ocean_vertical_heat_diffusivity"      />
+      <field field_ref="avm"          name="difvmo"   long_name="ocean_vertical_momentum_diffusivity"  />
+   
+      <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+      <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"             />
+      <field field_ref="sstgrad"      name="tosgrad"  long_name="module_of_sea_surface_temperature_gradient"    />
+      <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+      <field field_ref="ssh"          name="zos"      long_name="sea_surface_height_above_geoid"                />
+      <field field_ref="empmr"        name="wfo"      long_name="water_flux_into_sea_water"                     />
+      <field field_ref="qsr"          name="rsntds"   long_name="surface_net_downward_shortwave_flux"           />
+      <field field_ref="qt"           name="tohfls"   long_name="surface_net_downward_total_heat_flux"          />
+      <field field_ref="taum"                                                                                   />
+      <field field_ref="20d"                                                                                    />
+      <field field_ref="mldkz5"                                                                                 />
+      <field field_ref="mldr10_1"                                                                               />
+      <field field_ref="mldr10_3"                                                                               />
+      <field field_ref="mldr0_1"                                                                                />
+      <field field_ref="mldr0_3"                                                                                />
+      <field field_ref="mld_dt02"                                                                               />
+      <field field_ref="topthdep"                                                                               />
+      <field field_ref="pycndep"                                                                                />
+      <field field_ref="tinv"                                                                                   />
+      <field field_ref="depti"                                                                                  />
+      <field field_ref="BLT"          name="blt"      long_name="barrier_layer_thickness"                       />
+      <field field_ref="utau"         name="tauuo"    long_name="surface_downward_x_stress"                     />
+      <field field_ref="vtau"         name="tauvo"    long_name="surface_downward_y_stress"                     />
+    </field_group>
+
+    <field_group id="groupT" >
+      <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"               />
+      <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                            />
+      <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+      <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"             />
+      <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+      <field field_ref="ssh"          name="zos"      long_name="sea_surface_height_above_geoid"                />
+      <field field_ref="empmr"        name="wfo"      long_name="water_flux_into_sea_water"                     />
+      <field field_ref="qsr"          name="rsntds"   long_name="surface_net_downward_shortwave_flux"           />
+      <field field_ref="qt"           name="tohfls"   long_name="surface_net_downward_total_heat_flux"          />
+      <field field_ref="taum"                                                                                   />
+      <field field_ref="20d"                                                                                    />
+      <field field_ref="mldkz5"                                                                                 />
+      <field field_ref="mldr10_1"                                                                               />
+      <field field_ref="mldr10_3"                                                                               />
+      <field field_ref="mld_dt02"                                                                               />
+      <field field_ref="topthdep"                                                                               />
+      <field field_ref="pycndep"                                                                                />
+      <field field_ref="tinv"                                                                                   />
+      <field field_ref="depti"                                                                                  />
+      <field field_ref="BLT"          name="blt"      long_name="Barrier Layer Thickness"                       />
+    </field_group>
+    
+    <field_group id="groupU" >
+      <field field_ref="uoce"         name="uo"      long_name="sea_water_x_velocity"      />
+      <field field_ref="ssu"          name="uos"     long_name="sea_surface_x_velocity"    />
+      <field field_ref="utau"         name="tauuo"   long_name="surface_downward_x_stress" />
+    </field_group>
+    
+    <field_group id="groupV" >
+      <field field_ref="voce"         name="vo"      long_name="sea_water_y_velocity"      />
+      <field field_ref="ssv"          name="vos"     long_name="sea_surface_y_velocity"    />
+      <field field_ref="vtau"         name="tauvo"   long_name="surface_downward_y_stress" />
+    </field_group>
+    
+    <field_group id="groupW" >
+      <field field_ref="woce"         name="wo"       long_name="ocean vertical velocity"  />
+    </field_group>
+    
+    <field_group id="groupT1" > 
+     <field field_ref="sst"          name="sosstsst"   standard_name="sea_surface_temperature"                                 />
+     <field field_ref="sss"          name="sossssss"   standard_name="sea_surface_salinity"                                    />
+     <field field_ref="ssh"          name="sossheig"   standard_name="sea_surface_height_above_geoid"                          />
+     <field field_ref="empmr"        name="sowaflup"   standard_name="water_flux_out_of_sea_ice_and_sea_water"                 />
+     <field field_ref="qt"           name="sohefldo"   standard_name="surface_downward_heat_flux_in_sea_water"                 />
+   </field_group>
+
+   <field_group id="groupT2" >
+     <field field_ref="toce"         name="votemper"     operation="instant" freq_op="1d" > @toce_e3t / @e3t </field>
+     <field field_ref="soce"         name="vosaline"     operation="instant" freq_op="1d" > @soce_e3t / @e3t </field>
+     <field field_ref="ssh"          name="sossheig"   standard_name="sea_surface_height_above_geoid"                          />
+     <field field_ref="empmr"        name="sowaflup"   standard_name="water_flux_out_of_sea_ice_and_sea_water"                 />
+     <field field_ref="runoffs"      name="sorunoff"   standard_name=""                                                        />
+     <field field_ref="saltflx"      name="sosafldo"   standard_name="salt_flux_into_sea_water"                                />
+     <field field_ref="qt"           name="sohefldo"   standard_name="surface_downward_heat_flux_in_sea_water"                 />
+     <field field_ref="qsr"          name="soshfldo"   standard_name="downwelling_photosynthetic_radiative_flux_in_sea_water"  />
+     <field field_ref="mldkz5" name="somixhgt" standard_name="ocean_mixed_layer_thickness_defined_by_vertical_tracer_diffusivity" />
+     <field field_ref="mldr10_1"     name="somxl010"   standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"      />
+     <field field_ref="ice_cover"    name="soicecov"   standard_name="sea_ice_area_fraction"                                   />
+     <field field_ref="wspd"         name="sowindsp"   standard_name="wind_speed"                                              />
+     <field field_ref="qrp"          name="sohefldp"   standard_name="heat_flux_into_sea_water_due_to_newtonian_relaxation"    />
+     <field field_ref="erp"          name="sowafldp"   standard_name="water_flux_out_of_sea_water_due_to_newtonian_relaxation" />
+     <field field_ref="qisf"         name="sohflisf"   standard_name=""                                                        />
+     <field field_ref="fwfisf"       name="sowflisf"   standard_name=""                                                        />
+   </field_group>
+
+   <field_group id="SPIN-UP_T" >
+          <field field_ref="e3t"          name="e3t"        standard_name="cell_thickness" />
+          <field field_ref="toce"         name="votemper"        operation="average" freq_op="10d" > @toce_e3t / @e3t </field>
+          <field field_ref="toce"         name="votemper2"       operation="average" freq_op="10d" > @toce2_e3t / @e3t </field>
+          <field field_ref="soce"         name="vosaline"        operation="average" freq_op="10d" > @soce_e3t / @e3t </field>
+          <field field_ref="soce"         name="vosaline2"       operation="average" freq_op="10d" > @soce2_e3t / @e3t </field>
+          <field field_ref="ttrd_totad"   name="opottempadvect"  operation="average" freq_op="10d" > @ttrd_totad_e3t * 1026.0 * 3991.86795711963 </field>
+          <field field_ref="ttrd_iso"     name="opottemppmdiff"  operation="average" freq_op="10d" > @ttrd_iso_e3t * 1026.0 * 3991.86795711963 </field>
+          <field field_ref="ttrd_zdfp"    name="opottempdiff"    operation="average" freq_op="10d" > @ttrd_zdfp_e3t * 1026.0 * 3991.86795711963 </field>
+          <field field_ref="ttrd_evd"     name="ttrd_evd"        operation="average" freq_op="10d" > @ttrd_evd_e3t / @e3t </field>
+          <field field_ref="ttrd_qns"     name="ttrd_qns"        operation="average" freq_op="10d" > @ttrd_qns_e3t / @e3t_surf </field>
+          <field field_ref="ttrd_qsr"     name="rsdoabsorb"      operation="average" freq_op="10d" > @ttrd_qsr_e3t * 1026.0 * 3991.86795711963 </field>
+          <field field_ref="ttrd_bbl"     name="ttrd_bbl"        operation="average" freq_op="10d" > @ttrd_bbl_e3t / @e3t </field>
+          <field field_ref="ttrd_tot"     name="opottemptend"    operation="average" freq_op="10d" > @ttrd_tot_e3t * 1026.0 * 3991.86795711963 </field>
+          <field field_ref="strd_totad"   name="osaltadvect"     operation="average" freq_op="10d" > @strd_totad_e3t * 1026.0 * 0.001 </field>
+          <field field_ref="strd_iso"     name="osaltpmdiff"     operation="average" freq_op="10d" > @strd_iso_e3t * 1026.0 * 0.001  </field>
+          <field field_ref="strd_zdfp"    name="osaltdiff"       operation="average" freq_op="10d" > @strd_zdfp_e3t * 1026.0 * 0.001  </field>
+          <field field_ref="strd_evd"     name="strd_evd"        operation="average" freq_op="10d" > @strd_evd_e3t / @e3t </field>
+          <field field_ref="strd_tot"     name="osalttend"       operation="average" freq_op="10d" > @strd_tot_e3t * 1026.0 * 0.001 </field>
+          <field field_ref="strd_bbl"     name="strd_bbl"        operation="average" freq_op="10d" > @strd_bbl_e3t / @e3t </field>
+          <field field_ref="ssh"          name="sossheig"   standard_name="sea_surface_height_above_geoid"                          />
+          <field field_ref="ssh2"         name="zossq"      standard_name="square_of_sea_surface_height_above_geoid"                />
+          <field field_ref="empmr"        name="sowaflup"   standard_name="water_flux_out_of_sea_ice_and_sea_water"                 />
+          <field field_ref="saltflx"      name="sosafldo"   standard_name="salt_flux_into_sea_water"                                />
+          <field field_ref="qt"           name="sohefldo"   standard_name="surface_downward_heat_flux_in_sea_water"                 />
+          <field field_ref="qsr"          name="soshfldo"   standard_name="downwelling_photosynthetic_radiative_flux_in_sea_water"               />
+          <field field_ref="mldkz5"       name="somixhgt"   standard_name="ocean_mixed_layer_thickness_defined_by_vertical_tracer_diffusivity"   />
+          <field field_ref="mldr10_1"     name="somxl010"   standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"      />
+          <field field_ref="mldzint_1"    name="sokaraml"   standard_name="ocean_mixed_layer_thickness"                             />
+          <field field_ref="mldzint_2"    name="somlddbm"   standard_name="ocean_mixed_layer_thickness"                             />
+          <field field_ref="ice_cover"    name="soicecov"   standard_name="sea_ice_area_fraction"                                   />
+          <field field_ref="wspd"         name="sowindsp"   standard_name="wind_speed"                                              />
+          <field field_ref="qhcisf"       name="sohflisf"   standard_name="ice_shelf_heat_flux"                                                        />
+          <field field_ref="qlatisf"      name="soqlatisf"  standard_name="ice_shelf_latent_heat_flux"                                                        />
+          <field field_ref="fwfisf"       name="sowflisf"   standard_name="ice_shelf_melting"                                                        />
+          <field field_ref="berg_total_melt"       name="berg_total_melt"          standard_name=""                                 />
+          <field field_ref="berg_total_heat_flux"  name="berg_total_heat_flux"     standard_name=""                                 />
+          <field field_ref="runoffs"       name="sorunoff"    standard_name="water_flux_into_sea_water_from_rivers"                 />
+          <field field_ref="hflx_rain_cea" name="hfrainds"    standard_name="temperature_flux_due_to_rainfall_expressed_as_heat_flux_into_sea_water"/>
+          <field field_ref="hflx_evap_cea" name="hfevapds"    standard_name="temperature_flux_due_to_evaporation_expressed_as_heat_flux_out_of_sea_water"/>
+          <field field_ref="evap_ao_cea"   name="evap_ao_cea" standard_name="water_evaporation_flux"                                />
+          <field field_ref="rain"          name="pr"          standard_name="rainfall_flux"                                         />
+          <field field_ref="snowpre"       name="snowpre"     standard_name="snowfall_flux"                                         />
+          <field field_ref="snow_ao_cea"   name="snow_ao_cea" standard_name="snowfall_flux_over_ocean"                              />
+          <field field_ref="snow_ai_cea"   name="snow_ai_cea" standard_name="snowfall_flux_over_sea_ice"                            />
+
+   </field_group>
+
+   <field_group id="groupU1" >
+     <field field_ref="ssu"          name="sozocrtx"   standard_name="sea_surface_eastward_sea_water_velocity"                 />
+     <field field_ref="utau"         name="sozotaux"   standard_name="surface_downward_x_stress" />
+   </field_group>
+
+   <field_group id="groupU2" >
+     <field field_ref="uoce"         name="vozocrtx"     operation="instant" freq_op="1d" > @uoce_e3u / @e3u </field>
+     <field field_ref="utau"         name="sozotaux"   standard_name="surface_downward_x_stress" />
+   </field_group>
+
+   <field_group id="SPIN-UP_U" >
+          <field field_ref="e3u"          name="e3u"        standard_name="cell_thickness" />
+          <field field_ref="uoce"         name="vozocrtx"     operation="average" freq_op="10d" > @uoce_e3u / @e3u </field>
+          <field field_ref="uoce"         name="vozocrtx2"    operation="average" freq_op="10d" > @uoce2_e3u / @e3u </field>
+          <field field_ref="ut"           name="ut"           operation="average" freq_op="10d" > @ut_e3u / @e3u </field>
+          <field field_ref="us"           name="us"           operation="average" freq_op="10d" > @us_e3u / @e3u </field>
+   </field_group>
+
+   <field_group id="groupV1" >
+     <field field_ref="ssv"          name="somecrty"   standard_name="sea_surface_northward_sea_water_velocity"                 />
+     <field field_ref="vtau"         name="sometauy"   standard_name="surface_downward_y_stress" />
+   </field_group>
+
+   <field_group id="groupV2" >
+     <field field_ref="voce"         name="vomecrty"     operation="instant" freq_op="1d" > @voce_e3v / @e3v </field>
+     <field field_ref="vtau"         name="sometauy"   standard_name="surface_downward_y_stress" />   
+   </field_group>
+
+   <field_group id="SPIN-UP_V" >
+          <field field_ref="e3v"          name="e3v"        standard_name="cell_thickness" />
+          <field field_ref="voce"         name="vomecrty"     operation="average" freq_op="10d" > @voce_e3v / @e3v </field>
+          <field field_ref="voce"         name="vomecrty2"    operation="average" freq_op="10d" > @voce2_e3v / @e3v </field>
+          <field field_ref="vt"           name="vt"           operation="average" freq_op="10d" > @vt_e3v / @e3v </field>
+          <field field_ref="vs"           name="vs"           operation="average" freq_op="10d" > @vs_e3v / @e3v </field>
+          <field field_ref="vtau"         name="sometauy"   standard_name="surface_downward_y_stress" />
+   </field_group>
+
+   <field_group id="groupW2" >
+     <field field_ref="woce"         name="vovecrtz"   standard_name="upward_sea_water_velocity"                         />
+     <field field_ref="avt"          name="votkeavt"   standard_name="ocean_vertical_heat_diffusivity"                   />
+     <field field_ref="avm"          name="votkeavm"   standard_name="ocean_vertical_momentum_diffusivity"               />
+     <field field_ref="aht2d"        name="soleahtw"   standard_name="vertical_component_of_ocean_xy_tracer_diffusivity" />
+   </field_group>
+
+   <field_group id="SPIN-UP_W" >
+          <field field_ref="woce"         name="vovecrtz"   standard_name="upward_sea_water_velocity"                         />
+          <field field_ref="wt"           name="wt"         standard_name=""                                                  />
+          <field field_ref="ws"           name="ws"         standard_name=""                                                  />
+          <field field_ref="avt"          name="votkeavt"   standard_name="ocean_vertical_heat_diffusivity"                   />
+          <field field_ref="avm"          name="votkeavm"   standard_name="ocean_vertical_momentum_diffusivity"               />
+          <field field_ref="aht2d"        name="soleahtw"   standard_name="vertical_component_of_ocean_xy_tracer_diffusivity" />
+   </field_group>
+
+   <field_group id="SPIN-UP_diaptr" >
+          <field field_ref="zomsfglo"     name="zomsfglo"   standard_name="meridional_streamfunction_global"           grid_ref="gznl_W_3D"       />
+          <field field_ref="zotemglo"     name="zotemglo"   standard_name="zonal_mean_temperature_global"              grid_ref="gznl_T_3D"       />
+          <field field_ref="zosrfglo"     name="zosrfglo"   standard_name="zonal_mean_surface_global"                  grid_ref="gznl_T_3D"       />
+          <field field_ref="zosalglo"     name="zosalglo"   standard_name="zonal_mean_salinity_global"                 grid_ref="gznl_T_3D"       />
+          <field field_ref="zomsfatl"     name="zomsfatl"   standard_name="meridional_streamfunction_atlantic"         grid_ref="gznl_W_3D"       />
+          <field field_ref="zotematl"     name="zotematl"   standard_name="zonal_mean_temperature_atlantic"            grid_ref="gznl_T_3D"       />
+          <field field_ref="zosrfatl"     name="zosrfatl"   standard_name="zonal_mean_surface_atlantic"                grid_ref="gznl_T_3D"       />
+          <field field_ref="zosalatl"     name="zosalatl"   standard_name="zonal_mean_salinity_atlantic"               grid_ref="gznl_T_3D"       />
+          <field field_ref="zomsfpac"     name="zomsfpac"   standard_name="meridional_streamfunction_pacific"          grid_ref="gznl_W_3D"       />
+          <field field_ref="zotempac"     name="zotempac"   standard_name="zonal_mean_temperature_pacific"             grid_ref="gznl_T_3D"       />
+          <field field_ref="zosrfpac"     name="zosrfpac"   standard_name="zonal_mean_surface_pacific"                 grid_ref="gznl_T_3D"       />
+          <field field_ref="zosalpac"     name="zosalpac"   standard_name="zonal_mean_salinity_pacific"                grid_ref="gznl_T_3D"       />
+          <field field_ref="zomsfind"     name="zomsfind"   standard_name="meridional_streamfunction_indian"           grid_ref="gznl_W_3D"       />
+          <field field_ref="zotemind"     name="zotemind"   standard_name="zonal_mean_temperature_indian"              grid_ref="gznl_T_3D"       />
+          <field field_ref="zosrfind"     name="zosrfind"   standard_name="zonal_mean_surface_indian"                  grid_ref="gznl_T_3D"       />
+          <field field_ref="zosalind"     name="zosalind"   standard_name="zonal_mean_salinity_indian"                 grid_ref="gznl_T_3D"       />
+          <field field_ref="zomsfipc"     name="zomsfipc"   standard_name="meridional_streamfunction_indian_pacific"   grid_ref="gznl_W_3D"       />
+          <field field_ref="zotemipc"     name="zotemipc"   standard_name="zonal_mean_temperature_indian_pacific"      grid_ref="gznl_T_3D"       />
+          <field field_ref="zosrfipc"     name="zosrfipc"   standard_name="zonal_mean_surface_indian_pacific"          grid_ref="gznl_T_3D"       />
+          <field field_ref="zosalipc"     name="zosalipc"   standard_name="zonal_mean_salinity_indian_pacific"         grid_ref="gznl_T_3D"       />
+          <field field_ref="sophtadv"     name="sophtadv"   standard_name="advective_heat_transport"                   grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstadv"     name="sopstadv"   standard_name="advective_salt_transport"                   grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtldf"     name="sophtldf"   standard_name="diffusive_heat_transport"                   grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstldf"     name="sopstldf"   standard_name="diffusive_salt_transport"                   grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtadv_atl" name="sophtadv_atl"   standard_name="advective_heat_transport_atlantic"      grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstadv_atl" name="sopstadv_atl"   standard_name="advective_salt_transport_atlantic"      grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtldf_atl" name="sophtldf_atl"   standard_name="diffusive_heat_transport_atlantic"      grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstldf_atl" name="sopstldf_atl"   standard_name="diffusive_salt_transport_atlantic"      grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtadv_pac" name="sophtadv_pac"   standard_name="advective_heat_transport_pacific"       grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstadv_pac" name="sopstadv_pac"   standard_name="advective_salt_transport_pacific"       grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtldf_pac" name="sophtldf_pac"   standard_name="diffusive_heat_transport_pacific"       grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstldf_pac" name="sopstldf_pac"   standard_name="diffusive_salt_transport_pacific"       grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtadv_ind" name="sophtadv_ind"   standard_name="advective_heat_transport_indian"        grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstadv_ind" name="sopstadv_ind"   standard_name="advective_salt_transport_indian"        grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtldf_ind" name="sophtldf_ind"   standard_name="diffusive_heat_transport_indian"        grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstldf_ind" name="sopstldf_ind"   standard_name="diffusive_salt_transport_indian"        grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtadv_ipc" name="sophtadv_ipc"   standard_name="advective_heat_transport_indopacific"   grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstadv_ipc" name="sopstadv_ipc"   standard_name="advective_salt_transport_indopacific"   grid_ref="gznl_T_2D"       />
+          <field field_ref="sophtldf_ipc" name="sophtldf_ipc"   standard_name="diffusive_heat_transport_indopacific"   grid_ref="gznl_T_2D"       />
+          <field field_ref="sopstldf_ipc" name="sopstldf_ipc"   standard_name="diffusive_salt_transport_indopacific"   grid_ref="gznl_T_2D"       />
+   </field_group>
+
+  </field_definition>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_dyn_rev7515.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_dyn_rev7515.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/field_def_dyn_rev7515.xml	(revision 7693)
@@ -0,0 +1,1008 @@
+<!--
+< GO6.0 version of the XIOS namelist >
+< XIOS2 version namelist >
+
+<?xml version="1.0"?>
+       -->
+ 
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+   <field_definition level="1" prec="4" operation="average" enabled=".TRUE." default_value="1.e20" > <!-- time step automaticaly defined -->
+
+    <!-- 
+============================================================================================================
+                                  Physical ocean and ice model variables
+============================================================================================================
+    -->
+
+      <!-- T grid -->
+      
+      <field_group id="grid_T" grid_ref="grid_T_2D" >
+         <field id="e3t"          long_name="T-cell thickness"   standard_name="cell_thickness"   unit="m"   grid_ref="grid_T_3D"/>
+         <field id="e3t_0"        long_name="Initial T-cell thickness"   standard_name="ref_cell_thickness"   unit="m"   grid_ref="grid_T_3D"/>
+
+         <field id="toce"         long_name="temperature"         standard_name="sea_water_potential_temperature"   unit="degC"     grid_ref="grid_T_3D"/>
+         <field id="toce_e3t"     long_name="temperature * e3t"                                                     unit="degC*m"   grid_ref="grid_T_3D" > toce * e3t </field >
+         <field id="soce"         long_name="salinity"            standard_name="sea_water_practical_salinity"      unit="1e-3"     grid_ref="grid_T_3D"/>
+         <field id="soce_e3t"     long_name="salinity * e3t"                                                        unit="1e-3*m"   grid_ref="grid_T_3D" > soce * e3t </field >
+
+         <field id="sst"          long_name="sea surface temperature"             standard_name="sea_surface_temperature"             unit="degC"     />
+         <field id="sst2"         long_name="square of sea surface temperature"   standard_name="square_of_sea_surface_temperature"   unit="degC2"     > sst * sst </field >
+         <field id="sstmax"       long_name="max of sea surface temperature"   field_ref="sst"   operation="maximum"                                  />
+         <field id="sstmin"       long_name="min of sea surface temperature"   field_ref="sst"   operation="minimum"                                  />
+         <field id="sstgrad"      long_name="module of sst gradient"                                                                  unit="degC/m"   />
+         <field id="sstgrad2"     long_name="square of module of sst gradient"                                                        unit="degC2/m2" />
+         <field id="sbt"          long_name="sea bottom temperature"                                                                  unit="degC"     />
+	 
+         <field id="sss"          long_name="sea surface salinity"             standard_name="sea_surface_salinity"   unit="1e-3" />
+         <field id="sss2"         long_name="square of sea surface salinity"                                          unit="1e-6"  > sss * sss </field >
+         <field id="sssmax"       long_name="max of sea surface salinity"   field_ref="sss"   operation="maximum"                 />
+         <field id="sssmin"       long_name="min of sea surface salinity"   field_ref="sss"   operation="minimum"                 />
+         <field id="sbs"          long_name="sea bottom salinity"                                                     unit="1e-3" />
+
+         <field id="taubot"       long_name="bottom stress module"                                                    unit="N/m2" /> 
+
+         <field id="ssh"          long_name="sea surface height"             standard_name="sea_surface_height_above_geoid"             unit="m" />
+         <field id="ssh2"         long_name="square of sea surface height"   standard_name="square_of_sea_surface_height_above_geoid"   unit="m2" > ssh * ssh </field >
+         <field id="sshmax"       long_name="max of sea surface height"   field_ref="ssh"   operation="maximum"                                  />
+
+         <field id="mldkz5"       long_name="Turbocline depth (Kz = 5e-4)"                       standard_name="ocean_mixed_layer_thickness_defined_by_vertical_tracer_diffusivity"                unit="m"          />
+         <field id="mldr10_1"     long_name="Mixed Layer Depth (dsigma = 0.01 wrt 10m)"          standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"          />
+         <field id="mldr10_1max"  long_name="Max of Mixed Layer Depth (dsigma = 0.01 wrt 10m)"   field_ref="mldr10_1"   operation="maximum"                                                                          />
+         <field id="mldr10_1min"  long_name="Min of Mixed Layer Depth (dsigma = 0.01 wrt 10m)"   field_ref="mldr10_1"   operation="minimum"                                                                          />
+         <field id="mldzint_1"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_2"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_3"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_4"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldzint_5"    long_name="Mixed Layer Depth interpolated"                     standard_name="ocean_mixed_layer_thickness"                                                       unit="m"          />
+         <field id="mldhtc_1"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_2"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_3"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_4"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="mldhtc_5"     long_name="Mixed Layer Depth integrated heat content"          standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="heatc"        long_name="Heat content vertically integrated"                 standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"       />
+         <field id="saltc"        long_name="Salt content vertically integrated"                                                                                                                   unit="1e-3*kg/m2" />
+
+         <!-- EOS -->
+         <field id="alpha"        long_name="thermal expansion"                                                         unit="degC-1" grid_ref="grid_T_3D" />
+         <field id="beta"         long_name="haline contraction"                                                        unit="1e3"    grid_ref="grid_T_3D" />
+         <field id="rhop"         long_name="potential density (sigma0)"        standard_name="sea_water_sigma_theta"   unit="kg/m3"  grid_ref="grid_T_3D" />
+
+         <!-- Energy - horizontal divergence -->
+         <field id="eken"         long_name="kinetic energy"          standard_name="specific_kinetic_energy_of_sea_water"   unit="m2/s2"  grid_ref="grid_T_3D" />
+         <field id="hdiv"         long_name="horizontal divergence"                                                          unit="s-1"    grid_ref="grid_T_3D" />
+
+         <!-- variables available with MLE -->
+         <field id="Lf_NHpf"      long_name="MLE: Lf = N H / f"   unit="m" />
+
+         <!-- next variables available with key_diahth -->
+         <field id="mlddzt"       long_name="Thermocline Depth (depth of max dT/dz)"         standard_name="depth_at_maximum_upward_derivative_of_sea_water_potential_temperature"             unit="m"                         />
+         <field id="mldr10_3"     long_name="Mixed Layer Depth (dsigma = 0.03 wrt 10m)"      standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"                         />
+         <field id="mldr0_1"      long_name="Mixed Layer Depth (dsigma = 0.01 wrt sfc)"      standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"                         />
+         <field id="mldr0_3"      long_name="Mixed Layer Depth (dsigma = 0.03 wrt sfc)"      standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"                         />
+         <field id="mld_dt02"     long_name="Mixed Layer Depth (|dT| = 0.2 wrt 10m)"         standard_name="ocean_mixed_layer_thickness_defined_by_temperature"                                unit="m"                         />
+         <field id="topthdep"     long_name="Top of Thermocline Depth (dT = -0.2 wrt 10m)"   standard_name="ocean_mixed_layer_thickness_defined_by_temperature"                                unit="m"                         />
+         <field id="pycndep"      long_name="Pycnocline Depth (dsigma[dT=-0.2] wrt 10m)"     standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"                                unit="m"                         />
+         <field id="BLT"          long_name="Barrier Layer Thickness"                                                                                                                          unit="m"                          > topthdep - pycndep </field>
+         <field id="tinv"         long_name="Max of vertical invertion of temperature"                                                                                                         unit="degC"                      />
+         <field id="depti"        long_name="Depth of max. vert. inv. of temperature"                                                                                                          unit="m"                         />
+         <field id="20d"          long_name="Depth of 20C isotherm"                          standard_name="depth_of_isosurface_of_sea_water_potential_temperature"                            unit="m"      axis_ref="iax_20C" />
+         <field id="28d"          long_name="Depth of 28C isotherm"                          standard_name="depth_of_isosurface_of_sea_water_potential_temperature"                            unit="m"      axis_ref="iax_28C" />
+         <field id="hc300"        long_name="Heat content 0-300m"                            standard_name="integral_of_sea_water_potential_temperature_wrt_depth_expressed_as_heat_content"   unit="J/m2"                      />
+
+         <!-- variables available with key_diaar5 -->
+         <field id="botpres"      long_name="Pressure at sea floor"   standard_name="sea_water_pressure_at_sea_floor"   unit="dbar" />
+
+         <!-- variables available with key_vvl -->
+         <field id="tpt_dep"      long_name="T-point depth"                  standard_name="depth_below_geoid"   unit="m"   grid_ref="grid_T_3D" />
+         <field id="e3tdef"       long_name="T-cell thickness deformation"                                       unit="%"   grid_ref="grid_T_3D" />
+      </field_group>
+
+      <!-- Tides -->
+
+      <field_group id="Tides_T" grid_ref="grid_T_2D" operation="once" >
+         <!-- tidal composante -->
+         <field id="M2x"          long_name="M2 Elevation harmonic real part "                             unit="m"        />
+         <field id="M2y"          long_name="M2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="S2x"          long_name="S2 Elevation harmonic real part "                             unit="m"        />
+         <field id="S2y"          long_name="S2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="N2x"          long_name="N2 Elevation harmonic real part "                             unit="m"        />
+         <field id="N2y"          long_name="N2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="K1x"          long_name="K1 Elevation harmonic real part "                             unit="m"        />
+         <field id="K1y"          long_name="K1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="O1x"          long_name="O1 Elevation harmonic real part "                             unit="m"        />
+         <field id="O1y"          long_name="O1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="Q1x"          long_name="Q1 Elevation harmonic real part "                             unit="m"        />
+         <field id="Q1y"          long_name="Q1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="M4x"          long_name="M4 Elevation harmonic real part "                             unit="m"        />
+         <field id="M4y"          long_name="M4 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="K2x"          long_name="K2 Elevation harmonic real part "                             unit="m"        />
+         <field id="K2y"          long_name="K2 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="P1x"          long_name="P1 Elevation harmonic real part "                             unit="m"        />
+         <field id="P1y"          long_name="P1 Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="Mfx"          long_name="Mf Elevation harmonic real part "                             unit="m"        />
+         <field id="Mfy"          long_name="Mf Elevation harmonic imaginary part"                         unit="m"        />
+         <field id="Mmx"          long_name="Mm Elevation harmonic real part "                             unit="m"        />
+         <field id="Mmy"          long_name="Mm Elevation harmonic imaginary part"                         unit="m"        />
+      </field_group>
+	 
+      <field_group id="Tides_U" grid_ref="grid_U_2D" operation="once" >
+         <field id="M2x_u"        long_name="M2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="M2y_u"        long_name="M2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="S2x_u"        long_name="S2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="S2y_u"        long_name="S2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="N2x_u"        long_name="N2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="N2y_u"        long_name="N2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K1x_u"        long_name="K1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="K1y_u"        long_name="K1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="O1x_u"        long_name="O1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="O1y_u"        long_name="O1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Q1x_u"        long_name="Q1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="Q1y_u"        long_name="Q1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="M4x_u"        long_name="M4 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="M4y_u"        long_name="M4 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K2x_u"        long_name="K2 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="K2y_u"        long_name="K2 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="P1x_u"        long_name="P1 current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="P1y_u"        long_name="P1 current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mfx_u"        long_name="Mf current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="Mfy_u"        long_name="Mf current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mmx_u"        long_name="Mm current barotrope along i-axis harmonic real part "        unit="m/s"      />
+         <field id="Mmy_u"        long_name="Mm current barotrope along i-axis harmonic imaginary part "   unit="m/s"      />
+      </field_group>
+	 
+      <field_group id="Tides_V" grid_ref="grid_V_2D" operation="once" >
+         <field id="M2x_v"        long_name="M2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="M2y_v"        long_name="M2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="S2x_v"        long_name="S2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="S2y_v"        long_name="S2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="N2x_v"        long_name="N2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="N2y_v"        long_name="N2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K1x_v"        long_name="K1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="K1y_v"        long_name="K1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="O1x_v"        long_name="O1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="O1y_v"        long_name="O1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Q1x_v"        long_name="Q1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="Q1y_v"        long_name="Q1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="M4x_v"        long_name="M4 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="M4y_v"        long_name="M4 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="K2x_v"        long_name="K2 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="K2y_v"        long_name="K2 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="P1x_v"        long_name="P1 current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="P1y_v"        long_name="P1 current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mfx_v"        long_name="Mf current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="Mfy_v"        long_name="Mf current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />
+         <field id="Mmx_v"        long_name="Mm current barotrope along j-axis harmonic real part "        unit="m/s"      />
+         <field id="Mmy_v"        long_name="Mm current barotrope along j-axis harmonic imaginary part "   unit="m/s"      />	 
+      </field_group>
+
+      <!-- SBC -->
+      
+      <field_group id="SBC" grid_ref="grid_T_2D" > <!-- time step automaticaly defined based on nn_fsbc -->
+         <field id="empmr"        long_name="Net Upward Water Flux"                standard_name="water_flux_out_of_sea_ice_and_sea_water"                              unit="kg/m2/s"   />
+         <field id="empbmr"       long_name="Net Upward Water Flux at pre. tstep"  standard_name="water_flux_out_of_sea_ice_and_sea_water"                              unit="kg/m2/s"   />
+         <field id="emp_oce"      long_name="Evap minus Precip over ocean"         standard_name="evap_minus_precip_over_sea_water"                                     unit="kg/m2/s"   />
+         <field id="emp_ice"      long_name="Evap minus Precip over ice"           standard_name="evap_minus_precip_over_sea_ice"                                       unit="kg/m2/s"   />
+         <field id="saltflx"      long_name="Downward salt flux"                                                                                                        unit="1e-3/m2/s" />
+         <field id="fmmflx"       long_name="Water flux due to freezing/melting"                                                                                        unit="kg/m2/s"   />
+         <field id="snowpre"      long_name="Snow precipitation"                   standard_name="snowfall_flux"                                                        unit="kg/m2/s"   />
+         <field id="runoffs"      long_name="River Runoffs"                        standard_name="water_flux_into_sea_water_from_rivers"                                unit="kg/m2/s"   />
+         <field id="precip"       long_name="Total precipitation"                  standard_name="precipitation_flux"                                                   unit="kg/m2/s"   />
+ 
+         <field id="qt"           long_name="Net Downward Heat Flux"                standard_name="surface_downward_heat_flux_in_sea_water"                              unit="W/m2"                           />
+         <field id="qns"          long_name="non solar Downward Heat Flux"                                                                                               unit="W/m2"                           />
+         <field id="qsr"          long_name="Shortwave Radiation"                   standard_name="net_downward_shortwave_flux_at_sea_water_surface"                     unit="W/m2"                           />
+         <field id="qsr3d"        long_name="Shortwave Radiation 3D distribution"   standard_name="downwelling_shortwave_flux_in_sea_water"                              unit="W/m2"      grid_ref="grid_T_3D" />
+         <field id="qrp"          long_name="Surface Heat Flux: Damping"            standard_name="heat_flux_into_sea_water_due_to_newtonian_relaxation"                 unit="W/m2"                           />
+         <field id="erp"          long_name="Surface Water Flux: Damping"           standard_name="water_flux_out_of_sea_water_due_to_newtonian_relaxation"              unit="kg/m2/s"                        />
+         <field id="taum"         long_name="wind stress module"                    standard_name="magnitude_of_surface_downward_stress"                                 unit="N/m2"                           />
+         <field id="wspd"         long_name="wind speed module"                     standard_name="wind_speed"                                                           unit="m/s"                            />
+         
+         <!-- * variable relative to atmospheric pressure forcing : available with ln_apr_dyn -->
+         <field id="ssh_ib"       long_name="Inverse barometer sea surface height"  standard_name="sea_surface_height_correction_due_to_air_pressure_at_low_frequency"   unit="m"        />
+
+         <!-- * variable related to ice shelf forcing * -->
+         <field id="berg_calve"   long_name="Iceberg calving"                               unit="kg/m2/s"  />
+         <field id="fwfisf"       long_name="Ice shelf melting"                             unit="kg/m2/s"  />
+         <field id="qisf"         long_name="Ice Shelf Heat Flux"                           unit="W/m2"     />
+         <field id="isfgammat"    long_name="transfert coefficient for isf (temperature)"   unit="m/s"      />
+         <field id="isfgammas"    long_name="transfert coefficient for isf (salinity)"      unit="m/s"      />
+         <field id="stbl"         long_name="salinity in the Losh tbl"                      unit="1e-3"     />
+         <field id="ttbl"         long_name="temperature in the Losh tbl"                   unit="degC"     />
+
+         <!-- *_oce variables available with ln_blk_clio or ln_blk_core -->
+         <field id="qlw_oce"      long_name="Longwave Downward Heat Flux over open ocean"  standard_name="surface_net_downward_longwave_flux"   unit="W/m2"  />
+         <field id="qsb_oce"      long_name="Sensible Downward Heat Flux over open ocean"  standard_name="surface_downward_sensible_heat_flux"  unit="W/m2"  />
+         <field id="qla_oce"      long_name="Latent Downward Heat Flux over open ocean"    standard_name="surface_downward_latent_heat_flux"    unit="W/m2"  />
+         <field id="qemp_oce"     long_name="Downward Heat Flux from E-P over open ocean"                                                       unit="W/m2"  />
+         <field id="taum_oce"     long_name="wind stress module over open ocean"           standard_name="magnitude_of_surface_downward_stress" unit="N/m2"  />
+
+         <!-- available key_oasis3 -->
+         <field id="snow_ao_cea"  long_name="Snow over ice-free ocean (cell average)"   standard_name="snowfall_flux"                             unit="kg/m2/s"  />
+         <field id="snow_ai_cea"  long_name="Snow over sea-ice (cell average)"          standard_name="snowfall_flux"                             unit="kg/m2/s"  />
+         <field id="subl_ai_cea"  long_name="Sublimation over sea-ice (cell average)"   standard_name="surface_snow_and_ice_sublimation_flux"     unit="kg/m2/s"  />
+         <field id="icealb_cea"   long_name="Ice albedo (cell average)"                 standard_name="sea_ice_albedo"                            unit="1"        />
+         <field id="calving_cea"  long_name="Calving"                                   standard_name="water_flux_into_sea_water_from_icebergs"   unit="kg/m2/s"  />
+
+         <!-- available if key_oasis3 + conservative method -->
+         <field id="rain"          long_name="Liquid precipitation"                                     standard_name="rainfall_flux"                                                                 unit="kg/m2/s"  />
+         <field id="evap_ao_cea"   long_name="Evaporation over ice-free ocean (cell average)"           standard_name="water_evaporation_flux"                                                        unit="kg/m2/s"  />
+         <field id="isnwmlt_cea"   long_name="Snow over Ice melting (cell average)"                     standard_name="surface_snow_melt_flux"                                                        unit="kg/m2/s"  />
+         <field id="fsal_virt_cea" long_name="Virtual salt flux due to ice formation (cell average)"    standard_name="virtual_salt_flux_into_sea_water_due_to_sea_ice_thermodynamics"                unit="kg/m2/s"  />
+         <field id="fsal_real_cea" long_name="Real salt flux due to ice formation (cell average)"       standard_name="downward_sea_ice_basal_salt_flux"                                              unit="kg/m2/s"  />
+         <field id="hflx_rain_cea" long_name="heat flux due to rainfall"                                standard_name="temperature_flux_due_to_rainfall_expressed_as_heat_flux_into_sea_water"        unit="W/m2"     />
+         <field id="hflx_evap_cea" long_name="heat flux due to evaporation"                             standard_name="temperature_flux_due_to_evaporation_expressed_as_heat_flux_out_of_sea_water"   unit="W/m2"     />
+         <field id="hflx_snow_cea" long_name="heat flux due to snow falling over ice-free ocean"        standard_name="heat_flux_into_sea_water_due_to_snow_thermodynamics"                           unit="W/m2"     />
+         <field id="hflx_ice_cea"  long_name="heat flux due to ice thermodynamics"                      standard_name="heat_flux_into_sea_water_due_to_sea_ice_thermodynamics"                        unit="W/m2"     />
+         <field id="hflx_rnf_cea"  long_name="heat flux due to runoffs"                                 standard_name="temperature_flux_due_to_runoff_expressed_as_heat_flux_into_sea_water"          unit="W/m2"     />
+         <field id="hflx_cal_cea"  long_name="heat flux due to calving"                                 standard_name="heat_flux_into_sea_water_due_to_iceberg_thermodynamics"                        unit="W/m2"     />
+         <field id="bicemel_cea"   long_name="Rate of Melt at Sea Ice Base (cell average)"              standard_name="tendency_of_sea_ice_amount_due_to_basal_melting"                               unit="kg/m2/s"  />
+         <field id="licepro_cea"   long_name="Lateral Sea Ice Growth Rate (cell average)"               standard_name="tendency_of_sea_ice_amount_due_to_lateral_growth_of_ice_floes"                 unit="kg/m2/s"  />
+         <field id="snowmel_cea"   long_name="Snow Melt Rate (cell average)"                            standard_name="surface_snow_melt_flux"                                                        unit="kg/m2/s"  />
+         <field id="sntoice_cea"   long_name="Snow-Ice Formation Rate (cell average)"                   standard_name="tendency_of_sea_ice_amount_due_to_snow_conversion"                             unit="kg/m2/s"  />
+         <field id="ticemel_cea"   long_name="Rate of Melt at Upper Surface of Sea Ice (cell average)"  standard_name="tendency_of_sea_ice_amount_due_to_surface_melting"                             unit="kg/m2/s"  />
+
+         <!-- ice fields -->
+         <field id="ice_cover"    long_name="Ice fraction"                                                 standard_name="sea_ice_area_fraction"                              unit="1"            />
+
+         <field id="qsr_ai_cea"   long_name="Air-Ice downward solar heat flux (cell average)"              standard_name="surface_downwelling_shortwave_flux_in_air"          unit="W/m2"         />
+         <field id="qns_ai_cea"   long_name="Air-Ice downward non-solar heat flux (cell average)"                                                                             unit="W/m2"         />
+         <field id="qla_ai_cea"   long_name="Air-Ice downward Latent heat flux (cell average)"             standard_name="surface_downward_latent_heat_flux"                  unit="W/m2"         />
+         
+         <field id="qsr_io_cea"   long_name="Ice-Oce downward solar heat flux (cell average)"              standard_name="net_downward_shortwave_flux_at_sea_water_surface"   unit="W/m2"         />
+         <field id="qns_io_cea"   long_name="Ice-Oce downward non-solar heat flux (cell average)"                                                                             unit="W/m2"         />
+         
+         <field id="snowthic_cea" long_name="Snow thickness (cell average)"                                standard_name="surface_snow_thickness"                             unit="m"            />
+         <field id="icethic_cea"  long_name="Ice thickness (cell average)"                                 standard_name="sea_ice_thickness"                                  unit="m"            />
+         <field id="iceprod_cea"  long_name="Ice production (cell average)"                                                                                                   unit="m/s"          />
+         <field id="iiceconc"     long_name="Ice concentration"                                            standard_name="sea_ice_area_fraction"                              unit="1"            />
+         
+         <field id="ice_pres"     long_name="Ice presence"                                                                                                                    unit=""             />
+         <field id="ist_cea"      long_name="Ice surface temperature (cell average)"                       standard_name="surface_temperature"                                unit="degC"         />
+         <field id="ist_ipa"      long_name="Ice surface temperature (ice presence average)"               standard_name="surface_temperature"                                unit="degC"         />      
+         <field id="uice_ipa"     long_name="Ice velocity along i-axis at I-point (ice presence average)"  standard_name="sea_ice_x_velocity"                                 unit="m/s"          />      
+         <field id="vice_ipa"     long_name="Ice velocity along j-axis at I-point (ice presence average)"  standard_name="sea_ice_y_velocity"                                 unit="m/s"          />      
+         
+         <field id="utau_ice"     long_name="Wind stress along i-axis over the ice at i-point"             standard_name="surface_downward_x_stress"                          unit="N/m2"         />
+         <field id="vtau_ice"     long_name="Wind stress along j-axis over the ice at i-point"             standard_name="surface_downward_y_stress"                          unit="N/m2"         />
+         
+         <field id="u_imasstr"    long_name="Sea-ice mass transport along i-axis"                          standard_name="sea_ice_x_transport"                                unit="kg/s"         />
+         <field id="v_imasstr"    long_name="Sea-ice mass transport along j-axis"                          standard_name="sea_ice_y_transport"                                unit="kg/s"         />
+         <field id="emp_x_sst"    long_name="Concentration/Dilution term on SST"                                                                                              unit="kg*degC/m2/s" />
+         <field id="emp_x_sss"    long_name="Concentration/Dilution term on SSS"                                                                                              unit="kg*1e-3/m2/s" />        
+       
+         <field id="iceconc"      long_name="ice concentration"                                            standard_name="sea_ice_area_fraction"                              unit="%"            />
+       	 <field id="isst"         long_name="sea surface temperature"                                      standard_name="sea_surface_temperature"                            unit="degC"         />
+         <field id="isss"         long_name="sea surface salinity"                                         standard_name="sea_surface_salinity"                               unit="1e-3"         /> 
+         <field id="qt_oce"       long_name="total flux at ocean surface"                                  standard_name="surface_downward_heat_flux_in_sea_water"            unit="W/m2"         />
+         <field id="qsr_oce"      long_name="solar heat flux at ocean surface"                             standard_name="net_downward_shortwave_flux_at_sea_water_surface"   unit="W/m2"         />
+         <field id="qns_oce"      long_name="non-solar heat flux at ocean surface"                                                                                            unit="W/m2"         />
+         <field id="qt_ice"       long_name="total heat flux at ice surface: sum over categories"          standard_name="surface_downward_heat_flux_in_air"                  unit="W/m2"         />
+         <field id="qsr_ice"      long_name="solar heat flux at ice surface: sum over categories"          standard_name="surface_downwelling_shortwave_flux_in_air"          unit="W/m2"         />
+         <field id="qns_ice"      long_name="non-solar heat flux at ice surface: sum over categories"                                                                         unit="W/m2"         />
+         <field id="qtr_ice"      long_name="solar heat flux transmitted through ice: sum over categories"                                                                    unit="W/m2"         />
+         <field id="qemp_ice"     long_name="Downward Heat Flux from E-P over ice"                                                                                            unit="W/m2"         />
+         <field id="micesalt"     long_name="Mean ice salinity"                                                                                                               unit="1e-3"         />
+         <field id="miceage"      long_name="Mean ice age"                                                                                                                    unit="years"        />
+         <field id="alb_ice"      long_name="Mean albedo over sea ice"                                                                                                        unit=""             />
+         <field id="albedo"       long_name="Mean albedo over sea ice and ocean"                                                                                              unit=""             />
+
+         <field id="iceage_cat"   long_name="Ice age for categories"                                       unit="days"   axis_ref="ncatice" />
+         <field id="iceconc_cat"  long_name="Ice concentration for categories"                             unit="%"      axis_ref="ncatice" />
+         <field id="icethic_cat"  long_name="Ice thickness for categories"                                 unit="m"      axis_ref="ncatice" />
+         <field id="snowthic_cat" long_name="Snow thicknessi for categories"                               unit="m"      axis_ref="ncatice" />
+         <field id="salinity_cat" long_name="Sea-Ice Bulk salinity for categories"                         unit="g/kg"   axis_ref="ncatice" />
+         <field id="brinevol_cat" long_name="Brine volume for categories"                                  unit="%"      axis_ref="ncatice" />
+         <field id="icetemp_cat"  long_name="Ice temperature for categories"                               unit="degC"   axis_ref="ncatice" />
+         <field id="snwtemp_cat"  long_name="Snow temperature for categories"                              unit="degC"   axis_ref="ncatice" />
+
+         <field id="micet"        long_name="Mean ice temperature"                                         unit="degC"     />
+         <field id="icehc"        long_name="ice total heat content"                                       unit="10^9J"    /> 
+         <field id="isnowhc"      long_name="snow total heat content"                                      unit="10^9J"    />
+         <field id="icest"        long_name="ice surface temperature"                                      unit="degC"     />
+         <field id="ibrinv"       long_name="brine volume"                                                 unit="%"        />
+         <field id="icecolf"      long_name="frazil ice collection thickness"                              unit="m"        />
+         <field id="icestr"       long_name="ice strength"                                                 unit="N/m"      />
+         <field id="icevel"       long_name="ice velocity"                                                 unit="m/s"      />
+         <field id="idive"        long_name="divergence"                                                   unit="1e-8s-1"  />
+         <field id="ishear"       long_name="shear"                                                        unit="1e-8s-1"  />
+         <field id="icevolu"      long_name="ice volume"                                                   unit="m"        />
+         <field id="snowvol"      long_name="snow volume"                                                  unit="m"        />
+
+         <field id="icetrp"       long_name="ice volume transport"                                         unit="m/day"          />
+         <field id="snwtrp"       long_name="snw volume transport"                                         unit="m/day"          />
+         <field id="saltrp"       long_name="salt content transport"                                       unit="1e-3*kg/m2/day" />
+         <field id="deitrp"       long_name="advected ice enthalpy"                                        unit="W/m2"           />
+         <field id="destrp"       long_name="advected snw enthalpy"                                        unit="W/m2"           />
+
+         <field id="sfxbri"       long_name="brine salt flux"                                              unit="1e-3*kg/m2/day" />
+         <field id="sfxdyn"       long_name="salt flux from ridging rafting"                               unit="1e-3*kg/m2/day" />
+         <field id="sfxres"       long_name="salt flux from lipupdate (resultant)"                         unit="1e-3*kg/m2/day" />
+         <field id="sfxbog"       long_name="salt flux from bot growth"                                    unit="1e-3*kg/m2/day" />
+         <field id="sfxbom"       long_name="salt flux from bot melt"                                      unit="1e-3*kg/m2/day" />
+         <field id="sfxsum"       long_name="salt flux from surf melt"                                     unit="1e-3*kg/m2/day" />
+         <field id="sfxsni"       long_name="salt flux from snow-ice formation"                            unit="1e-3*kg/m2/day" />
+         <field id="sfxopw"       long_name="salt flux from open water ice formation"                      unit="1e-3*kg/m2/day" />
+         <field id="sfxsub"       long_name="salt flux from sublimation"                                   unit="1e-3*kg/m2/day" />
+         <field id="sfx"          long_name="salt flux total"                                              unit="1e-3*kg/m2/day" />
+
+         <field id="vfxbog"       long_name="daily bottom thermo ice prod."                                unit="m/day"   />
+         <field id="vfxdyn"       long_name="daily  dynamic ice prod."                                     unit="m/day"   />
+         <field id="vfxopw"       long_name="daily lateral thermo ice prod."                               unit="m/day"   />
+         <field id="vfxsni"       long_name="daily snowice ice prod."                                      unit="m/day"   />
+         <field id="vfxsum"       long_name="surface melt"                                                 unit="m/day"   />
+         <field id="vfxbom"       long_name="bottom melt"                                                  unit="m/day"   />
+         <field id="vfxres"       long_name="daily resultant ice prod./melting from limupdate"             unit="m/day"   />
+         <field id="vfxice"       long_name="ice melt/growth"                                              unit="m/day"   />
+         <field id="vfxsnw"       long_name="snw melt/growth"                                              unit="m/day"   />
+         <field id="vfxsub"       long_name="snw sublimation"                                              unit="m/day"   />
+         <field id="vfxspr"       long_name="snw precipitation on ice"                                     unit="m/day"   />
+         <field id="vfxthin"      long_name="daily thermo ice prod. for thin ice(<20cm) + open water"      unit="m/day"   />
+
+         <field id="afxtot"       long_name="area tendency (total)"                                        unit="day-1"   />
+         <field id="afxdyn"       long_name="area tendency (dynamics)"                                     unit="day-1"   />
+         <field id="afxthd"       long_name="area tendency (thermo)"                                       unit="day-1"   />
+
+         <field id="hfxsum"       long_name="heat fluxes causing surface ice melt"                         unit="W/m2"  />
+         <field id="hfxbom"       long_name="heat fluxes causing bottom ice melt"                          unit="W/m2"  />
+         <field id="hfxbog"       long_name="heat fluxes causing bottom ice growth"                        unit="W/m2"  />
+         <field id="hfxdif"       long_name="heat fluxes causing ice temperature change"                   unit="W/m2"  />
+         <field id="hfxopw"       long_name="heat fluxes causing open water ice formation"                 unit="W/m2"  />
+         <field id="hfxsnw"       long_name="heat fluxes causing snow melt"                                unit="W/m2"  />
+         <field id="hfxerr"       long_name="heat fluxes error after heat diffusion"                       unit="W/m2"  />
+         <field id="hfxerr_rem"   long_name="heat fluxes error after remapping"                            unit="W/m2"  />
+         <field id="hfxout"       long_name="total heat fluxes received by the ocean"                      unit="W/m2"  />
+         <field id="hfxin"        long_name="total heat fluxes at the ice/ocean surface"                   unit="W/m2"  />
+
+         <!-- heat flux associated with mass exchange -->
+         <field id="hfxthd"       long_name="heat fluxes from ice-ocean mass exchange during thermo"       unit="W/m2"  />
+         <field id="hfxdyn"       long_name="heat fluxes from ice-ocean mass exchange during dynamic"      unit="W/m2"  />
+         <field id="hfxres"       long_name="heat fluxes from ice-ocean mass exchange during resultant"    unit="W/m2"  />
+         <field id="hfxsub"       long_name="heat fluxes from ice-atm. mass exchange during sublimation"   unit="W/m2"  />
+         <field id="hfxspr"       long_name="heat fluxes from ice-atm. mass exchange during snow precip"   unit="W/m2"  />
+
+         <!-- diags -->
+         <field id="hfxdhc"       long_name="Heat content variation in snow and ice"                       unit="W/m2" />
+         <field id="hfxtur"       long_name="turbulent heat flux at the ice base"                          unit="W/m2" />
+	 <!-- sbcssm variables -->
+         <field id="sst_m"    unit="degC" />
+         <field id="sss_m"    unit="psu"  />
+         <field id="ssu_m"    unit="m/s"  />
+         <field id="ssv_m"    unit="m/s"  />
+         <field id="ssh_m"    unit="m"    />
+         <field id="e3t_m"    unit="m"    />
+         <field id="frq_m"    unit="-"    />
+
+      </field_group>
+
+      <!-- U grid -->
+      
+      <field_group id="grid_U"   grid_ref="grid_U_2D">
+         <field id="e3u"          long_name="U-cell thickness"                                       standard_name="cell_thickness"              unit="m"          grid_ref="grid_U_3D" />
+         <field id="e3u_0"        long_name="Initial U-cell thickness"                               standard_name="ref_cell_thickness"          unit="m"          grid_ref="grid_U_3D"/>
+         <field id="utau"         long_name="Wind Stress along i-axis"                               standard_name="surface_downward_x_stress"   unit="N/m2"                            />
+         <field id="uoce"         long_name="ocean current along i-axis"                             standard_name="sea_water_x_velocity"        unit="m/s"        grid_ref="grid_U_3D" />
+         <field id="uoce_e3u"     long_name="ocean current along i-axis * e3u"                                                                   unit="m2/s"       grid_ref="grid_U_3D"  > uoce * e3u </field>
+         <field id="ssu"          long_name="ocean surface current along i-axis"                                                                 unit="m/s"                             />
+         <field id="sbu"          long_name="ocean bottom current along i-axis"                                                                  unit="m/s"                             />
+         <field id="ubar"         long_name="ocean barotropic current along i-axis"                                                              unit="m/s"                             />
+         <field id="uocetr_eff"   long_name="Effective ocean transport along i-axis"                 standard_name="ocean_volume_x_transport"    unit="m3/s"       grid_ref="grid_U_3D" />
+         <field id="uocet"        long_name="ocean transport along i-axis times temperature (CRS)"                                               unit="degC*m/s"   grid_ref="grid_U_3D" />
+         <field id="uoces"        long_name="ocean transport along i-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_U_3D" />
+
+         <!-- variables available with MLE -->
+         <field id="psiu_mle"     long_name="MLE streamfunction along i-axis"   unit="m3/s"   grid_ref="grid_U_3D" />
+
+         <!-- uoce_eiv: available with key_traldf_eiv and key_diaeiv -->
+         <field id="uoce_eiv"     long_name="EIV ocean current along i-axis"   standard_name="bolus_sea_water_x_velocity"   unit="m/s"   grid_ref="grid_U_3D" />
+
+         <!-- uoce_eiv: available with key_trabbl -->
+         <field id="uoce_bbl"     long_name="BBL ocean current along i-axis"    unit="m/s"  />
+         <field id="ahu_bbl"      long_name="BBL diffusive flux along i-axis"   unit="m3/s" />
+
+         <!-- variable for ice shelves -->
+         <field id="utbl"         long_name="zonal current in the Losh tbl"     unit="m/s" />
+
+         <!-- variables available with key_diaar5 -->
+         <field id="u_masstr"     long_name="ocean eulerian mass transport along i-axis"    standard_name="ocean_mass_x_transport"                          unit="kg/s"        grid_ref="grid_U_3D" />
+         <field id="u_heattr"     long_name="ocean eulerian heat transport along i-axis"    standard_name="ocean_heat_x_transport"                          unit="W"                                />
+         <field id="u_salttr"     long_name="ocean eulerian salt transport along i-axis"    standard_name="ocean_salt_x_transport"                          unit="1e-3*kg/s"                        />
+         <field id="ueiv_heattr"  long_name="ocean bolus heat transport along i-axis"       standard_name="ocean_heat_x_transport_due_to_bolus_advection"   unit="W"                                />
+         <field id="udiff_heattr" long_name="ocean diffusion heat transport along i-axis"   standard_name="ocean_heat_x_transport_due_to_diffusion"         unit="W"                                />
+      </field_group>
+      
+      <!-- V grid -->
+      
+      <field_group id="grid_V"   grid_ref="grid_V_2D">
+         <field id="e3v"          long_name="V-cell thickness"                                       standard_name="cell_thickness"              unit="m"          grid_ref="grid_V_3D" />
+         <field id="e3v_0"        long_name="Initial V-cell thickness"                               standard_name="ref_cell_thickness"          unit="m"          grid_ref="grid_V_3D"/>
+         <field id="vtau"         long_name="Wind Stress along j-axis"                               standard_name="surface_downward_y_stress"   unit="N/m2"                            />
+         <field id="voce"         long_name="ocean current along j-axis"                             standard_name="sea_water_y_velocity"        unit="m/s"        grid_ref="grid_V_3D" />
+         <field id="voce_e3v"     long_name="ocean current along j-axis * e3v"                                                                   unit="m2/s"       grid_ref="grid_V_3D"  > voce * e3v </field>
+         <field id="ssv"          long_name="ocean surface current along j-axis"                                                                 unit="m/s"                             />
+         <field id="sbv"          long_name="ocean bottom current along j-axis"                                                                  unit="m/s"                             />
+         <field id="vbar"         long_name="ocean barotropic current along j-axis"                                                              unit="m/s"                             />
+         <field id="vocetr_eff"   long_name="Effective ocean transport along j-axis"                 standard_name="ocean_volume_y_transport"    unit="m3/s"       grid_ref="grid_V_3D" />
+         <field id="vocet"        long_name="ocean transport along j-axis times temperature (CRS)"                                               unit="degC*m/s"   grid_ref="grid_V_3D" />
+         <field id="voces"        long_name="ocean transport along j-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_V_3D" />
+
+         <!-- variables available with MLE -->
+         <field id="psiv_mle"     long_name="MLE streamfunction along j-axis"   unit="m3/s"   grid_ref="grid_V_3D" />
+
+         <!-- voce_eiv: available with key_traldf_eiv and key_diaeiv -->
+         <field id="voce_eiv"     long_name="EIV ocean current along j-axis"   standard_name="bolus_sea_water_y_velocity"   unit="m/s"   grid_ref="grid_V_3D" />
+
+         <!-- voce_eiv: available with key_trabbl -->
+         <field id="voce_bbl"     long_name="BBL ocean current along j-axis"    unit="m/s"  />
+         <field id="ahv_bbl"      long_name="BBL diffusive flux along j-axis"   unit="m3/s" />
+
+         <!-- variable for ice shelves -->
+         <field id="vtbl"         long_name="meridional current in the Losh tbl"   unit="m/s" />
+
+         <!-- variables available with key_diaar5 -->
+         <field id="v_masstr"     long_name="ocean eulerian mass transport along j-axis"    standard_name="ocean_mass_y_transport"                          unit="kg/s"        grid_ref="grid_V_3D" />
+         <field id="v_heattr"     long_name="ocean eulerian heat transport along j-axis"    standard_name="ocean_heat_y_transport"                          unit="W"                                />
+         <field id="v_salttr"     long_name="ocean eulerian salt transport along i-axis"    standard_name="ocean_salt_y_transport"                          unit="1e-3*kg/s"                        />
+         <field id="veiv_heattr"  long_name="ocean bolus heat transport along j-axis"       standard_name="ocean_heat_y_transport_due_to_bolus_advection"   unit="W"                                />
+         <field id="vdiff_heattr" long_name="ocean diffusion heat transport along j-axis"   standard_name="ocean_heat_y_transport_due_to_diffusion"         unit="W"                                />
+      </field_group>
+      
+      <!-- W grid -->
+      
+      <field_group id="grid_W" grid_ref="grid_W_3D">
+        <field id="e3w"          long_name="W-cell thickness"                     standard_name="cell_thickness"              unit="m"    />
+        <field id="woce"         long_name="ocean vertical velocity"              standard_name="upward_sea_water_velocity"   unit="m/s"  />
+        <field id="wocetr_eff"   long_name="effective ocean vertical transport"                                               unit="m3/s" />
+
+        <!-- woce_eiv: available with key_traldf_eiv and key_diaeiv -->
+        <field id="woce_eiv"     long_name="EIV ocean vertical velocity"   standard_name="bolus_upward_sea_water_velocity"   unit="m/s" />
+
+        <field id="avt"          long_name="vertical eddy diffusivity"   standard_name="ocean_vertical_heat_diffusivity"       unit="m2/s" />
+        <field id="logavt"       long_name="logarithm of vertical eddy diffusivity"   standard_name="ocean_vertical_heat_diffusivity"       unit="m2/s" />
+        <field id="avm"          long_name="vertical eddy viscosity"     standard_name="ocean_vertical_momentum_diffusivity"   unit="m2/s" />
+
+        <!-- avs: available with key_zdfddm -->
+        <field id="avs"          long_name="salt vertical eddy diffusivity"   standard_name="ocean_vertical_salt_diffusivity"   unit="m2/s" />
+        <field id="logavs"       long_name="logarithm of salt vertical eddy diffusivity"   standard_name="ocean_vertical_heat_diffusivity"       unit="m2/s" />
+
+        <!-- avt_evd and avm_evd: available with ln_zdfevd -->
+        <field id="avt_evd"      long_name="convective enhancement to vertical diffusivity"   standard_name="ocean_vertical_tracer_diffusivity_due_to_convection"     unit="m2/s" />
+        <field id="avm_evd"      long_name="convective enhancement to vertical viscosity"     standard_name="ocean_vertical_momentum_diffusivity_due_to_convection"   unit="m2/s" />
+
+        <!-- avt_tide: available with key_zdftmx -->
+        <field id="av_tide"      long_name="tidal vertical diffusivity"   standard_name="ocean_vertical_tracer_diffusivity_due_to_tides"   unit="m2/s" />
+
+       <!-- variables available with key_zdftmx_new -->
+        <field id="av_ratio"     long_name="S over T diffusivity ratio"            standard_name="salinity_over_temperature_diffusivity_ratio"                     unit="1"    />
+        <field id="av_wave"      long_name="wave-induced vertical diffusivity"     standard_name="ocean_vertical_tracer_diffusivity_due_to_internal_waves"         unit="m2/s" />
+        <field id="bn2"          long_name="squared Brunt-Vaisala frequency"       standard_name="squared_brunt_vaisala_frequency"                                 unit="s-1"  />
+        <field id="bflx_tmx"     long_name="wave-induced buoyancy flux"            standard_name="buoyancy_flux_due_to_internal_waves"                             unit="W/kg" />
+        <field id="pcmap_tmx"    long_name="power consumed by wave-driven mixing"  standard_name="vertically_integrated_power_consumption_by_wave_driven_mixing"   unit="W/m2"      grid_ref="grid_W_2D" />
+        <field id="emix_tmx"     long_name="power density available for mixing"    standard_name="power_available_for_mixing_from_breaking_internal_waves"         unit="W/kg" />
+
+        <!-- variables available with key_diaar5 -->   
+        <field id="w_masstr"     long_name="vertical mass transport"             standard_name="upward_ocean_mass_transport"             unit="kg/s"   />
+        <field id="w_masstr2"    long_name="square of vertical mass transport"   standard_name="square_of_upward_ocean_mass_transport"   unit="kg2/s2" />
+
+        <!-- aht2d and  aht2d_eiv: available with key_traldf_eiv and key_traldf_c2d -->
+        <field id="aht2d"        long_name="lateral eddy diffusivity"       standard_name="ocean_tracer_xy_laplacian_diffusivity"      unit="m2/s"   grid_ref="grid_W_2D" />
+        <field id="aht2d_eiv"    long_name="EIV lateral eddy diffusivity"   standard_name="ocean_tracer_bolus_laplacian_diffusivity"   unit="m2/s"   grid_ref="grid_W_2D" />
+        <!-- variables added for nn_etau revision testing -->
+        <field id="htau"         long_name="e-decay length scale of nn_etau TKE"       unit="m"        grid_ref="grid_W_2D" />
+        <field id="tke"          long_name="Turbulent Kinetic Energy"                  unit="m2/s2"    />
+        <field id="tke_niw"      long_name="Turbulent Kinetic Energy due to near-inertial wave breaking"  unit="m2/s2" />
+      </field_group>
+          
+      <!-- product fields -->
+      <field_group id="diaprod">
+	<field id="ut"           long_name="product_of_sea_water_x_velocity_and_potential_temperature"      unit="degC m/s"      grid_ref="grid_U_3D"   />
+        <field id="ut_e3u"       long_name="product_of_sea_water_x_velocity_and_potential_temperature * e3u"  unit="degC m2/s"   grid_ref="grid_U_3D" > ut * e3u </field >
+	<field id="us"           long_name="product_of_sea_water_x_velocity_and_salinity"                   unit="PSU m/s"       grid_ref="grid_U_3D"   />
+        <field id="us_e3u"       long_name="product_of_sea_water_x_velocity_and_salinity * e3u"             unit="PSU m2/s"      grid_ref="grid_U_3D" > us * e3u </field >
+	<field id="urhop"        long_name="product_of_sea_water_x_velocity_and_potential_density"          unit="(kg/m3).(m/s)" grid_ref="grid_U_3D"   />
+        <field id="urhop_e3u"    long_name="product_of_sea_water_x_velocity_and_potential_density * e3u"    unit="(kg/m3).(m2/s)"   grid_ref="grid_U_3D" > urhop * e3u </field >
+	<field id="vt"           long_name="product_of_sea_water_y_velocity_and_potential_temperature"      unit="degC m/s"      grid_ref="grid_V_3D"   />
+        <field id="vt_e3v"       long_name="product_of_sea_water_y_velocity_and_potential_temperature * e3v"  unit="degC m2/s"   grid_ref="grid_V_3D" > vt * e3v </field >
+	<field id="vs"           long_name="product_of_sea_water_y_velocity_and_salinity"                   unit="PSU m/s"       grid_ref="grid_V_3D"   />
+        <field id="vs_e3v"       long_name="product_of_sea_water_y_velocity_and_salinity * e3t"             unit="PSU m2/s"      grid_ref="grid_V_3D" > vs * e3v </field >
+	<field id="vrhop"        long_name="product_of_sea_water_y_velocity_and_potential_density"          unit="(kg/m3).(m/s)" grid_ref="grid_V_3D"   />
+        <field id="vrhop_e3v"    long_name="product_of_sea_water_y_velocity_and_potential_density * e3t"    unit="(kg/m3).(m2/s)"  grid_ref="grid_V_3D" > vrhop * e3v </field >
+	<field id="wt"           long_name="product_of_upward_sea_water_velocity_and_potential_temperature" unit="degC m/s"      grid_ref="grid_W_3D"   />
+	<field id="ws"           long_name="product_of_upward_sea_water_velocity_and_salinity"              unit="PSU m/s"       grid_ref="grid_W_3D"   />
+	<field id="wrhop"        long_name="product_of_upward_sea_water_velocity_and_potential_density"     unit="(kg/m3).(m/s)" grid_ref="grid_W_3D"   />
+      </field_group>
+
+      <!-- scalar variables available with key_diaar5 -->
+
+      <field_group id="scalar"  domain_ref="1point" >
+         <field id="voltot"     long_name="global total volume"                          standard_name="sea_water_volume"                               unit="m3"   />
+         <field id="sshtot"     long_name="global mean ssh"                              standard_name="global_average_sea_level_change"                unit="m"    />
+         <field id="sshsteric"  long_name="global mean ssh steric"                       standard_name="global_average_steric_sea_level_change"         unit="m"    />
+         <field id="sshthster"  long_name="global mean ssh thermosteric"                 standard_name="global_average_thermosteric_sea_level_change"   unit="m"    />
+         <field id="masstot"    long_name="global total mass"                            standard_name="sea_water_mass"                                 unit="kg"   />
+         <field id="temptot"    long_name="global mean temperature"                      standard_name="sea_water_potential_temperature"                unit="degC" />
+         <field id="saltot"     long_name="global mean salinity"                         standard_name="sea_water_salinity"                             unit="1e-3" />
+         <field id="fram_trans" long_name="Sea Ice Mass Transport Through Fram Strait"   standard_name="sea_ice_transport_across_line"                  unit="kg/s" />
+
+      	 <!-- available with ln_diahsb -->
+    	 <field id="bgtemper"     long_name="drift in global mean temperature wrt timestep 1"                 standard_name="change_over_time_in_sea_water_potential_temperature"   unit="degC"     />
+    	 <field id="bgsaline"     long_name="drift in global mean salinity wrt timestep 1"                    standard_name="change_over_time_in_sea_water_practical_salinity"      unit="1e-3"     />
+    	 <field id="bgheatco"     long_name="drift in global mean heat content wrt timestep 1"                                                                                      unit="10^9J"    />
+    	 <field id="bgsaltco"     long_name="drift in global mean salt content wrt timestep 1"                                                                                      unit="1e-3*m3"  />
+    	 <field id="bgvolssh"     long_name="drift in global mean ssh volume wrt timestep 1"                                                                                        unit="km3"      />
+         <field id="bgvole3t"     long_name="drift in global mean volume variation (e3t) wrt timestep 1"                                                                            unit="km3"      />
+    	 <field id="bgvoltot"     long_name="drift in global mean volume wrt timestep 1"                                                                                            unit="km3"      />
+         <!-- NOTE: No matching iom_put call -->
+    	 <field id="bgsshtot"     long_name="drift in global mean ssh wrt timestep 1"                         standard_name="global_average_sea_level_change"                       unit="m"        />
+    	 <field id="bgfrcvol"     long_name="drift in global mean volume from forcing wrt timestep 1"                                                                               unit="km3"      />
+    	 <field id="bgfrctem"     long_name="drift in global mean heat content from forcing wrt timestep 1"                                                                         unit="10^9J"    />
+    	 <field id="bgfrcsal"     long_name="drift in global mean salt content from forcing wrt timestep 1"                                                                         unit="1e-3*km3" />
+    	 <field id="bgmistem"     long_name="global mean temperature error due to free surface"                                                                                     unit="degC"     />
+    	 <field id="bgmissal"     long_name="global mean salinity error due to free surface"                                                                                        unit="1e-3"     />
+      </field_group>
+
+      <!-- LIM3 scalar variables -->
+
+      <field_group id="SBC_scalar"  domain_ref="1point" >
+         <!-- available with ln_limdiaout -->
+         <field id="ibgvoltot"    long_name="global mean ice volume"                                 unit="km3"        />
+         <field id="sbgvoltot"    long_name="global mean snow volume"                                unit="km3"        />
+         <field id="ibgarea"      long_name="global mean ice area"                                   unit="km2"        />
+         <field id="ibgsaline"    long_name="global mean ice salinity"                               unit="1e-3"       />
+         <field id="ibgtemper"    long_name="global mean ice temperature"                            unit="degC"       />
+         <field id="ibgheatco"    long_name="global mean ice heat content"                           unit="10^20J"     />
+         <field id="sbgheatco"    long_name="global mean snow heat content"                          unit="10^20J"     />
+         <field id="ibgsaltco"    long_name="global mean ice salt content"                           unit="1e-3*km3"   />
+
+         <field id="ibgvfx"       long_name="global mean volume flux (emp)"                          unit="m/day"      />
+         <field id="ibgvfxbog"    long_name="global mean volume flux (bottom growth)"                unit="m/day"      />
+         <field id="ibgvfxopw"    long_name="global mean volume flux (open water growth)"            unit="m/day"      />
+         <field id="ibgvfxsni"    long_name="global mean volume flux (snow-ice growth)"              unit="m/day"      />
+         <field id="ibgvfxdyn"    long_name="global mean volume flux (dynamic growth)"               unit="m/day"      />
+         <field id="ibgvfxbom"    long_name="global mean volume flux (bottom melt)"                  unit="m/day"      />
+         <field id="ibgvfxsum"    long_name="global mean volume flux (surface melt)"                 unit="m/day"      />
+         <field id="ibgvfxres"    long_name="global mean volume flux (resultant)"                    unit="m/day"      />
+         <field id="ibgvfxspr"    long_name="global mean volume flux (snow precip)"                  unit="m/day"      />
+         <field id="ibgvfxsnw"    long_name="global mean volume flux (snow melt)"                    unit="m/day"      />
+         <field id="ibgvfxsub"    long_name="global mean volume flux (snow sublimation)"             unit="m/day"      />
+
+         <field id="ibgsfx"       long_name="global mean salt flux (total)"                          unit="1e-3*m/day" />
+         <field id="ibgsfxbri"    long_name="global mean salt flux (brines)"                         unit="1e-3*m/day" />
+         <field id="ibgsfxdyn"    long_name="global mean salt flux (dynamic)"                        unit="1e-3*m/day" />
+         <field id="ibgsfxres"    long_name="global mean salt flux (resultant)"                      unit="1e-3*m/day" />
+         <field id="ibgsfxbog"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
+         <field id="ibgsfxopw"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
+         <field id="ibgsfxsni"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
+         <field id="ibgsfxbom"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
+         <field id="ibgsfxsum"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
+         <field id="ibgsfxsub"    long_name="global mean salt flux (thermo)"                         unit="1e-3*m/day" />
+
+         <field id="ibghfxdhc"    long_name="Heat content variation in snow and ice"                 unit="W"          />
+         <field id="ibghfxspr"    long_name="Heat content of snow precip"                            unit="W"          />
+
+         <field id="ibghfxthd"    long_name="heat fluxes from ice-ocean exchange during thermo"      unit="W"          />
+         <field id="ibghfxsum"    long_name="heat fluxes causing surface ice melt"                   unit="W"          />
+         <field id="ibghfxbom"    long_name="heat fluxes causing bottom ice melt"                    unit="W"          />
+         <field id="ibghfxbog"    long_name="heat fluxes causing bottom ice growth"                  unit="W"          />
+         <field id="ibghfxdif"    long_name="heat fluxes causing ice temperature change"             unit="W"          />
+         <field id="ibghfxopw"    long_name="heat fluxes causing open water ice formation"           unit="W"          />
+         <field id="ibghfxdyn"    long_name="heat fluxes from ice-ocean exchange during dynamic"     unit="W"          />
+         <field id="ibghfxres"    long_name="heat fluxes from ice-ocean exchange during resultant"   unit="W"          />
+         <field id="ibghfxsub"    long_name="heat fluxes from sublimation"                           unit="W"          />
+         <field id="ibghfxsnw"    long_name="heat fluxes from snow-ocean exchange"                   unit="W"          />
+         <field id="ibghfxout"    long_name="non solar heat fluxes received by the ocean"            unit="W"          />
+         <field id="ibghfxin"     long_name="total heat fluxes at the ice surface"                   unit="W"          />
+
+         <field id="ibgfrcvol"    long_name="global mean forcing volume (emp)"                       unit="km3"        />
+         <field id="ibgfrcsfx"    long_name="global mean forcing salt   (sfx)"                       unit="1e-3*km3"   />
+         <field id="ibgvolgrm"    long_name="global mean ice growth+melt volume"                     unit="km3"        />
+      </field_group>
+  
+      <!-- variables available with key_float -->
+
+      <field_group id="floatvar" domain_ref="1point" axis_ref="nfloat" operation="instant" >
+        <field id="traj_lon"      long_name="floats longitude"                                                           unit="degrees_east"  />
+        <field id="traj_lat"      long_name="floats latitude"                                                            unit="degrees_north" />
+        <field id="traj_dep"      long_name="floats depth"                                                               unit="m"             />
+        <field id="traj_temp"     long_name="floats temperature"       standard_name="sea_water_potential_temperature"   unit="degC"          />
+        <field id="traj_salt"     long_name="floats salinity"          standard_name="sea_water_practical_salinity"      unit="1e-3"          />
+        <field id="traj_dens"     long_name="floats in-situ density"   standard_name="sea_water_density"                 unit="kg/m3"         />
+        <field id="traj_group"    long_name="floats group"                                                               unit="1"             />
+      </field_group>
+
+      <!-- variables available with iceberg trajectories -->
+
+      <field_group id="icbvar" grid_ref="grid_T_2D"  > 
+        <field id="berg_total_melt"    long_name="icb melt rate 2 of icebergs"                     unit="kg/m2/s"                    />
+        <field id="berg_total_heat_flux"  long_name="icb latent heat of melting of icebergs"          unit="kg/m2/s"                    />
+        <field id="berg_melt"          long_name="icb melt rate of icebergs"                       unit="kg/m2/s"                    />
+        <field id="berg_buoy_melt"     long_name="icb buoyancy component of iceberg melt rate"     unit="kg/m2/s"                    />
+        <field id="berg_eros_melt"     long_name="icb erosion component of iceberg melt rate"      unit="kg/m2/s"                    />
+        <field id="berg_conv_melt"     long_name="icb convective component of iceberg melt rate"   unit="kg/m2/s"                    />
+        <field id="berg_virtual_area"  long_name="icb virtual coverage by icebergs"                unit="m2"                         />
+        <field id="bits_src"           long_name="icb mass source of bergy bits"                   unit="kg/m2/s"                    />
+        <field id="bits_melt"          long_name="icb melt rate of bergy bits"                     unit="kg/m2/s"                    />
+        <field id="bits_mass"          long_name="icb bergy bit density field"                     unit="kg/m2"                      />
+        <field id="berg_mass"          long_name="icb iceberg density field"                       unit="kg/m2"                      />
+        <field id="calving"            long_name="icb calving mass input"                          unit="kg/s"                       />
+        <field id="berg_floating_melt" long_name="icb melt rate of icebergs + bits"                unit="kg/m2/s"                    />
+        <field id="berg_real_calving"  long_name="icb calving into iceberg class"                  unit="kg/s"     axis_ref="icbcla" />
+        <field id="berg_stored_ice"    long_name="icb accumulated ice mass by class"               unit="kg"       axis_ref="icbcla" />
+      </field_group>
+
+      <!-- Poleward transport : ptr -->     
+      <field_group id="diaptr" domain_ref="ptr" > 
+        <field id="zomsfglo"          long_name="Meridional Stream-Function: Global"           unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfatl"          long_name="Meridional Stream-Function: Atlantic"         unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfpac"          long_name="Meridional Stream-Function: Pacific"          unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfind"          long_name="Meridional Stream-Function: Indian"           unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zomsfipc"          long_name="Meridional Stream-Function: Pacific+Indian"   unit="Sv"       grid_ref="gznl_W_3D" />
+        <field id="zotemglo"          long_name="Zonal Mean Temperature : Global"              unit="degC"     grid_ref="gznl_T_3D" />
+        <field id="zotematl"          long_name="Zonal Mean Temperature : Atlantic"            unit="degC"     grid_ref="gznl_T_3D" />
+        <field id="zotempac"          long_name="Zonal Mean Temperature : Pacific"             unit="degC"     grid_ref="gznl_T_3D" />
+        <field id="zotemind"          long_name="Zonal Mean Temperature : Indian"              unit="degC"     grid_ref="gznl_T_3D" />
+        <field id="zotemipc"          long_name="Zonal Mean Temperature : Pacific+Indian"      unit="degC"     grid_ref="gznl_T_3D" />
+        <field id="zosalglo"          long_name="Zonal Mean Salinity : Global"                 unit="1e-3"     grid_ref="gznl_T_3D" />
+        <field id="zosalatl"          long_name="Zonal Mean Salinity : Atlantic"               unit="1e-3"     grid_ref="gznl_T_3D" />
+        <field id="zosalpac"          long_name="Zonal Mean Salinity : Pacific"                unit="1e-3"     grid_ref="gznl_T_3D" />
+        <field id="zosalind"          long_name="Zonal Mean Salinity : Indian"                 unit="1e-3"     grid_ref="gznl_T_3D" />
+        <field id="zosalipc"          long_name="Zonal Mean Salinity : Pacific+Indian"         unit="1e-3"     grid_ref="gznl_T_3D" />
+        <field id="zosrfglo"          long_name="Zonal Mean Surface"                           unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfatl"          long_name="Zonal Mean Surface : Atlantic"                unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfpac"          long_name="Zonal Mean Surface : Pacific"                 unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfind"          long_name="Zonal Mean Surface : Indian"                  unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="zosrfipc"          long_name="Zonal Mean Surface : Pacific+Indian"          unit="m2"       grid_ref="gznl_T_3D" />
+        <field id="sophtadv"          long_name="Advective Heat Transport"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sophtldf"          long_name="Diffusive Heat Transport"                     unit="PW"       grid_ref="gznl_T_2D" />
+        <field id="sopstadv"          long_name="Advective Salt Transport"                     unit="Giga g/s" grid_ref="gznl_T_2D" />
+        <field id="sopstldf"          long_name="Diffusive Salt Transport"                     unit="Giga g/s" grid_ref="gznl_T_2D" />
+      </field_group>
+
+    <!-- 
+============================================================================================================
+                  Physical ocean model trend diagnostics : temperature, KE, PE, momentum
+============================================================================================================
+    -->
+
+    <field_group id="trendT" grid_ref="grid_T_3D">
+      <!-- variables available with ln_tra_trd -->
+      <field id="ttrd_xad"      long_name="temperature-trend: i-advection"                                                                                          unit="degC/s"                        />
+      <field id="strd_xad"      long_name="salinity   -trend: i-advection"                                                                                          unit="1e-3/s"                        />
+      <field id="ttrd_yad"      long_name="temperature-trend: j-advection"                                                                                          unit="degC/s"                        />
+      <field id="strd_yad"      long_name="salinity   -trend: j-advection"                                                                                          unit="1e-3/s"                        />
+      <field id="ttrd_zad"      long_name="temperature-trend: k-advection"                                                                                          unit="degC/s"                        />
+      <field id="strd_zad"      long_name="salinity   -trend: k-advection"                                                                                          unit="1e-3/s"                        />
+      <field id="ttrd_ad"       long_name="temperature-trend: advection"               standard_name="tendency_of_sea_water_temperature_due_to_advection"           unit="degC/s"                         > sqrt( ttrd_xad^2 + ttrd_yad^2 + ttrd_zad^2 ) </field>
+      <field id="strd_ad"       long_name="salinity   -trend: advection"               standard_name="tendency_of_sea_water_salinity_due_to_advection"              unit="1e-3/s"                         > sqrt( strd_xad^2 + strd_yad^2 + strd_zad^2 ) </field>
+      <field id="ttrd_sad"      long_name="temperature-trend: surface adv. (no-vvl)"                                                                                unit="degC/s"   grid_ref="grid_T_2D" />
+      <field id="strd_sad"      long_name="salinity   -trend: surface adv. (no-vvl)"                                                                                unit="1e-3/s"   grid_ref="grid_T_2D" />
+      <field id="ttrd_ldf"      long_name="temperature-trend: lateral  diffusion"      standard_name="tendency_of_sea_water_temperature_due_to_horizontal_mixing"   unit="degC/s"                        />
+      <field id="strd_ldf"      long_name="salinity   -trend: lateral  diffusion"      standard_name="tendency_of_sea_water_salinity_due_to_horizontal_mixing"      unit="1e-3/s"                        />
+      <field id="ttrd_zdf"      long_name="temperature-trend: vertical diffusion"      standard_name="tendency_of_sea_water_temperature_due_to_vertical_mixing"     unit="degC/s"                        />
+      <field id="strd_zdf"      long_name="salinity   -trend: vertical diffusion"      standard_name="tendency_of_sea_water_salinity_due_to_vertical_mixing"        unit="1e-3/s"                        />
+
+      <!-- ln_traldf_iso=T only (iso-neutral diffusion) -->
+      <field id="ttrd_zdfp"     long_name="temperature-trend: pure vert. diffusion"   unit="degC/s" />
+      <field id="strd_zdfp"     long_name="salinity   -trend: pure vert. diffusion"   unit="1e-3/s" />
+
+      <!-- -->
+      <field id="ttrd_dmp"      long_name="temperature-trend: interior restoring"        unit="degC/s" />
+      <field id="strd_dmp"      long_name="salinity   -trend: interior restoring"        unit="1e-3/s" />
+      <field id="ttrd_bbl"      long_name="temperature-trend: bottom boundary layer"     unit="degC/s" />
+      <field id="strd_bbl"      long_name="salinity   -trend: bottom boundary layer"     unit="1e-3/s" />
+      <field id="ttrd_npc"      long_name="temperature-trend: non-penetrative conv."     unit="degC/s" />
+      <field id="strd_npc"      long_name="salinity   -trend: non-penetrative conv."     unit="1e-3/s" />
+      <field id="ttrd_qns"      long_name="temperature-trend: non-solar flux + runoff"   unit="degC/s" />
+      <field id="strd_cdt"      long_name="salinity   -trend: C/D term       + runoff"   unit="degC/s" />
+      <field id="ttrd_qsr"      long_name="temperature-trend: solar penetr. heating"     unit="degC/s" />
+      <field id="ttrd_bbc"      long_name="temperature-trend: geothermal heating"        unit="degC/s" />
+      <field id="ttrd_atf"      long_name="temperature-trend: asselin time filter"       unit="degC/s" />
+      <field id="strd_atf"      long_name="salinity   -trend: asselin time filter"       unit="1e-3/s" />
+
+      <!-- variables available with ln_KE_trd -->
+      <field id="ketrd_hpg"     long_name="ke-trend: hydrostatic pressure gradient"          unit="W/s^3"                        />
+      <field id="ketrd_spg"     long_name="ke-trend: surface     pressure gradient"          unit="W/s^3"                        />
+      <field id="ketrd_spgexp"  long_name="ke-trend: surface pressure gradient (explicit)"   unit="W/s^3"                        />
+      <field id="ketrd_spgflt"  long_name="ke-trend: surface pressure gradient (filter)"     unit="W/s^3"                        />
+      <field id="ssh_flt"       long_name="filtered contribution to ssh (dynspg_flt)"        unit="m"       grid_ref="grid_T_2D" />
+      <field id="w0"            long_name="surface vertical velocity"                        unit="m/s"     grid_ref="grid_T_2D" />
+      <field id="pw0_exp"       long_name="surface pressure flux due to ssh"                 unit="W/s^2"   grid_ref="grid_T_2D" />
+      <field id="pw0_flt"       long_name="surface pressure flux due to filtered ssh"        unit="W/s^2"   grid_ref="grid_T_2D" />
+      <field id="ketrd_keg"     long_name="ke-trend: KE gradient         or hor. adv."       unit="W/s^3"                        />
+      <field id="ketrd_rvo"     long_name="ke-trend: relative  vorticity or metric term"     unit="W/s^3"                        />
+      <field id="ketrd_pvo"     long_name="ke-trend: planetary vorticity"                    unit="W/s^3"                        />
+      <field id="ketrd_zad"     long_name="ke-trend: vertical  advection"                    unit="W/s^3"                        />
+      <field id="ketrd_udx"     long_name="ke-trend: U.dx[U]"                                unit="W/s^3"                        />
+      <field id="ketrd_ldf"     long_name="ke-trend: lateral   diffusion"                    unit="W/s^3"                        />
+      <field id="ketrd_zdf"     long_name="ke-trend: vertical  diffusion"                    unit="W/s^3"                        />
+      <field id="ketrd_tau"     long_name="ke-trend: wind stress "                           unit="W/s^3"   grid_ref="grid_T_2D" />
+      <field id="ketrd_bfr"     long_name="ke-trend: bottom friction (explicit)"             unit="W/s^3"                        />   
+      <field id="ketrd_bfri"    long_name="ke-trend: bottom friction (implicit)"             unit="W/s^3"                        />   
+      <field id="ketrd_atf"     long_name="ke-trend: asselin time filter trend"              unit="W/s^3"                        />  
+      <field id="ketrd_convP2K" long_name="ke-trend: conversion (potential to kinetic)"      unit="W/s^3"                        />
+      <field id="KE"            long_name="kinetic energy: u(n)*u(n+1)/2"                    unit="W/s^2"                        />   
+
+      <!-- variables available with ln_PE_trd -->
+      <field id="petrd_xad"     long_name="pe-trend: i-advection"                unit="W/m^3"                        />
+      <field id="petrd_yad"     long_name="pe-trend: j-advection"                unit="W/m^3"                        />
+      <field id="petrd_zad"     long_name="pe-trend: k-advection"                unit="W/m^3"                        />
+      <field id="petrd_sad"     long_name="pe-trend: surface adv. (no-vvl)"      unit="W/m^3"   grid_ref="grid_T_2D" />
+      <field id="petrd_ldf"     long_name="pe-trend: lateral  diffusion"         unit="W/m^3"                        />
+      <field id="petrd_zdf"     long_name="pe-trend: vertical diffusion"         unit="W/m^3"                        />
+      <field id="petrd_zdfp"    long_name="pe-trend: pure vert. diffusion"       unit="W/m^3"                        />
+      <field id="petrd_dmp"     long_name="pe-trend: interior restoring"         unit="W/m^3"                        />
+      <field id="petrd_bbl"     long_name="pe-trend: bottom boundary layer"      unit="W/m^3"                        />
+      <field id="petrd_npc"     long_name="pe-trend: non-penetrative conv."      unit="W/m^3"                        />
+      <field id="petrd_nsr"     long_name="pe-trend: surface forcing + runoff"   unit="W/m^3"                        />
+      <field id="petrd_qsr"     long_name="pe-trend: solar penetr. heating"      unit="W/m^3"                        />
+      <field id="petrd_bbc"     long_name="pe-trend: geothermal heating"         unit="W/m^3"                        />
+      <field id="petrd_atf"     long_name="pe-trend: asselin time filter"        unit="W/m^3"                        />
+      <field id="PEanom"        long_name="potential energy anomaly"             unit="1"                            />   
+      <field id="alphaPE"       long_name="partial deriv. of PEanom wrt T"       unit="degC-1"                       />   
+      <field id="betaPE"        long_name="partial deriv. of PEanom wrt S"       unit="1e3"                          />   
+    </field_group>
+
+    <field_group id="trendU" grid_ref="grid_U_3D">
+     <!-- variables available with ln_dyn_trd -->
+     <field id="utrd_hpg"       long_name="i-trend: hydrostatic pressure gradient"          unit="m/s^2"                        />
+     <field id="utrd_spg"       long_name="i-trend: surface     pressure gradient"          unit="m/s^2"                        />
+     <field id="utrd_spgexp"    long_name="i-trend: surface pressure gradient (explicit)"   unit="m/s^2"                        />
+     <field id="utrd_spgflt"    long_name="i-trend: surface pressure gradient (filtered)"   unit="m/s^2"                        />
+     <field id="utrd_keg"       long_name="i-trend: KE gradient         or hor. adv."       unit="m/s^2"                        />
+     <field id="utrd_rvo"       long_name="i-trend: relative  vorticity or metric term"     unit="m/s^2"                        />
+     <field id="utrd_pvo"       long_name="i-trend: planetary vorticity"                    unit="m/s^2"                        />
+     <field id="utrd_zad"       long_name="i-trend: vertical  advection"                    unit="m/s^2"                        />
+     <field id="utrd_udx"       long_name="i-trend: U.dx[U]"                                unit="m/s^2"                        />
+     <field id="utrd_ldf"       long_name="i-trend: lateral   diffusion"                    unit="m/s^2"                        />
+     <field id="utrd_zdf"       long_name="i-trend: vertical  diffusion"                    unit="m/s^2"                        />
+     <field id="utrd_tau"       long_name="i-trend: wind stress "                           unit="m/s^2"   grid_ref="grid_U_2D" />
+     <field id="utrd_bfr"       long_name="i-trend: bottom friction (explicit)"             unit="m/s^2"                        />   
+     <field id="utrd_bfri"      long_name="i-trend: bottom friction (implicit)"             unit="m/s^2"                        />   
+     <field id="utrd_tot"       long_name="i-trend: total momentum trend before atf"        unit="m/s^2"                        />   
+     <field id="utrd_atf"       long_name="i-trend: asselin time filter trend"              unit="m/s^2"                        />   
+    </field_group>
+
+    <field_group id="trendV" grid_ref="grid_V_3D">
+     <!-- variables available with ln_dyn_trd -->
+     <field id="vtrd_hpg"       long_name="j-trend: hydrostatic pressure gradient"          unit="m/s^2"                        />
+     <field id="vtrd_spg"       long_name="j-trend: surface     pressure gradient"          unit="m/s^2"                        />
+     <field id="vtrd_spgexp"    long_name="j-trend: surface pressure gradient (explicit)"   unit="m/s^2"                        />
+     <field id="vtrd_spgflt"    long_name="j-trend: surface pressure gradient (filtered)"   unit="m/s^2"                        />
+     <field id="vtrd_keg"       long_name="j-trend: KE gradient         or hor. adv."       unit="m/s^2"                        />
+     <field id="vtrd_rvo"       long_name="j-trend: relative  vorticity or metric term"     unit="m/s^2"                        />
+     <field id="vtrd_pvo"       long_name="j-trend: planetary vorticity"                    unit="m/s^2"                        />
+     <field id="vtrd_zad"       long_name="j-trend: vertical  advection"                    unit="m/s^2"                        />
+     <field id="vtrd_vdy"       long_name="i-trend: V.dx[V]"                                unit="m/s^2"                        />
+     <field id="vtrd_ldf"       long_name="j-trend: lateral   diffusion"                    unit="m/s^2"                        />
+     <field id="vtrd_zdf"       long_name="j-trend: vertical  diffusion"                    unit="m/s^2"                        />
+     <field id="vtrd_tau"       long_name="j-trend: wind stress "                           unit="m/s^2"   grid_ref="grid_V_2D" />
+     <field id="vtrd_bfr"       long_name="j-trend: bottom friction (explicit)"             unit="m/s^2"                        />   
+     <field id="vtrd_bfri"      long_name="j-trend: bottom friction (implicit)"             unit="m/s^2"                        />   
+     <field id="vtrd_tot"       long_name="j-trend: total momentum trend before atf"        unit="m/s^2"                        />   
+     <field id="vtrd_atf"       long_name="j-trend: asselin time filter trend"              unit="m/s^2"                        />   
+    </field_group>
+
+
+    <!-- 
+============================================================================================================
+                                        Definitions for iodef_demo.xml
+============================================================================================================
+    -->
+
+    <field_group id="mooring" >
+      <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"      />
+      <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                   />
+      <field field_ref="uoce"         name="uo"       long_name="sea_water_x_velocity"                 />
+      <field field_ref="voce"         name="vo"       long_name="sea_water_y_velocity"                 />
+      <field field_ref="woce"         name="wo"       long_name="sea_water_z_velocity"                 />
+      <field field_ref="avt"          name="difvho"   long_name="ocean_vertical_heat_diffusivity"      />
+      <field field_ref="avm"          name="difvmo"   long_name="ocean_vertical_momentum_diffusivity"  />
+   
+      <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+      <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"             />
+      <field field_ref="sstgrad"      name="tosgrad"  long_name="module_of_sea_surface_temperature_gradient"    />
+      <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+      <field field_ref="ssh"          name="zos"      long_name="sea_surface_height_above_geoid"                />
+      <field field_ref="empmr"        name="wfo"      long_name="water_flux_into_sea_water"                     />
+      <field field_ref="qsr"          name="rsntds"   long_name="surface_net_downward_shortwave_flux"           />
+      <field field_ref="qt"           name="tohfls"   long_name="surface_net_downward_total_heat_flux"          />
+      <field field_ref="taum"                                                                                   />
+      <field field_ref="20d"                                                                                    />
+      <field field_ref="mldkz5"                                                                                 />
+      <field field_ref="mldr10_1"                                                                               />
+      <field field_ref="mldr10_3"                                                                               />
+      <field field_ref="mldr0_1"                                                                                />
+      <field field_ref="mldr0_3"                                                                                />
+      <field field_ref="mld_dt02"                                                                               />
+      <field field_ref="topthdep"                                                                               />
+      <field field_ref="pycndep"                                                                                />
+      <field field_ref="tinv"                                                                                   />
+      <field field_ref="depti"                                                                                  />
+      <field field_ref="BLT"          name="blt"      long_name="barrier_layer_thickness"                       />
+      <field field_ref="utau"         name="tauuo"    long_name="surface_downward_x_stress"                     />
+      <field field_ref="vtau"         name="tauvo"    long_name="surface_downward_y_stress"                     />
+    </field_group>
+
+    <field_group id="groupT" >
+      <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"               />
+      <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                            />
+      <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+      <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"             />
+      <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+      <field field_ref="ssh"          name="zos"      long_name="sea_surface_height_above_geoid"                />
+      <field field_ref="empmr"        name="wfo"      long_name="water_flux_into_sea_water"                     />
+      <field field_ref="qsr"          name="rsntds"   long_name="surface_net_downward_shortwave_flux"           />
+      <field field_ref="qt"           name="tohfls"   long_name="surface_net_downward_total_heat_flux"          />
+      <field field_ref="taum"                                                                                   />
+      <field field_ref="20d"                                                                                    />
+      <field field_ref="mldkz5"                                                                                 />
+      <field field_ref="mldr10_1"                                                                               />
+      <field field_ref="mldr10_3"                                                                               />
+      <field field_ref="mld_dt02"                                                                               />
+      <field field_ref="topthdep"                                                                               />
+      <field field_ref="pycndep"                                                                                />
+      <field field_ref="tinv"                                                                                   />
+      <field field_ref="depti"                                                                                  />
+      <field field_ref="BLT"          name="blt"      long_name="Barrier Layer Thickness"                       />
+    </field_group>
+    
+    <field_group id="groupU" >
+      <field field_ref="uoce"         name="uo"      long_name="sea_water_x_velocity"      />
+      <field field_ref="ssu"          name="uos"     long_name="sea_surface_x_velocity"    />
+      <field field_ref="utau"         name="tauuo"   long_name="surface_downward_x_stress" />
+    </field_group>
+    
+    <field_group id="groupV" >
+      <field field_ref="voce"         name="vo"      long_name="sea_water_y_velocity"      />
+      <field field_ref="ssv"          name="vos"     long_name="sea_surface_y_velocity"    />
+      <field field_ref="vtau"         name="tauvo"   long_name="surface_downward_y_stress" />
+    </field_group>
+    
+    <field_group id="groupW" >
+      <field field_ref="woce"         name="wo"       long_name="ocean vertical velocity"  />
+    </field_group>
+    
+    <field_group id="groupT1" > 
+     <field field_ref="sst"          name="sosstsst"   standard_name="sea_surface_temperature"                                 />
+     <field field_ref="sss"          name="sossssss"   standard_name="sea_surface_salinity"                                    />
+     <field field_ref="ssh"          name="sossheig"   standard_name="sea_surface_height_above_geoid"                          />
+     <field field_ref="empmr"        name="sowaflup"   standard_name="water_flux_out_of_sea_ice_and_sea_water"                 />
+     <field field_ref="qt"           name="sohefldo"   standard_name="surface_downward_heat_flux_in_sea_water"                 />
+   </field_group>
+
+   <field_group id="groupT2" >
+     <field field_ref="toce"         name="votemper"     operation="instant" freq_op="1d" > @toce_e3t / @e3t </field>
+     <field field_ref="soce"         name="vosaline"     operation="instant" freq_op="1d" > @soce_e3t / @e3t </field>
+     <field field_ref="ssh"          name="sossheig"   standard_name="sea_surface_height_above_geoid"                          />
+     <field field_ref="empmr"        name="sowaflup"   standard_name="water_flux_out_of_sea_ice_and_sea_water"                 />
+     <field field_ref="runoffs"      name="sorunoff"   standard_name=""                                                        />
+     <field field_ref="saltflx"      name="sosafldo"   standard_name="salt_flux_into_sea_water"                                />
+     <field field_ref="qt"           name="sohefldo"   standard_name="surface_downward_heat_flux_in_sea_water"                 />
+     <field field_ref="qsr"          name="soshfldo"   standard_name="downwelling_photosynthetic_radiative_flux_in_sea_water"  />
+     <field field_ref="mldkz5" name="somixhgt" standard_name="ocean_mixed_layer_thickness_defined_by_vertical_tracer_diffusivity" />
+     <field field_ref="mldr10_1"     name="somxl010"   standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"      />
+     <field field_ref="ice_cover"    name="soicecov"   standard_name="sea_ice_area_fraction"                                   />
+     <field field_ref="wspd"         name="sowindsp"   standard_name="wind_speed"                                              />
+     <field field_ref="qrp"          name="sohefldp"   standard_name="heat_flux_into_sea_water_due_to_newtonian_relaxation"    />
+     <field field_ref="erp"          name="sowafldp"   standard_name="water_flux_out_of_sea_water_due_to_newtonian_relaxation" />
+     <field field_ref="qisf"         name="sohflisf"   standard_name=""                                                        />
+     <field field_ref="fwfisf"       name="sowflisf"   standard_name=""                                                        />
+   </field_group>
+
+   <field_group id="SPIN-UP_T" >
+     <field field_ref="e3t"          name="e3t"        standard_name="cell_thickness" />
+     <field field_ref="toce"         name="votemper"     operation="average" freq_op="10d" > @toce_e3t / @e3t </field>
+     <field field_ref="toce"         name="votemper2"    operation="average" freq_op="10d" > @toce * @toce_e3t / @e3t </field>
+     <field field_ref="soce"         name="vosaline"     operation="average" freq_op="10d" > @soce_e3t / @e3t </field>
+     <field field_ref="soce"         name="vosaline2"    operation="average" freq_op="10d" > @soce * @soce_e3t / @e3t </field>
+     <field field_ref="ttrd_ldf"     name="ttrd_ldf"   standard_name="tendency_of_sea_water_temperature_due_to_horizontal_mixing"/>
+     <field field_ref="ttrd_zdf"     name="ttrd_zdf"   standard_name="tendency_of_sea_water_temperature_due_to_vertical_mixing"/>
+     <field field_ref="strd_ldf"     name="strd_ldf"   standard_name="tendency_of_sea_water_salinity_due_to_horizontal_mixing" />
+     <field field_ref="strd_zdf"     name="strd_zdf"   standard_name="tendency_of_sea_water_salinity_due_to_vertical_mixing"   />
+     <field field_ref="ssh"          name="sossheig"   standard_name="sea_surface_height_above_geoid"                          />
+     <field field_ref="ssh2"         name="zossq"      standard_name="square_of_sea_surface_height_above_geoid"                />
+     <field field_ref="empmr"        name="sowaflup"   standard_name="water_flux_out_of_sea_ice_and_sea_water"                 />
+     <field field_ref="saltflx"      name="sosafldo"   standard_name="salt_flux_into_sea_water"                                />
+     <field field_ref="qt"           name="sohefldo"   standard_name="surface_downward_heat_flux_in_sea_water"                 />
+     <field field_ref="qsr"          name="soshfldo"   standard_name="downwelling_photosynthetic_radiative_flux_in_sea_water"               />
+     <field field_ref="mldkz5"       name="somixhgt"   standard_name="ocean_mixed_layer_thickness_defined_by_vertical_tracer_diffusivity"   />
+     <field field_ref="mldr10_1"     name="somxl010"   standard_name="ocean_mixed_layer_thickness_defined_by_sigma_theta"      />
+     <field field_ref="mldzint_1"    name="sokaraml"                                                                           />
+     <field field_ref="mldzint_2"    name="somlddbm"                                                                           />
+     <field field_ref="ice_cover"    name="soicecov"   standard_name="sea_ice_area_fraction"                                   />
+     <field field_ref="wspd"         name="sowindsp"   standard_name="wind_speed"                                              />          
+     <field field_ref="qisf"         name="sohflisf"   standard_name=""                                                        />
+     <field field_ref="fwfisf"       name="sowflisf"   standard_name=""                                                        />
+     <field field_ref="berg_total_melt"       name="berg_total_melt"          standard_name=""                                 />
+     <field field_ref="berg_total_heat_flux"  name="berg_total_heat_flux"     standard_name=""                                 />
+     <field field_ref="runoffs"      name="sorunoff"   standard_name="water_flux_into_sea_water_from_rivers"                   />
+   </field_group>
+
+   <field_group id="groupU1" >
+     <field field_ref="ssu"          name="sozocrtx"   standard_name="sea_surface_eastward_sea_water_velocity"                 />
+     <field field_ref="utau"         name="sozotaux"   standard_name="surface_downward_x_stress" />
+   </field_group>
+
+   <field_group id="groupU2" >
+     <field field_ref="uoce"         name="vozocrtx"     operation="instant" freq_op="1d" > @uoce_e3u / @e3u </field>
+     <field field_ref="utau"         name="sozotaux"   standard_name="surface_downward_x_stress" />
+   </field_group>
+
+   <field_group id="SPIN-UP_U" >
+     <field field_ref="e3u"          name="e3u"        standard_name="cell_thickness" />
+     <field field_ref="uoce"         name="vozocrtx"     operation="average" freq_op="10d" > @uoce_e3u / @e3u </field>
+     <field field_ref="uoce"         name="vozocrtx2"    operation="average" freq_op="10d" > @uoce * @uoce_e3u / @e3u </field>
+     <field field_ref="ut"           name="ut"           operation="average" freq_op="10d" > @ut_e3u / @e3u </field>
+     <field field_ref="us"           name="us"           operation="average" freq_op="10d" > @us_e3u / @e3u </field>
+     <field field_ref="utau"         name="sozotaux"   standard_name="surface_downward_x_stress" />   
+   </field_group>
+
+   <field_group id="groupV1" >
+     <field field_ref="ssv"          name="somecrty"   standard_name="sea_surface_northward_sea_water_velocity"                 />
+     <field field_ref="vtau"         name="sometauy"   standard_name="surface_downward_y_stress" />
+   </field_group>
+
+   <field_group id="groupV2" >
+     <field field_ref="voce"         name="vomecrty"     operation="instant" freq_op="1d" > @voce_e3v / @e3v </field>
+     <field field_ref="vtau"         name="sometauy"   standard_name="surface_downward_y_stress" />   
+   </field_group>
+
+   <field_group id="SPIN-UP_V" >
+     <field field_ref="e3v"          name="e3v"        standard_name="cell_thickness" />
+     <field field_ref="voce"         name="vomecrty"     operation="average" freq_op="10d" > @voce_e3v / @e3v </field>
+     <field field_ref="voce"         name="vomecrty2"    operation="average" freq_op="10d" > @voce * @voce_e3v / @e3v </field>
+     <field field_ref="vt"           name="vt"           operation="average" freq_op="10d" > @vt_e3v / @e3v </field>
+     <field field_ref="vs"           name="vs"           operation="average" freq_op="10d" > @vs_e3v / @e3v </field>
+     <field field_ref="vtau"         name="sometauy"   standard_name="surface_downward_y_stress" />
+   </field_group>
+
+   <field_group id="groupW2" >
+     <field field_ref="woce"         name="vovecrtz"   standard_name="upward_sea_water_velocity"                         />
+     <field field_ref="avt"          name="votkeavt"   standard_name="ocean_vertical_heat_diffusivity"                   />
+     <field field_ref="avm"          name="votkeavm"   standard_name="ocean_vertical_momentum_diffusivity"               />
+     <field field_ref="aht2d"        name="soleahtw"   standard_name="vertical_component_of_ocean_xy_tracer_diffusivity" />
+   </field_group>
+
+   <field_group id="SPIN-UP_W" >
+ <field field_ref="woce"         name="vovecrtz"   standard_name="upward_sea_water_velocity"                         />
+     <field field_ref="wt"           name="wt"         standard_name=""                                                  />
+     <field field_ref="ws"           name="ws"         standard_name=""                                                  />
+     <field field_ref="avt"          name="votkeavt"   standard_name="ocean_vertical_heat_diffusivity"                   />
+     <field field_ref="avm"          name="votkeavm"   standard_name="ocean_vertical_momentum_diffusivity"               />
+     <field field_ref="aht2d"        name="soleahtw"   standard_name="vertical_component_of_ocean_xy_tracer_diffusivity" />
+   </field_group>
+
+   <field_group id="SPIN-UP_diaptr" >
+     <field field_ref="zomsfglo"     name="zomsfglo"   standard_name="meridional_streamfunction_global"           grid_ref="gznl_W_3D"       />
+     <field field_ref="zotemglo"     name="zotemglo"   standard_name="zonal_mean_temperature_global"              grid_ref="gznl_T_3D"       />
+     <field field_ref="zosrfglo"     name="zosrfglo"   standard_name="zonal_mean_surface_global"                  grid_ref="gznl_T_3D"       />
+     <field field_ref="zosalglo"     name="zosalglo"   standard_name="zonal_mean_salinity_global"                 grid_ref="gznl_T_3D"       />          
+     <field field_ref="zomsfatl"     name="zomsfatl"   standard_name="meridional_streamfunction_atlantic"         grid_ref="gznl_W_3D"       />
+     <field field_ref="zotematl"     name="zotematl"   standard_name="zonal_mean_temperature_atlantic"            grid_ref="gznl_T_3D"       />
+     <field field_ref="zosrfatl"     name="zosrfatl"   standard_name="zonal_mean_surface_atlantic"                grid_ref="gznl_T_3D"       />
+     <field field_ref="zosalatl"     name="zosalatl"   standard_name="zonal_mean_salinity_atlantic"               grid_ref="gznl_T_3D"       />          
+     <field field_ref="zomsfpac"     name="zomsfpac"   standard_name="meridional_streamfunction_pacific"          grid_ref="gznl_W_3D"       />
+     <field field_ref="zotempac"     name="zotempac"   standard_name="zonal_mean_temperature_pacific"             grid_ref="gznl_T_3D"       />
+     <field field_ref="zosrfpac"     name="zosrfpac"   standard_name="zonal_mean_surface_pacific"                 grid_ref="gznl_T_3D"       />
+     <field field_ref="zosalpac"     name="zosalpac"   standard_name="zonal_mean_salinity_pacific"                grid_ref="gznl_T_3D"       />
+     <field field_ref="zomsfind"     name="zomsfind"   standard_name="meridional_streamfunction_indian"           grid_ref="gznl_W_3D"       />
+     <field field_ref="zotemind"     name="zotemind"   standard_name="zonal_mean_temperature_indian"              grid_ref="gznl_T_3D"       />
+     <field field_ref="zosrfind"     name="zosrfind"   standard_name="zonal_mean_surface_indian"                  grid_ref="gznl_T_3D"       />
+     <field field_ref="zosalind"     name="zosalind"   standard_name="zonal_mean_salinity_indian"                 grid_ref="gznl_T_3D"       />          
+     <field field_ref="zomsfipc"     name="zomsfipc"   standard_name="meridional_streamfunction_indian_pacific"   grid_ref="gznl_W_3D"       />
+     <field field_ref="zotemipc"     name="zotemipc"   standard_name="zonal_mean_temperature_indian_pacific"      grid_ref="gznl_T_3D"       />
+     <field field_ref="zosrfipc"     name="zosrfipc"   standard_name="zonal_mean_surface_indian_pacific"          grid_ref="gznl_T_3D"       />
+     <field field_ref="zosalipc"     name="zosalipc"   standard_name="zonal_mean_salinity_indian_pacific"         grid_ref="gznl_T_3D"       />          
+     <field field_ref="sophtadv"     name="sophtadv"   standard_name="advective_heat_transport"                   grid_ref="gznl_T_2D"       />
+     <field field_ref="sopstadv"     name="sopstadv"   standard_name="advective_salt_transport"                   grid_ref="gznl_T_2D"       />
+     <field field_ref="sophtldf"     name="sophtldf"   standard_name="diffusive_heat_transport"                   grid_ref="gznl_T_2D"       />
+     <field field_ref="sopstldf"     name="sopstldf"   standard_name="diffusive_salt_transport"                   grid_ref="gznl_T_2D"       />
+   </field_group>
+
+  </field_definition>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/iodef_medusa_et_al.xml
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/iodef_medusa_et_al.xml	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/iodef_medusa_et_al.xml	(revision 7693)
@@ -0,0 +1,199 @@
+<!-- GO6.0 version of the XIOS namelist -->
+<!-- XIOS2 version namelist -->
+
+<?xml version="1.0"?>
+<simulation> 
+
+ <context id="nemo" time_origin="1950-01-01 00:00:00" >
+    
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+    <field_definition src="./field_def.xml"/>
+    <field_definition src="./field_def_bgc.xml"/>
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="multiple_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".FALSE."> <!-- 6h files -->
+        <file id="file8" name_suffix="_UK_shelf" description="Forcings for the UK shelf seas model" >
+          <field field_ref="toce"         name="votemper"     grid_ref="grid_T_3D_zoom"    operation="instant" standard_name="sea_water_potential_temperature"/> 
+          <field field_ref="soce"         name="vosaline"     grid_ref="grid_T_3D_zoom"    operation="instant" standard_name="sea_water_salinity"/>   
+          <field field_ref="ssh"          name="sossheig"     grid_ref="grid_T_2D_zoom"    operation="instant" standard_name="sea_surface_height_above_geoid"/>
+          <field field_ref="uoce"         name="vozocrtx"     grid_ref="grid_U_3D_zoom"    operation="instant" standard_name="sea_water_x_velocity"/>
+          <field field_ref="voce"         name="vomecrty"     grid_ref="grid_V_3D_zoom"    operation="instant" standard_name="sea_water_y_velocity"/>
+          <field field_ref="ubar"         name="ubar"         grid_ref="grid_U_3D_zoom"    operation="instant" standard_name="ocean_barotropic_current_along_i-axis"/>
+          <field field_ref="vbar"         name="vbar"         grid_ref="grid_V_3D_zoom"    operation="instant" standard_name="ocean_barotropic_current_along_j-axis"/>
+        </file>
+      </file_group>
+     
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+
+      <file_group id="10d" output_freq="10d"  output_level="10" enabled=".TRUE.">  <!-- 10d files -->   
+    
+	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+          <field_group group_ref="SPIN-UP_T" />
+	</file>
+	
+	<file id="file2" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field_group group_ref="SPIN-UP_U" />	
+	</file>
+	
+	<file id="file3" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field_group group_ref="SPIN-UP_V" />
+	</file>
+
+	<file id="file4" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field_group group_ref="SPIN-UP_W" />
+	</file>
+	
+	<file id="file5" name_suffix="_diaptr" description="process diagnostics" >
+          <field_group group_ref="SPIN-UP_diaptr" />
+	</file>	
+	
+        <file id="file6" name_suffix="_ptrc_T" description="Medusa sms variables" >
+          <field_group group_ref="groupMEDUSA" />
+          <field_group group_ref="groupIDTRA" />
+          <field_group group_ref="groupCFC" />
+          <field_group group_ref="groupAGE" />
+        </file>
+
+        <file id="file7" name_suffix="_diad_T" description="Medusa diagnostic variables" >
+          <field_group group_ref="groupMEDUSA_dia" /> 
+          <field_group group_ref="groupMEDUSA_3dd" /> 
+          <field_group group_ref="groupMEDUSA_dms" />
+          <field_group group_ref="groupIDTRA_dia" />
+          <field_group group_ref="groupCFC_dia" />
+          <field_group group_ref="groupMEDUSA_cmip6" />
+        </file>
+       
+      </file_group>
+      
+  
+      <!-- file_group id="1m" output_freq="1mo" split_freq="1mo" output_level="10" enabled=".TRUE." -->  <!-- 1mo files -->   
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".FALSE.">  <!-- 1mo files -->   
+
+        <file id="file9" name_suffix="_grid_T" description="ocean T grid variables" >
+          <field_group group_ref="SPIN-UP_T" />
+	</file>
+	
+	<file id="file10" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field_group group_ref="SPIN-UP_U" />
+	</file>
+	
+	<file id="file11" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field_group group_ref="SPIN-UP_V" />
+	</file>
+	
+	<file id="file12" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field_group group_ref="SPIN-UP_W" />
+	</file>
+	
+	<file id="file13" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field_group group_ref="SPIN-UP_diaptr" />
+	</file>
+	
+        <file id="file14" name_suffix="_ptrc_T" description="Medusa sms variables" >
+          <field_group group_ref="groupMEDUSA" />
+          <field_group group_ref="groupIDTRA" />
+          <field_group group_ref="groupCFC" />
+          <field_group group_ref="groupAGE" />
+        </file>
+
+        <file id="file15" name_suffix="_diad_T" description="Medusa diagnostic variables" >
+          <field_group group_ref="groupMEDUSA_dia" /> 
+          <field_group group_ref="groupMEDUSA_3dd" /> 
+          <field_group group_ref="groupMEDUSA_dms" />
+          <field_group group_ref="groupIDTRA_dia" />
+          <field_group group_ref="groupCFC_dia" />
+          <field_group group_ref="groupMEDUSA_cmip6" />
+        </file>
+
+      </file_group>
+
+      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real yearly files -->
+      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
+    
+    <!-- 
+============================================================================================================
+= grid definition = = DO NOT CHANGE =
+============================================================================================================
+    -->
+
+   <axis_definition>
+      <axis id="deptht" standard_name="depth" long_name="Vertical T levels" unit="m" positive="down" />
+      <axis id="depthu" standard_name="depth" long_name="Vertical U levels" unit="m" positive="down" />
+      <axis id="depthv" standard_name="depth" long_name="Vertical V levels" unit="m" positive="down" />
+      <axis id="depthw" standard_name="depth" long_name="Vertical W levels" unit="m" positive="down" />
+      <axis id="nfloat" long_name="Float number"      unit="-"  />
+      <axis id="icbcla" long_name="Iceberg class"     unit="-"  />
+   </axis_definition>
+    
+   <domain_definition src="./domain_def.xml"/>
+   
+   <grid_definition>    
+     <grid id="grid_T_2D" domain_ref="grid_T"/>
+     <grid id="grid_T_3D" domain_ref="grid_T" axis_ref="deptht"/>
+     <grid id="grid_U_2D" domain_ref="grid_U"/>
+     <grid id="grid_U_3D" domain_ref="grid_U" axis_ref="depthu"/>
+     <grid id="grid_V_2D" domain_ref="grid_V"/>
+     <grid id="grid_V_3D" domain_ref="grid_V" axis_ref="depthv"/>
+     <grid id="grid_W_2D" domain_ref="grid_W"/>
+     <grid id="grid_W_3D" domain_ref="grid_W" axis_ref="depthw"/>
+     <grid id="grid_T_2D_zoom" domain_ref="zoomT"/>
+     <grid id="grid_T_3D_zoom" domain_ref="zoomT" axis_ref="deptht"/>
+     <grid id="grid_U_3D_zoom" domain_ref="zoomU" axis_ref="depthu"/>
+     <grid id="grid_V_3D_zoom" domain_ref="zoomV" axis_ref="depthv"/>
+     <grid id="gznl_T_2D" domain_ref="gznl"/>
+     <grid id="gznl_T_3D" domain_ref="gznl" axis_ref="deptht"/>
+     <grid id="gznl_W_3D" domain_ref="gznl" axis_ref="depthw"/>
+    </grid_definition>   
+  </context>
+  
+
+  <context id="xios">
+
+      <variable_definition>
+	
+     <!-- 
+        We must have buffer_size > jpi*jpj*jpk*8 (with jpi and jpj the subdomain size)
+-->
+	  <variable id="buffer_size"               type="integer">30000000</variable>
+	  <variable id="buffer_server_factor_size" type="integer">2</variable>
+	  <variable id="info_level"                type="integer">0</variable>
+	  <variable id="using_server"              type="boolean">true</variable>
+	  <variable id="using_oasis"               type="boolean">true</variable>
+	  <variable id="oasis_codes_id"            type="string" >toyoce</variable>
+	
+      </variable_definition>
+               
+  </context>
+  
+</simulation>
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_age_ref
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_age_ref	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_age_ref	(revision 7693)
@@ -0,0 +1,9 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! AGE  :       1  - dates                                 (namage)
+!! namelists
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&namage     !   dates
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+   rn_age_depth       = 10            ! depth over which age tracer reset to zero
+   rn_age_kill_rate   = -0.000138888  !  = -1/7200 recip of relaxation timescale (s) for  age tracer shallower than age_depth
+/
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_cfc_ref
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_cfc_ref	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_cfc_ref	(revision 7693)
@@ -7,5 +7,7 @@
 !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    ndate_beg  = 300101    !  datedeb1
-   nyear_res  = 1932      !  iannee1
+   nyear_res  = 1600      !  iannee1
+   simu_type  = 1         ! kind of Simulation: 1 = SPIN-UP (90y-cycle)
+!!                                           !! 2 = Hindcast/proj (100y cycle)
 /
 !'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_cfc_v1_ref
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_cfc_v1_ref	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_cfc_v1_ref	(revision 7693)
@@ -0,0 +1,20 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! CFC  :       1  - dates                                 (namcfcdate)
+!! namelists    
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&namcfcdate     !   dates
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+   ndate_beg  = 300101    !  datedeb1
+   nyear_res  = 1600      !  iannee1
+   simu_type  = 1         ! kind of Simulation: 1 = SPIN-UP (90y-cycle)
+!!                                           !! 2 = Hindcast/proj (100y cycle)
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&namcfcdia     !   additional 2D/3D tracers diagnostics 
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!              !    name   !           title of the field          !     units      !
+!              !           !                                       !                !
+   cfcdia2d(1)  = 'qtr_c11 ' , 'Air-sea flux of CFC-11           ',  'mol/m2/s    '
+   cfcdia2d(2)  = 'qint_c11' , 'Cumulative air-sea flux of CFC-11 ', 'mol/m2      '
+/
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_idtra_ref
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_idtra_ref	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_idtra_ref	(revision 7693)
@@ -0,0 +1,43 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+! idealize Tracer namelist :  NEMO idealize traceur model option and parameter input
+! -------------
+! 
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       namidtra   parameter for 1/2 decay time
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!! idealize tracer 1/2 decay time
+!!       tmp_decay   :  1/2 decay time
+!!
+!! idealize tracer names (to be added if needed)
+!!
+&namidtra
+!
+!! idealize tracer 1/2 decay time
+      tmp_decay = 10        !! years
+!! idealize tracer names
+!!###############################################
+!!   names are defined in the top namelist (namtrc) 
+!!   
+!!###############################################
+/
+!=================================================
+! nammeddia    Passive tracers additional diagnostics
+!=================================================
+!
+!      ctrc2d  : 2d output field name
+!      ctrc2u  : 2d output field unit
+!      ctrc2l  : 2d output field long name
+!
+!      nwriteadd: frequency of additional arrays outputs(namelist)
+!&nammeddia
+!!##########################################################
+!! No aditional diagnostics associated to idealize tracers.
+!! If one want to add additional diag, 
+!! can be done here, following the example just below 
+!!##########################################################
+!            meddia2d(1)  = 'INVTN'             ,              'Column N inventory'                            ,              'mmolN/m2'
+!            meddia2d(2)  = 'INVTSI'            ,              'Column Si inventory'                           ,              'mmolSi/m2'
+!/
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_medusa_ref
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_medusa_ref	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_medusa_ref	(revision 7693)
@@ -0,0 +1,372 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+! BIO namelist :  MEDUSA biological model option and parameter input
+! -------------
+!
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natbio   Shared parameters for dynamics/advection/thermo
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!! Primary production and chl related quantities
+!!       xxi         :  conversion factor from gC to mmolN 
+!!       xaln        :  Chl-a specific initial slope of P-I curve for non-diatoms 
+!!       xald        :  Chl-a specific initial slope of P-I curve for diatoms
+!!       jphy        :  phytoplankton T-dependent growth switch
+!!       xvpn        :  maximum growth rate for non-diatoms
+!!       xvpd        :  maximum growth rate for diatoms
+!!       xthetam     :  maximum Chl to C ratio for non-diatoms      
+!!       xthetamd    :  maximum Chl to C ratio for diatoms
+!!
+!! Diatom silicon parameters
+!!       xsin0       :  minimum diatom Si:N ratio
+!!       xnsi0       :  minimum diatom N:Si ratio
+!!       xuif        :  hypothetical growth ratio at infinite Si:N ratio
+!!
+!! Nutrient limitation
+!!       jliebig     :  Liebig nutrient uptake switch
+!!       xnln        :  half-sat constant for DIN uptake by non-diatoms 
+!!       xnld        :  half-sat constant for DIN uptake by diatoms 
+!!       xsl         :  half-sat constant for Si uptake by diatoms 
+!!       xfld        :  half-sat constant for Fe uptake by diatoms  
+!!       xfln        :  half-sat constant for Fe uptake by non-datoms 
+!!
+!! Grazing
+!!       xgmi        :  microzoo maximum growth rate 
+!!       xgme        :  mesozoo maximum growth rate 
+!!       xkmi        :  microzoo grazing half-sat parameter
+!!       xkme        :  mesozoo grazing half-sat parameter
+!!       xphi        :  micro/mesozoo grazing inefficiency
+!!       xbetan      :  micro/mesozoo N assimilation efficiency
+!!       xbetac      :  micro/mesozoo C assimilation efficiency
+!!       xkc         :  micro/mesozoo net C growth efficiency
+!!       xpmipn      :  grazing preference of microzoo for non-diatoms
+!!       xpmid       :  grazing preference of microzoo for diatoms
+!!       xpmepn      :  grazing preference of mesozoo for non-diatoms 
+!!       xpmepd      :  grazing preference of mesozoo for diatoms
+!!       xpmezmi     :  grazing preference of mesozoo for microzoo
+!!       xpmed       :  grazing preference of mesozoo for detritus
+!!
+!! Metabolic losses
+!!       xmetapn     :  non-diatom metabolic loss rate
+!!       xmetapd     :  diatom     metabolic loss rate
+!!       xmetazmi    :  microzoo   metabolic loss rate
+!!       xmetazme    :  mesozoo    metabolic loss rate
+!!
+!! Mortality losses
+!!       jmpn        :  non-diatom mortality functional form
+!!       xmpn        :  non-diatom mortality rate
+!!       xkphn       :  non-diatom mortality half-sat constant
+!!       jmpd        :  diatom     mortality functional form
+!!       xmpd        :  diatom     mortality rate
+!!       xkphd       :  diatom     mortality half-sat constant
+!!       jmzmi       :  microzoo   mortality functional form
+!!       xmzmi       :  microzoo   mortality rate
+!!       xkzmi       :  microzoo   mortality half-sat constant
+!!       jmzme       :  mesozoo    mortality functional form
+!!       xmzme       :  mesozoo    mortality rate
+!!       xkzme       :  mesozoo    mortality half-sat constant
+!!
+!! Remineralisation
+!!       jmd         :  detritus T-dependent remineralisation switch
+!!       jsfd        :  accelerate seafloor detritus remin. switch
+!!       xmd         :  detrital nitrogen remineralisation rate 
+!!       xmdc        :  detrital carbon   remineralisation rate 
+!!
+!! Stochiometric ratios
+!!       xthetapn    :  non-diatom C:N ratio
+!!       xthetapd    :  diatom C:N ratio
+!!       xthetazmi   :  microzoo C:N ratio
+!!       xthetazme   :  mesozoo C:N ratio
+!!       xthetad     :  detritus C:N ratio (FOR IMPLICIT DTC ONLY)
+!!       xrfn        :  phytoplankton Fe:N ratio
+!!	 xrsn        :  phytoplankton Si:N ratio (LEGACY; NOT USED)
+!!
+!! Iron parameters
+!!       jiron       :  iron scavenging submodel switch
+!!       xfe_mass    :  iron atomic mass
+!!	 xfe_sol     :  aeolian iron solubility
+!!	 xfe_sed     :  sediment iron input
+!!	 xLgT	     :  total ligand concentration (umol/m3)
+!!	 xk_FeL	     :  dissociation constant for (Fe + L)
+!!	 xk_sc_Fe    :  scavenging rate of "free" iron
+!!	 
+!! Fast-sinking detritus parameters
+!!       jmartin     :  fast detritus remineralisation switch
+!!       jfdfate     :  fate of fast detritus at seafloor switch
+!!       jrratio     :  rain ratio switch
+!!	 jocalccd    :  CCD switch
+!!	 xridg_r0    :  Ridgwell rain ratio coefficient
+!!       xfdfrac1    :  fast-sinking fraction of diatom nat. mort. losses
+!!       xfdfrac2    :  fast-sinking fraction of mesozooplankton mort. losses
+!!       xfdfrac3    :  fast-sinking fraction of diatom silicon grazing losses
+!!       xcaco3a     :  polar (high latitude) CaCO3 fraction
+!!       xcaco3b     :  equatorial (low latitude) CaCO3 fraction
+!!       xmassc      :  organic C mass:mole ratio, C106 H175 O40 N16 P1
+!!       xmassca     :  calcium carbonate mass:mole ratio, CaCO3
+!!       xmasssi     :  biogenic silicon mass:mole ratio, (H2SiO3)n
+!!       xprotca     :  calcium carbonate protection ratio
+!!       xprotsi     :  biogenic silicon protection ratio
+!!       xfastc      :  organic C remineralisation length scale
+!!       xfastca     :  calcium carbonate dissolution length scale
+!!       xfastsi     :  biogenic silicon dissolution length scale
+!!
+!! Benthos parameters
+!!       jorgben     :  does   organic detritus go to the benthos?
+!!       jinorgben   :  does inorganic detritus go to the benthos?
+!!       xsedn       :  organic   nitrogen sediment remineralisation rate 
+!!       xsedfe      :  organic   iron     sediment remineralisation rate 
+!!       xsedsi      :  inorganic silicon  sediment dissolution      rate 
+!!       xsedc       :  organic   carbon   sediment remineralisation rate 
+!!       xsedca      :  inorganic carbon   sediment dissolution      rate 
+!!       xburial     :  burial fraction of sediment material
+!!
+!! River parameters
+!!       jriver_n    :  riverine N          input?
+!!       jriver_si   :  riverine Si         input?
+!!       jriver_c    :  riverine C          input?
+!!       jriver_alk  :  riverine alkalinity input?
+!!       jriver_dep  :  depth of riverine   input?
+!!
+!! Miscellaneous
+!!       xsdiss      :  diatom frustule dissolution rate
+!!
+!! Gravitational sinking      
+!!       vsed        :  detritus gravitational sinking rate 
+!!       xhr         :  coeff for Martin's remineralisation profile
+!!
+!! Additional parameters
+!!       jpkb        :  vertical layer for diagnostic of the vertical flux 
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+!!       jdms        :  include dms diagnostics
+!!       jdms_input  :  use instant (0) or diel-avg (1) inputs
+!!       jdms_model  :  which DMS model is passed to atmosphere
+!!
+!!       
+&natbio
+!
+!! Primary production and chl related quantities
+      xxi       = 0.01257   !!
+      xaln      = 15.0      !! EKP (05/03/09)
+      xald      = 11.25     !! EKP (05/03/09)
+      jphy      = 1         !! 0 = T-independent; 1 = T-dependent; 2 = T-dependent-Q10
+      xvpn      = 0.640     !! EKP (05/03/09) -- daily avg = 0.530; daily cycle = 1.060; Q10 = 0.64
+      xvpd      = 0.600     !! EKP (05/03/09) -- daily avg = 0.500; daily cycle = 1.000; Q10 = 0.6
+      xthetam   = 0.05      !! EKP (05/03/09)
+      xthetamd  = 0.05      !! EKP (05/03/09)
+      jq10      = 1.50      !! Jpalm (17-06-2016)
+!!
+!! Diatom silicon parameters
+      xsin0     = 0.2       !! Mongin et al. (2003)
+      xnsi0     = 0.2       !! Mongin et al. (2003)
+      xuif      = 1.5       !! Mongin et al. (2003)
+!!
+!! Nutrient limitation
+      jliebig   = 0         !! 0 = multiplicative, 1 = Liebig
+      xnln      = 0.5       !! Fasham (1993)
+      xnld      = 0.75      !! EKP (05/03/09)
+      xsld      = 3.00      !! Fasham et al. (2006)-ish
+      xfln      = 0.00033   !! EKP (29/10/09); Parekh et al. (2005)
+      xfld      = 0.00067   !! EKP (29/10/09); Parekh et al. (2005); filtered through Moore et al. (2004)
+!!
+!! Grazing
+      xgmi      = 2.0       !! EKP (05/03/09)
+      xgme      = 0.5       !! AXY (21/12/09)
+      xkmi      = 0.8       !! EKP (26/02/09)
+      xkme      = 0.3       !! EKP (26/02/09)
+      xphi      = 0.20      !! Anderson & Pondaven (2003; 0.23); EKP (05/03/09; 0.20)
+      xbetan    = 0.77      !! Anderson & Pondaven (2003)
+      xbetac    = 0.64      !! Anderson & Pondaven (2003)
+!!    xbetan    = 0.69      !! compromise values inbetween those from ...
+!!    xbetac    = 0.69      !! Anderson & Pondaven (2003)for detrital carbon model
+      xkc       = 0.80      !! Anderson & Pondaven (2003)
+      xpmipn    = 0.75      !! 
+      xpmid     = 0.25      !!
+      xpmepn    = 0.15      !! EKP (26/02/09)
+      xpmepd    = 0.35      !! EKP (26/02/09)
+      xpmezmi   = 0.35      !! EKP (26/02/09)
+      xpmed     = 0.15      !! EKP (26/02/09)
+!!
+!! Metabolic losses
+      xmetapn   = 0.02      !! 
+      xmetapd   = 0.02      !! 
+      xmetazmi  = 0.02      !! 
+      xmetazme  = 0.02      !! 
+!!
+!! Mortality losses
+      jmpn      = 3         !! 1=linear; 2=quadratic; 3=hyperbolic; 4=sigmoid
+      xmpn      = 0.1       !!
+      xkphn     = 0.5       !! EKP (26/02/09): new parameter
+      jmpd      = 3         !! 1=linear; 2=quadratic; 3=hyperbolic; 4=sigmoid
+      xmpd      = 0.1       !!
+      xkphd     = 0.5       !! EKP (26/02/09): new parameter
+      jmzmi     = 3         !! 1=linear; 2=quadratic; 3=hyperbolic; 4=sigmoid
+      xmzmi     = 0.1       !!
+      xkzmi     = 0.5       !!
+      jmzme     = 3         !! 1=linear; 2=quadratic; 3=hyperbolic; 4=sigmoid
+      xmzme     = 0.2       !! EKP (26/02/09)
+      xkzme     = 0.75      !! EKP (26/02/09)
+!!
+!! Remineralisation
+      jmd       = 2         !! 0 = T-independent; 1 = T-dependent; 2 = T-dependent-Q10
+      jsfd      = 0         !! 0 = unchanged seafloor remin.; 1 = accelerated seafloor remin.
+      xmd       = 0.0190    !! T-dependent; 0.05 at 18C (Yool et al., 2010) - Q10 = 0.0190
+      xmdc      = 0.0152    !! T-dependent; 0.04 at 18C (Yool et al., 2010) - Q10 = 0.0152
+!! 
+!! Stochiometric ratios
+      xthetapn  = 6.625     !! Redfield
+      xthetapd  = 6.625     !! Redfield
+      xthetazmi = 5.625     !! Redfield
+      xthetazme = 5.625     !! Redfield
+!! AXY (26/11/08): implicit detrital carbon change
+      xthetad   = 6.625     !! Redfield
+      xrfn      = 30.0e-6   !! Parekh et al. (2005)
+      xrsn      = 1.0       !! not used here; retained for Lobster
+!!
+!! Iron parameters
+      jiron     = 1         !! iron scavenging submodel switch
+      xfe_mass  = 55.485    !! Fe atomic mass
+      xfe_sol   = 0.00532   !! scaled to get same input as Parekh et al. (2005)
+      xfe_sed   = 0.000228  !! AXY (10/07/12): Moore-ish
+      xLgT      = 1.0       !! from Diat-HadOCC; from Parekh et al. (2005)
+      xk_FeL	= 100.0     !! from Diat-HadOCC
+      xk_sc_Fe  = 1.e-3     !! from Dutkiewicz et al. (2005)
+!!
+!! Fast-sinking detritus parameters
+      jexport   = 1         !! 1 = ballast; 2 = Martin (1987); 3 = Henson (2011)
+      jfdfate   = 0         !! 0 = instant remin.; 1 = transmogrify into slow detritus
+      jrratio   = 2         !! 0 = Dunne (2005); 1 = Ridgwell (2007) surface; 2 = Ridgwell (2007) 3D
+      jocalccd  = 1         !! 0 = default, fixed; 1 = calculated, dynamic
+      xridg_r0  = 0.026     !! = 0.044, Ridgwell et al. (2007); scaled to 60% from preliminary sims
+      xfdfrac1  = 0.333     !! control parameter; no "real" value (AXY; 12/03/09)
+      xfdfrac2  = 1.00      !! control parameter; no "real" value (AXY; 12/03/09)
+      xfdfrac3  = 0.80      !! control parameter; no "real" value (AXY; 12/03/09)
+      xcaco3a   = 0.02      !! Dunne et al. (2005); not an exact value
+      xcaco3b   = 0.10      !! Dunne et al. (2005); not an exact value
+!! AXY (06/01/09): after contacting Dunne, new values are used for masses ...
+!!    xmassc    = 22.1188   !!
+!!    xmassca   = 100.086   !! original values; replaced by Dunne suggestion
+!!    xmasssi   = 78.0988   !!
+      xmassc    = 12.011    !! C atomic mass
+      xmassca   = 100.086   !! CaCO3; based on atomic masses
+      xmasssi   = 60.084    !! SiO2; based on atomic masses
+      xprotca   = 0.070     !! Dunne et al. (2005)
+      xprotsi   = 0.026     !! Dunne et al. (2005)
+      xfastc    = 188.0     !! Dunne et al. (2005)
+      xfastca   = 3500.0    !! Dunne et al. (2005)
+      xfastsi   = 2000.0    !! Dunne et al. (2005)
+!!
+!! Benthos parameters
+      jorgben   = 1         !! 0 = no; 1 = yes
+      jinorgben = 1         !! 0 = no; 1 = yes
+      xsedn     = 0.05      !! default ERSEM-ish value
+      xsedfe    = 0.05      !! default ERSEM-ish value
+      xsedsi    = 0.01      !! default ERSEM-ish value
+      xsedc     = 0.05      !! default ERSEM-ish value
+      xsedca    = 0.01      !! default ERSEM-ish value
+      xburial   = 0.0       !! set to zero
+!! 
+!! River parameters
+      jriver_n  = 0         !! 0 = no; 1 = runoff-dependent fluxes; 2= fixed fluxes
+      jriver_si = 0         !! 0 = no; 1 = runoff-dependent fluxes; 2= fixed fluxes
+      jriver_c  = 0         !! 0 = no; 1 = runoff-dependent fluxes; 2= fixed fluxes
+      jriver_alk= 0         !! 0 = no; 1 = runoff-dependent fluxes; 2= fixed fluxes
+      jriver_dep= 5         !! depth to which river nutrients are added
+!!
+!! Miscellaneous
+      xsdiss    = 0.006     !! Mongin et al. (2003); 0.006 is an alternative
+!!
+!! Gravitational sinking
+      vsed      = 3.472e-5  !! EKP (05/03/09)
+!!
+!! Additional parameters
+      jpkb      = 16        !! 
+!!
+!! UKESM1 - new diagnostics !! Jpalm
+      jdms       = 1        !! include dms diagnostics
+      jdms_input = 1        !! use instant (0) or diel-avg (1) inputs
+      jdms_model = 3        !! choice of DMS model passed to atmosphere
+!!                             1 = ANDR, 2 = SIMO, 3 = ARAN, 4 = HALL
+!!
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natroam
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!!       xthetaphy :  oxygen evolution/consumption by phytoplankton
+!!                    = (32 / 16) + (6.625 * (119 / 106)) = (2 + 7.4375) mol O2 / mol N
+!!       xthetazoo :  oxygen consumption by zooplankton
+!!                    = (32 / 16) + (5.625 * (119 / 106)) = (2 + 6.3149) mol O2 / mol N
+!!       xthetanit :  oxygen consumption by nitrogen remineralisation
+!!                    = (32 / 16) = 2 mol O2 / mol N
+!!       xthetarem :  oxygen consumption by carbon remineralisation
+!!                    = (119 / 106) = 1.1226 mol O2 / mol C
+!!       xo2min    :  oxygen minimum concentration
+!
+&natroam
+   xthetaphy = 9.4375
+   xthetazoo = 8.3149
+   xthetanit = 2.0
+   xthetarem = 1.1226
+   xo2min    = 4.0
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natopt
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!   xkg0 : green water absorption coefficient   [m-1]
+!   xkr0 : red water absorption coefficient     [m-1]
+!  xkgp  : pigment green absorption coefficient [m-1]
+!  xkrp  : pigment red absorption coefficient   [m-1]
+!  xlg   : green chl exposant
+!  xlr   : red chl exposant
+!  rpig  : chla / (chla+phea) ratio
+!
+&natopt
+   xkg0 = 0.0232
+   xkr0 = 0.225
+   xkgp = 0.074
+   xkrp = 0.037
+   xlg  = 0.629
+   xlr  = 0.674
+   rpig = 0.7
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natdbi used if key_trc_diabio is set
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  ctrbio    : array of biological trend numbers
+!  ctrbil    : character string describing each biological trend
+!  ctrbiu    : array of unit numbers used for trend output
+!  nwritebio : frequency of biological model output [timesteps]
+!
+&natdbi
+   ctrbio    = "BIO_01", "BIO_02", "BIO_03", "BIO_04", "BIO_05", "BIO_06", "BIO_07", "BIO_08", "BIO_09", "BIO_10", "BIO_11", "BIO_12", "BIO_13", "BIO_14", "BIO_15", "BIO_16", "BIO_17", "BIO_18", "BIO_19", "BIO_20", "BIO_21", "BIO_22", "BIO_23", "BIO_24", "BIO_25", "BIO_26", "BIO_27", "BIO_28", "BIO_29", "BIO_30", "BIO_31", "BIO_32", "BIO_33", "BIO_34"
+   ctrbil    = "BIO_01", "BIO_02", "BIO_03", "BIO_04", "BIO_05", "BIO_06", "BIO_07", "BIO_08", "BIO_09", "BIO_10", "BIO_11", "BIO_12", "BIO_13", "BIO_14", "BIO_15", "BIO_16", "BIO_17", "BIO_18", "BIO_19", "BIO_20", "BIO_21", "BIO_22", "BIO_23", "BIO_24", "BIO_25", "BIO_26", "BIO_27", "BIO_28", "BIO_29", "BIO_30", "BIO_31", "BIO_32", "BIO_33", "BIO_34"
+   ctrbiu    = "m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m","m"
+   nwritebio = 10
+!/
+!&natopt
+/
+!=================================================
+! nammeddia    Passive tracers additional diagnostics
+!=================================================
+!
+!      ctrc2d  : 2d output field name
+!      ctrc2u  : 2d output field unit
+!      ctrc2l  : 2d output field long name
+!
+!      nwriteadd: frequency of additional arrays outputs(namelist)
+&nammeddia
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nammedsbc     !   parameters for inputs deposition
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!              !  file name        ! frequency (hours) ! variable      ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                   !  (if <0  months)  !   name        !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_dust     = 'dust.orca'       ,     -1            , 'dust'        ,  .true.      , .true. , 'yearly'  , ''       , ''    , ''
+!
+   cn_dir      = './'      !  root directory for the location of the dynamical files
+   bdustfer    =  .true.   ! boolean for dust input from the atmosphere
+/
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_top_MEDUSA_et_al_cfg
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_top_MEDUSA_et_al_cfg	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_top_MEDUSA_et_al_cfg	(revision 7693)
@@ -0,0 +1,119 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/TOP1 :   - tracer run information                (namtrc_run)
+!!               - tracer definition                     (namtrc    )
+!!               - tracer data initialisation            (namtrc_dta)
+!!               - tracer advection                      (namtrc_adv)
+!!               - tracer lateral diffusion              (namtrc_ldf)
+!!               - tracer vertical physics               (namtrc_zdf)
+!!               - tracer newtonian damping              (namtrc_dmp)
+!!               - dynamical tracer trends               (namtrc_trd)
+!!               - tracer output diagonstics             (namtrc_dia)
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!-----------------------------------------------------------------------
+&namtrc_run     !   run information
+!-----------------------------------------------------------------------
+   nn_dttrc      =  1        !  time step frequency for passive sn_tracers
+   nn_writetrc   =  640     !  time step frequency for sn_tracer outputs
+   ln_top_euler  = .false.    !  use Euler time-stepping for TOP
+   ln_rsttr      = .false.   !  start from a restart file (T) or not (F)
+   nn_rsttr      =   0       !  restart control = 0 initial time step is not compared to the restart file value
+                           !                  = 1 do not use the value in the restart file
+                           !                  = 2 calendar parameters read in the restart file
+   cn_trcrst_in  = "restart_trc"   !  suffix of pass. sn_tracer restart name (input)
+   cn_trcrst_indir = "."           !  directory from which to read input passive tracer restarts
+   cn_trcrst_out = "restart_trc"   !  suffix of pass. sn_tracer restart name (output)
+   cn_trcrst_outdir = "."          !  directory to which to write output passive tracer restarts
+/
+!-----------------------------------------------------------------------
+&namtrc     !   tracers definition
+!-----------------------------------------------------------------------
+   ln_trcdta     =  .false.  !  Initialisation from data input file (T) or not (F)
+   ln_trcdmp     =  .false.  !  add a damping termn (T) or not (F)
+   ln_trcdmp_clo =  .false.  !  damping term (T) or not (F) on closed seas
+/
+!-----------------------------------------------------------------------
+&namtrc_dta      !    Initialisation from data input file
+!-----------------------------------------------------------------------
+!
+   cn_dir        =  './'      !  root directory for the location of the data files
+/
+!-----------------------------------------------------------------------
+&namtrc_adv    !   advection scheme for passive tracer 
+!-----------------------------------------------------------------------
+   ln_trcadv_cen2    =  .false.  !  2nd order centered scheme   
+   ln_trcadv_tvd     =  .true.  !  TVD scheme
+   ln_trcadv_muscl   =  .false.   !  MUSCL scheme
+   ln_trcadv_muscl2  =  .false.  !  MUSCL2 scheme + cen2 at boundaries
+   ln_trcadv_ubs     =  .false.  !  UBS scheme
+   ln_trcadv_qck     =  .false.  !  QUICKEST scheme
+   ln_trcadv_msc_ups =  .false.  !  use upstream scheme within muscl
+/
+!-----------------------------------------------------------------------
+&namtrc_ldf    !   lateral diffusion scheme for passive tracer 
+!-----------------------------------------------------------------------
+!                               !  Type of the operator : 
+   ln_trcldf_lap    =  .true.   !     laplacian operator       
+   ln_trcldf_bilap  =  .false.  !     bilaplacian operator     
+                                !  Direction of action  :
+   ln_trcldf_level  =  .false.  !     iso-level                
+   ln_trcldf_hor    =  .false.  !     horizontal (geopotential)         (require "key_ldfslp" when ln_sco=T)
+   ln_trcldf_iso    =  .true.   !     iso-neutral                       (require "key_ldfslp")
+!                               !  Coefficient
+   rn_ahtrc_0       =  2000.    !  horizontal eddy diffusivity for tracers [m2/s]
+   rn_ahtrb_0       =     0.    !     background eddy diffusivity for ldf_iso [m2/s]
+/
+!-----------------------------------------------------------------------
+&namtrc_zdf        !   vertical physics
+!-----------------------------------------------------------------------
+   ln_trczdf_exp   =  .false.  !  split explicit (T) or implicit (F) time stepping
+   nn_trczdf_exp   =   3       !  number of sub-timestep for ln_trczdfexp=T
+/
+!-----------------------------------------------------------------------
+&namtrc_rad        !  treatment of negative concentrations 
+!-----------------------------------------------------------------------
+   ln_trcrad   =  .true.  !  artificially correct negative concentrations (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namtrc_dmp    !   passive tracer newtonian damping   
+!-----------------------------------------------------------------------
+   nn_zdmp_tr  =    1      !  vertical   shape =0    damping throughout the water column
+                           !                   =1 no damping in the mixing layer (kz  criteria)
+                           !                   =2 no damping in the mixed  layer (rho crieria)
+   cn_resto_tr  = 'resto_tr.nc'    !  create a damping.coeff NetCDF file (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namtrc_ice       !    Representation of sea ice growth & melt effects
+!-----------------------------------------------------------------------
+   nn_ice_tr   =  -1        !  tracer concentration in sea ice 
+                           !    =-1 (no vvl: identical cc in ice and ocean / vvl: cc_ice = 0)
+                           !    = 0 (no vvl: cc_ice = zero / vvl: cc_ice = )
+                           !    = 1 prescribed to a namelist value (implemented in pisces only)
+/
+!-----------------------------------------------------------------------
+&namtrc_trd       !   diagnostics on tracer trends        ('key_trdtrc')
+!                          or mixed-layer trends          ('key_trdmld_trc')
+!----------------------------------------------------------------------
+   nn_trd_trc  =  640       !  time step frequency and tracers trends
+   nn_ctls_trc =   0        !  control surface type in mixed-layer trends (0,1 or n<jpk)
+   rn_ucf_trc  =   1        !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
+   ln_trdmld_trc_restart = .false.  !  restart for ML diagnostics
+   ln_trdmld_trc_instant = .true.  !  flag to diagnose trends of instantantaneous or mean ML T/S
+   ln_trdtrc(1)  =   .true.
+   ln_trdtrc(2)  =   .true.
+   ln_trdtrc(23) =   .true.
+/
+!-----------------------------------------------------------------------
+&namtrc_dia       !   parameters for passive tracer additional diagnostics
+!----------------------------------------------------------------------
+   ln_diatrc     =  .false.  !  save additional diag. (T) or not (F)
+   ln_diabio     =  .true.   !  output biological trends
+   nn_writedia   =  640      !  time step frequency for diagnostics
+   nn_writebio   =  640      !: frequency of biological outputs
+/
+!----------------------------------------------------------------------
+! namtrc_bc       !   data for boundary conditions
+!-----------------------------------------------------------------------
+&namtrc_bc
+!
+   cn_dir        =  './'      !  root directory for the location of the data files
+/
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_top_MEDUSA_et_al_ref
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_top_MEDUSA_et_al_ref	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/SHARED/namelist_top_MEDUSA_et_al_ref	(revision 7693)
@@ -0,0 +1,119 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/TOP1 :   - tracer run information                (namtrc_run)
+!!               - tracer definition                     (namtrc    )
+!!               - tracer data initialisation            (namtrc_dta)
+!!               - tracer advection                      (namtrc_adv)
+!!               - tracer lateral diffusion              (namtrc_ldf)
+!!               - tracer vertical physics               (namtrc_zdf)
+!!               - tracer newtonian damping              (namtrc_dmp)
+!!               - dynamical tracer trends               (namtrc_trd)
+!!               - tracer output diagonstics             (namtrc_dia)
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!-----------------------------------------------------------------------
+&namtrc_run     !   run information
+!-----------------------------------------------------------------------
+   nn_dttrc      =  1        !  time step frequency for passive sn_tracers
+   nn_writetrc   =  640     !  time step frequency for sn_tracer outputs
+   ln_top_euler  = .false.    !  use Euler time-stepping for TOP
+   ln_rsttr      = .false.   !  start from a restart file (T) or not (F)
+   nn_rsttr      =   0       !  restart control = 0 initial time step is not compared to the restart file value
+                           !                  = 1 do not use the value in the restart file
+                           !                  = 2 calendar parameters read in the restart file
+   cn_trcrst_in  = "restart_trc"   !  suffix of pass. sn_tracer restart name (input)
+   cn_trcrst_indir = "."           !  directory from which to read input passive tracer restarts
+   cn_trcrst_out = "restart_trc"   !  suffix of pass. sn_tracer restart name (output)
+   cn_trcrst_outdir = "."          !  directory to which to write output passive tracer restarts
+/
+!-----------------------------------------------------------------------
+&namtrc     !   tracers definition
+!-----------------------------------------------------------------------
+   ln_trcdta     =  .false.  !  Initialisation from data input file (T) or not (F)
+   ln_trcdmp     =  .false.  !  add a damping termn (T) or not (F)
+   ln_trcdmp_clo =  .false.  !  damping term (T) or not (F) on closed seas
+/
+!-----------------------------------------------------------------------
+&namtrc_dta      !    Initialisation from data input file
+!-----------------------------------------------------------------------
+!
+   cn_dir        =  './'      !  root directory for the location of the data files
+/
+!-----------------------------------------------------------------------
+&namtrc_adv    !   advection scheme for passive tracer 
+!-----------------------------------------------------------------------
+   ln_trcadv_cen2    =  .false.  !  2nd order centered scheme   
+   ln_trcadv_tvd     =  .true.  !  TVD scheme
+   ln_trcadv_muscl   =  .false.   !  MUSCL scheme
+   ln_trcadv_muscl2  =  .false.  !  MUSCL2 scheme + cen2 at boundaries
+   ln_trcadv_ubs     =  .false.  !  UBS scheme
+   ln_trcadv_qck     =  .false.  !  QUICKEST scheme
+   ln_trcadv_msc_ups =  .false.  !  use upstream scheme within muscl
+/
+!-----------------------------------------------------------------------
+&namtrc_ldf    !   lateral diffusion scheme for passive tracer 
+!-----------------------------------------------------------------------
+!                               !  Type of the operator : 
+   ln_trcldf_lap    =  .true.   !     laplacian operator       
+   ln_trcldf_bilap  =  .false.  !     bilaplacian operator     
+                                !  Direction of action  :
+   ln_trcldf_level  =  .false.  !     iso-level                
+   ln_trcldf_hor    =  .false.  !     horizontal (geopotential)         (require "key_ldfslp" when ln_sco=T)
+   ln_trcldf_iso    =  .true.   !     iso-neutral                       (require "key_ldfslp")
+!                               !  Coefficient
+   rn_ahtrc_0       =  2000.    !  horizontal eddy diffusivity for tracers [m2/s]
+   rn_ahtrb_0       =     0.    !     background eddy diffusivity for ldf_iso [m2/s]
+/
+!-----------------------------------------------------------------------
+&namtrc_zdf        !   vertical physics
+!-----------------------------------------------------------------------
+   ln_trczdf_exp   =  .false.  !  split explicit (T) or implicit (F) time stepping
+   nn_trczdf_exp   =   3       !  number of sub-timestep for ln_trczdfexp=T
+/
+!-----------------------------------------------------------------------
+&namtrc_rad        !  treatment of negative concentrations 
+!-----------------------------------------------------------------------
+   ln_trcrad   =  .true.  !  artificially correct negative concentrations (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namtrc_dmp    !   passive tracer newtonian damping   
+!-----------------------------------------------------------------------
+   nn_zdmp_tr  =    1      !  vertical   shape =0    damping throughout the water column
+                           !                   =1 no damping in the mixing layer (kz  criteria)
+                           !                   =2 no damping in the mixed  layer (rho crieria)
+   cn_resto_tr  = 'resto_tr.nc'    !  create a damping.coeff NetCDF file (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namtrc_ice       !    Representation of sea ice growth & melt effects
+!-----------------------------------------------------------------------
+   nn_ice_tr   =  -1        !  tracer concentration in sea ice 
+                           !    =-1 (no vvl: identical cc in ice and ocean / vvl: cc_ice = 0)
+                           !    = 0 (no vvl: cc_ice = zero / vvl: cc_ice = )
+                           !    = 1 prescribed to a namelist value (implemented in pisces only)
+/
+!-----------------------------------------------------------------------
+&namtrc_trd       !   diagnostics on tracer trends        ('key_trdtrc')
+!                          or mixed-layer trends          ('key_trdmld_trc')
+!----------------------------------------------------------------------
+   nn_trd_trc  =  640       !  time step frequency and tracers trends
+   nn_ctls_trc =   0        !  control surface type in mixed-layer trends (0,1 or n<jpk)
+   rn_ucf_trc  =   1        !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
+   ln_trdmld_trc_restart = .false.  !  restart for ML diagnostics
+   ln_trdmld_trc_instant = .true.  !  flag to diagnose trends of instantantaneous or mean ML T/S
+   ln_trdtrc(1)  =   .true.
+   ln_trdtrc(2)  =   .true.
+   ln_trdtrc(23) =   .true.
+/
+!-----------------------------------------------------------------------
+&namtrc_dia       !   parameters for passive tracer additional diagnostics
+!----------------------------------------------------------------------
+   ln_diatrc     =  .false.  !  save additional diag. (T) or not (F)
+   ln_diabio     =  .true.   !  output biological trends
+   nn_writedia   =  640      !  time step frequency for diagnostics
+   nn_writebio   =  640      !: frequency of biological outputs
+/
+!----------------------------------------------------------------------
+! namtrc_bc       !   data for boundary conditions
+!-----------------------------------------------------------------------
+&namtrc_bc
+!
+   cn_dir        =  './'      !  root directory for the location of the data files
+/
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/cfg.txt
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/cfg.txt	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/CONFIG/cfg.txt	(revision 7693)
@@ -11,2 +11,3 @@
 ORCA2_LIM OPA_SRC LIM_SRC_2 NST_SRC
 ORCA2_OFF_PISCES OPA_SRC OFF_SRC TOP_SRC
+ORCA2_OFF_MEDUSA OPA_SRC OFF_SRC TOP_SRC
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/OPA_SRC/TRD/trdtrc.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/OPA_SRC/TRD/trdtrc.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/OPA_SRC/TRD/trdtrc.F90	(revision 7693)
@@ -1,2 +1,3 @@
+#if ! defined key_top
 MODULE trdtrc
    !!======================================================================
@@ -22,2 +23,3 @@
    !!======================================================================
 END MODULE trdtrc
+#endif
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/par_age.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/par_age.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/par_age.F90	(revision 7693)
@@ -0,0 +1,83 @@
+MODULE par_age
+   !!======================================================================
+   !!                        ***  par_age  ***
+   !! TOP :   set the AGE parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_pisces , ONLY : jp_pisces       !: number of tracers in PISCES
+   USE par_pisces , ONLY : jp_pisces_2d    !: number of 2D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_3d    !: number of 3D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_trd   !: number of biological diag in PISCES
+
+   USE par_medusa , ONLY : jp_medusa       !: number of tracers in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_2d    !: number of 2D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_3d    !: number of 3D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_trd   !: number of biological diag in MEDUSA
+
+   USE par_idtra  , ONLY : jp_idtra        !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_2d     !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_3d     !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_trd    !: number of tracers in MEDUSA
+
+   USE par_cfc    , ONLY : jp_cfc          !: number of tracers in CFC
+   USE par_cfc    , ONLY : jp_cfc_2d       !: number of tracers in CFC
+   USE par_cfc    , ONLY : jp_cfc_3d       !: number of tracers in CFC
+   USE par_cfc    , ONLY : jp_cfc_trd      !: number of tracers in CFC
+
+   USE par_c14b   , ONLY : jp_c14b         !: number of tracers in C14
+   USE par_c14b   , ONLY : jp_c14b_2d      !: number of tracers in C14
+   USE par_c14b   , ONLY : jp_c14b_3d      !: number of tracers in C14
+   USE par_c14b   , ONLY : jp_c14b_trd     !: number of tracers in C14
+
+   IMPLICIT NONE
+
+   INTEGER, PARAMETER ::   jp_lm      =  jp_pisces     + jp_medusa     +            &
+                      jp_idtra      + jp_cfc     + jp_c14b     !:  cum. number of pass. tracers
+   INTEGER, PARAMETER ::   jp_lm_2d   =  jp_pisces_2d  + jp_medusa_2d  +            &
+                      jp_idtra_2d   + jp_cfc_2d  + jp_c14b_2d  !:
+   INTEGER, PARAMETER ::   jp_lm_3d   =  jp_pisces_3d  + jp_medusa_3d  +            &
+                      jp_idtra_3d   + jp_cfc_3d  + jp_c14b_3d  !:
+   INTEGER, PARAMETER ::   jp_lm_trd  =  jp_pisces_trd + jp_medusa_trd +            &
+                      jp_idtra_trd  + jp_cfc_trd + jp_c14b_trd !:
+
+#if defined key_age
+   !!---------------------------------------------------------------------
+   !!   'key_age'                     user defined tracers (AGE)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_age     = .TRUE.   !: PTS flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_age     =  1       !: number of PTS tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age_2d  =  0       !: additional 2d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_age_3d  =  0       !: additional 3d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_age_trd =  0       !: number of sms trends for AGE
+
+   ! assign an index in trc arrays for each PTS prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jpage1 = jp_lm + 1     !: 1st AGE tracer
+
+#else
+   !!---------------------------------------------------------------------
+   !!   Default                           No user defined tracers (AGE)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_age     = .FALSE.  !: AGE flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_age     =  0       !: No AGE tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age_2d  =  0       !: No AGE additional 2d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_age_3d  =  0       !: No AGE additional 3d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_age_trd =  0       !: number of sms trends for AGE
+#endif
+
+   ! Starting/ending PISCES do-loop indices (N.B. no PISCES : jpl_pcs < jpf_pcs the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_age0     = jp_lm     + 1              !: First index of AGE passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age1     = jp_lm     + jp_age      !: Last  index of AGE passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age0_2d  = jp_lm_2d  + 1              !: First index of AGE passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age1_2d  = jp_lm_2d  + jp_age_2d   !: Last  index of AGE passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age0_3d  = jp_lm_3d  + 1              !: First index of AGE passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age1_3d  = jp_lm_3d  + jp_age_3d   !: Last  index of AGE passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age0_trd = jp_lm_trd + 1              !: First index of AGE passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_age1_trd = jp_lm_trd + jp_age_trd  !: Last  index of AGE passive tracers
+
+   !!======================================================================
+END MODULE par_age
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcini_age.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcini_age.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcini_age.F90	(revision 7693)
@@ -0,0 +1,71 @@
+MODULE trcini_age
+   !!======================================================================
+   !!                         ***  MODULE trcini_age  ***
+   !! TOP :   initialisation of the AGE tracer
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (G. Nurser, G. Madec, C. Ethe ) Original code
+   !!----------------------------------------------------------------------
+#if defined key_age
+   !!----------------------------------------------------------------------
+   !!   'key_age'                                               AGE tracer
+   !!----------------------------------------------------------------------
+   !! trc_ini_age   : MY_TRC model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc
+   USE trc
+   USE trcsms_age
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_age   ! called by trcini.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$ 
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_ini_age
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ini_age  ***  
+      !!
+      !! ** Purpose :   initialization for AGE model
+      !!
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_age: passive tracer age'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+
+      rryear  = 1._wp / ( nyear_len(1) * rday )    ! recip number of seconds in one year
+
+      !! BUG in s-coordinate this does not work!
+      nlb_age = MINLOC( gdepw_1d, mask = gdepw_1d > rn_age_depth, dim = 1 ) ! shallowest W level Below age_depth
+                                                                            !  = shallowest T level wholly below age_depth
+
+      nl_age  = nlb_age - 1                                                 ! deepest    W level Above age_depth
+                                                                            !  = T level surrounding age_depth
+
+      nla_age = nl_age - 1                                                   ! deepest    T level wholly above age_depth
+
+      frac_kill_age = ( rn_age_depth - gdepw_1d(nl_age) ) / e3t_1d(nl_age)      ! fraction of level nl_age above age_depth
+      frac_add_age  = 1._wp -  frac_kill_age                                    ! fraction of level nl_age below age_depth
+
+      
+      IF( .NOT. ln_rsttr ) trn(:,:,:,jp_age0:jp_age1) = 0.
+      !
+   END SUBROUTINE trc_ini_age
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No AGE model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_age             ! Empty routine
+   END SUBROUTINE trc_ini_age
+#endif
+
+   !!======================================================================
+END MODULE trcini_age
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcnam_age.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcnam_age.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcnam_age.F90	(revision 7693)
@@ -0,0 +1,82 @@
+MODULE trcnam_age
+   !!======================================================================
+   !!                         ***  MODULE trcnam_age  ***
+   !! TOP :   initialisation of some run parameters for Age tracer
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) 
+   !!----------------------------------------------------------------------
+#if defined key_age
+   !!----------------------------------------------------------------------
+   !!   'key_age'                                               AGE tracers
+   !!----------------------------------------------------------------------
+   !! trc_nam_age      : AGE  tracer initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE trcsms_age      ! AGE specific variable
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_nam_age   ! called by trcnam.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nam_age
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_nam_age  ***
+      !!                 
+      !! ** Purpose :   Definition some run parameter for AGE model
+      !!
+      !! ** input   :   Namelist namage
+      !!----------------------------------------------------------------------
+      INTEGER ::  numnatg_ref = -1   ! Logical unit for reference AGE namelist
+      INTEGER ::  numnatg_cfg = -1   ! Logical unit for configuration AGE namelist
+      INTEGER ::  numong      = -1   ! Logical unit for output namelist
+      INTEGER :: ios                 ! Local integer output status for namelist read
+      INTEGER :: jl, jn
+      !!
+      NAMELIST/namage/ rn_age_depth, rn_age_kill_rate 
+      !!----------------------------------------------------------------------
+      !                             ! Open namelist files
+      CALL ctl_opn( numnatg_ref, 'namelist_age_ref'   ,     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      CALL ctl_opn( numnatg_cfg, 'namelist_age_cfg'   ,     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      IF(lwm) CALL ctl_opn( numong, 'output.namelist.age', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+
+      REWIND( numnatg_ref )              ! Namelist namagedate in reference namelist : AGE parameters
+      READ  ( numnatg_ref, namage, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namage in reference namelist', lwp )
+
+      REWIND( numnatg_cfg )              ! Namelist namagedate in configuration namelist : AGE parameters
+      READ  ( numnatg_cfg, namage, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namage in configuration namelist', lwp )
+      IF(lwm) WRITE ( numong, namage )
+
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' trc_nam_age: Read namage, namelist for Age passive tracer'
+         WRITE(numout,*) ' ~~~~~~~'
+         WRITE(numout,*) '  depth over which age tracer reset to zero                              rn_age_depth      = ', rn_age_depth 
+         WRITE(numout,*) '  recip of relax. timescale (s) for age tracer shallower than age_depth  rn_age_kill_rate  = ', rn_age_kill_rate 
+      ENDIF
+
+      IF(lwm) CALL FLUSH ( numong )     ! flush output namelist
+
+   END SUBROUTINE trc_nam_age
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                                No AGE
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nam_age                      ! Empty routine
+   END  SUBROUTINE  trc_nam_age
+#endif  
+
+   !!======================================================================
+END MODULE trcnam_age
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcsms_age.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcsms_age.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcsms_age.F90	(revision 7693)
@@ -0,0 +1,100 @@
+MODULE trcsms_age
+   !!======================================================================
+   !!                         ***  MODULE trcsms_age  ***
+   !! TOP :   Main module of the AGE tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!----------------------------------------------------------------------
+#if defined key_age
+   !!----------------------------------------------------------------------
+   !!   'key_age'                                               AGE tracer
+   !!----------------------------------------------------------------------
+   !! trc_sms_age       : AGE model main routine
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE trc             ! TOP variables
+   USE trd_oce
+   USE trdtrc
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sms_age       ! called by trcsms.F90 module
+
+   INTEGER , PUBLIC :: nl_age             ! T level surrounding age_depth
+   INTEGER , PUBLIC :: nla_age            ! T level wholly above age_depth
+   INTEGER , PUBLIC :: nlb_age            ! T level wholly below age_depth
+
+   REAL(wp), PUBLIC :: rn_age_depth       ! = 10       depth over which age tracer reset to zero
+   REAL(wp), PUBLIC :: rn_age_kill_rate   ! = -1./7200  recip of relaxation timescale (s) for  age tracer shallower than age_depth
+   
+   REAL(wp), PUBLIC :: rryear          !: recip number of seconds in one year
+   REAL(wp), PUBLIC :: frac_kill_age   !: fraction of level nl_age above age_depth where it is relaxed towards zero
+   REAL(wp), PUBLIC :: frac_add_age    !: fraction of level nl_age below age_depth where it is incremented
+
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_sms_age( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_sms_age  ***
+      !!
+      !! ** Purpose :   main routine of AGE model
+      !!
+      !! ** Method  : -
+      !!----------------------------------------------------------------------
+      !
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
+      INTEGER ::   jn, jk   ! dummy loop index
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrage
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('trc_sms_age')
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_sms_age:  AGE model'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+
+      IF( l_trdtrc )  CALL wrk_alloc( jpi, jpj, jpk, ztrage )
+
+      DO jk = 1, nla_age
+         tra(:,:,jk,jpage1) = rn_age_kill_rate * trb(:,:,jk,jpage1)
+      ENDDO
+      !
+      tra(:,:,nl_age,jpage1) = frac_kill_age * rn_age_kill_rate * trb(:,:,nl_age,jpage1)  &
+          &                  + frac_add_age  * rryear * tmask(:,:,nl_age)
+      !
+      DO jk = nlb_age, jpk
+         tra(:,:,jk,jpage1) = tmask(:,:,jk) * rryear
+      ENDDO
+      !
+      IF( l_trdtrc ) THEN      ! Save the trends in the mixed layer
+          DO jn = jp_age0, jp_age1
+            ztrage(:,:,:) = tra(:,:,:,jn)
+            CALL trd_trc( ztrage, jn, jptra_sms, kt )   ! save trends
+          END DO
+          CALL wrk_dealloc( jpi, jpj, jpk, ztrage )
+      END IF
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('trc_sms_age')
+      !
+   END SUBROUTINE trc_sms_age
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No AGE model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_sms_age( kt )             ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_sms_age: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sms_age
+#endif
+
+   !!======================================================================
+END MODULE trcsms_age
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcwri_age.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcwri_age.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/AGE/trcwri_age.F90	(revision 7693)
@@ -0,0 +1,62 @@
+MODULE trcwri_age
+   !!======================================================================
+   !!                       *** MODULE trcwri ***
+   !!    age :   Output of age tracers
+   !!======================================================================
+   !! History :   1.0  !  2009-05 (C. Ethe)  Original code
+   !!----------------------------------------------------------------------
+#if defined key_top && defined key_age && defined key_iomput
+   !!----------------------------------------------------------------------
+   !!   'key_age'                                           age model
+   !!----------------------------------------------------------------------
+   !! trc_wri_age   :  outputs of concentration fields
+   !!----------------------------------------------------------------------
+   USE par_age     
+   USE trc         
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_wri_age 
+
+#  include "top_substitute.h90"
+CONTAINS
+
+   SUBROUTINE trc_wri_age
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_wri_trc  ***
+      !!
+      !! ** Purpose :   output passive tracers fields 
+      !!---------------------------------------------------------------------
+      CHARACTER (len=20)   :: cltra
+      INTEGER              :: jn
+      !!---------------------------------------------------------------------
+
+ 
+      ! write the tracer concentrations in the file
+      ! ---------------------------------------
+      DO jn = jp_age0, jp_age1
+         cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
+         CALL iom_put( TRIM(cltra), trn(:,:,:,jn) )
+      END DO
+      !
+      !
+   END SUBROUTINE trc_wri_age
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+   PUBLIC trc_wri_age
+CONTAINS
+   SUBROUTINE trc_wri_age                     ! Empty routine  
+   END SUBROUTINE trc_wri_age
+#endif
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trcwri_age
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/C14b/par_c14b.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/C14b/par_c14b.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/C14b/par_c14b.F90	(revision 7693)
@@ -11,4 +11,14 @@
    USE par_pisces , ONLY : jp_pisces_trd   !: number of biological diag in PISCES
 
+   USE par_medusa , ONLY : jp_medusa       !: number of tracers in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_2d    !: number of 2D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_3d    !: number of 3D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_trd   !: number of biological diag in MEDUSA
+
+   USE par_idtra  , ONLY : jp_idtra        !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_2d     !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_3d     !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_trd    !: number of tracers in MEDUSA
+
    USE par_cfc    , ONLY : jp_cfc          !: number of tracers in CFC
    USE par_cfc    , ONLY : jp_cfc_2d       !: number of 2D diag in CFC
@@ -19,8 +29,12 @@
    IMPLICIT NONE
 
-   INTEGER, PARAMETER ::   jp_lb      =  jp_pisces     + jp_cfc     !: cum. number of pass. tracers
-   INTEGER, PARAMETER ::   jp_lb_2d   =  jp_pisces_2d  + jp_cfc_2d  !:
-   INTEGER, PARAMETER ::   jp_lb_3d   =  jp_pisces_3d  + jp_cfc_3d  !:
-   INTEGER, PARAMETER ::   jp_lb_trd  =  jp_pisces_trd + jp_cfc_trd !:
+   INTEGER, PARAMETER ::   jp_lb      =  jp_pisces     + jp_medusa     +   &
+                      jp_idtra      + jp_cfc                               !: cum. number of pass. tracers
+   INTEGER, PARAMETER ::   jp_lb_2d   =  jp_pisces_2d  + jp_medusa_2d  +   &
+                      jp_idtra_2d   + jp_cfc_2d  !:
+   INTEGER, PARAMETER ::   jp_lb_3d   =  jp_pisces_3d  + jp_medusa_3d  +   &
+                      jp_idtra_3d   + jp_cfc_3d  !:
+   INTEGER, PARAMETER ::   jp_lb_trd  =  jp_pisces_trd + jp_medusa_trd +   &
+                      jp_idtra_trd  + jp_cfc_trd !:
    
 #if defined key_c14b
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/par_cfc.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/par_cfc.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/par_cfc.F90	(revision 7693)
@@ -15,10 +15,24 @@
    USE par_pisces , ONLY : jp_pisces_trd   !: number of biological diag in PISCES
 
+   USE par_medusa , ONLY : jp_medusa       !: number of tracers in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_2d    !: number of 2D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_3d    !: number of 3D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_trd   !: number of biological diag in MEDUSA
+
+   USE par_idtra  , ONLY : jp_idtra        !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_2d     !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_3d     !: number of tracers in MEDUSA
+   USE par_idtra  , ONLY : jp_idtra_trd    !: number of tracers in MEDUSA
+
    IMPLICIT NONE
 
-   INTEGER, PARAMETER ::   jp_lc      =  jp_pisces     !: cumulative number of passive tracers
-   INTEGER, PARAMETER ::   jp_lc_2d   =  jp_pisces_2d  !:
-   INTEGER, PARAMETER ::   jp_lc_3d   =  jp_pisces_3d  !:
-   INTEGER, PARAMETER ::   jp_lc_trd  =  jp_pisces_trd !:
+   INTEGER, PARAMETER ::   jp_lc      =  jp_pisces     + jp_medusa     + &
+                      jp_idtra     !: cumulative number of passive tracers
+   INTEGER, PARAMETER ::   jp_lc_2d   =  jp_pisces_2d  + jp_medusa_2d  + &
+                      jp_idtra_2d !:
+   INTEGER, PARAMETER ::   jp_lc_3d   =  jp_pisces_3d  + jp_medusa_3d  + &
+                      jp_idtra_3d !:
+   INTEGER, PARAMETER ::   jp_lc_trd  =  jp_pisces_trd + jp_medusa_trd + &
+                      jp_idtra_trd !:
    
 #if defined key_cfc
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcnam_cfc.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcnam_cfc.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcnam_cfc.F90	(revision 7693)
@@ -49,5 +49,5 @@
       TYPE(DIAG), DIMENSION(jp_cfc_2d) :: cfcdia2d
       !!
-      NAMELIST/namcfcdate/ ndate_beg, nyear_res
+      NAMELIST/namcfcdate/ ndate_beg, nyear_res, simu_type 
       NAMELIST/namcfcdia/  cfcdia2d     ! additional diagnostics
       !!----------------------------------------------------------------------
@@ -72,4 +72,9 @@
          WRITE(numout,*) '    initial calendar date (aammjj) for CFC  ndate_beg = ', ndate_beg
          WRITE(numout,*) '    restoring time constant (year)          nyear_res = ', nyear_res
+         IF (simu_type==1) THEN
+            WRITE(numout,*) ' CFC running on SPIN-UP mode             simu_type = ', simu_type
+         ELSEIF (simu_type==2) THEN
+            WRITE(numout,*) ' CFC running on HINDCAST/PROJECTION mode simu_type = ', simu_type
+         ENDIF
       ENDIF
       nyear_beg = ndate_beg / 10000
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 7693)
@@ -15,4 +15,5 @@
    !!   cfc_init     :  sets constants for CFC surface forcing computation
    !!----------------------------------------------------------------------
+   USE dom_oce       ! ocean space and time domain
    USE oce_trc       ! Ocean variables
    USE par_trc       ! TOP parameters
@@ -31,4 +32,6 @@
    INTEGER , PUBLIC            ::   jpyear         ! Number of years read in CFC1112 file
    INTEGER , PUBLIC            ::   ndate_beg      ! initial calendar date (aammjj) for CFC
+   INTEGER , PUBLIC            ::   simu_type      ! Kind of simulation: 1- Spin-up 
+                                                   !                     2- Hindcast/projection
    INTEGER , PUBLIC            ::   nyear_res      ! restoring time constant (year)
    INTEGER , PUBLIC            ::   nyear_beg      ! initial year (aa) 
@@ -79,5 +82,5 @@
       !
       INTEGER  ::   ji, jj, jn, jl, jm, js
-      INTEGER  ::   iyear_beg, iyear_end
+      INTEGER  ::   iyear_beg, iyear_end, iyear_tmp
       INTEGER  ::   im1, im2, ierr
       REAL(wp) ::   ztap, zdtap        
@@ -103,5 +106,41 @@
       ! Temporal interpolation
       ! ----------------------
-      iyear_beg = nyear - 1900
+      !! JPALM -- 15-06-2016 -- define 2 kind of CFC run.
+      !!                     we want to make cycle experiments, 
+      !!                     to periodically compare the ocean dynamic within
+      !!                     1- the SPIN-UP and 2- Hincast/Projections
+      !!                     -- main difference is the way to define the year of
+      !!                     simulation, that determine the atm pCFC.
+      !!                     1-- Spin-up: our atm forcing is of 30y we cycle on.
+      !!                     So we do 90y CFC cycles to be in good
+      !!                     correspondance with the atmosphere
+      !!                     2-- Hindcast/proj, instead of nyear-1900 we keep
+      !!                     the 2 last digit, and enable 3 cycle from 1800 to 2100.  
+      !!----------------------------------------------------------------------
+      !! 1 -- SPIN-UP
+      IF (simu_type==1) THEN
+         iyear_tmp = nyear - nyear_res  !! JPALM -- in our spin-up, nyear_res is 1000
+         iyear_beg = MOD( iyear_tmp , 90 )
+         !! JPALM -- the pCFC file only got 78 years.
+         !!       So if iyear_beg > 78 then we set pCFC to 0
+         !!             iyear_beg = 0 as well -- must try to avoid obvious problems
+         !!             as Pcfc is set to 0.00 up to year 32, let set iyear_beg to year 10
+         !!          else, must add 30 to iyear_beg to match with P_cfc indices
+         !!---------------------------------------
+         IF ((iyear_beg > 77) .OR. (iyear_beg==0)) THEN
+            iyear_beg = 10
+         ELSE 
+            iyear_beg = iyear_beg + 30
+         ENDIF
+      !!
+      !! 2 -- Hindcast/proj
+      ELSEIF (simu_type==2) THEN
+         iyear_beg = MOD(nyear, 100)
+         IF (iyear_beg < 9)  iyear_beg = iyear_beg + 100
+         !! JPALM -- Same than previously, if iyear_beg is out of P_cfc range,
+         !!       we want to set p_CFC to 0.00 --> set iyear_beg = 10
+         IF ((iyear_beg < 30) .OR. (iyear_beg > 107)) iyear_beg = 10             
+      ENDIF
+      !!
       IF ( nmonth <= 6 ) THEN
          iyear_beg = iyear_beg - 1
@@ -176,14 +215,41 @@
          !                                                  !----------------!
       END DO                                                !  end CFC loop  !
-      !
-      IF( lrst_trc ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'trc_sms_cfc : cumulated input function fields written in ocean restart file ',   &
-            &                    'at it= ', kt,' date= ', ndastp
-         IF(lwp) WRITE(numout,*) '~~~~'
-         DO jn = jp_cfc0, jp_cfc1
-            CALL iom_rstput( kt, nitrst, numrtw, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jn) )
-         END DO
-      ENDIF                                            
+         !
+      IF( kt == nittrc000 ) THEN
+         DO jl = 1, jp_cfc   
+             WRITE(NUMOUT,*) ' '
+             WRITE(NUMOUT,*) 'CFC interpolation verification '  !! Jpalm  
+             WRITE(NUMOUT,*) '################################## '
+             WRITE(NUMOUT,*) ' '
+               if (jl.EQ.1) then
+                   WRITE(NUMOUT,*) 'Traceur = CFC11: '
+               elseif (jl.EQ.2) then
+                   WRITE(NUMOUT,*) 'Traceur = CFC12: '
+               endif
+             WRITE(NUMOUT,*) 'nyear    = ', nyear
+             WRITE(NUMOUT,*) 'nmonth   = ', nmonth
+             WRITE(NUMOUT,*) 'iyear_beg= ', iyear_beg
+             WRITE(NUMOUT,*) 'iyear_end= ', iyear_end
+             WRITE(NUMOUT,*) 'p_cfc(iyear_beg)= ',p_cfc(iyear_beg, 1, jl)
+             WRITE(NUMOUT,*) 'p_cfc(iyear_end)= ',p_cfc(iyear_end, 1, jl)
+             WRITE(NUMOUT,*) 'Im1= ',im1
+             WRITE(NUMOUT,*) 'Im2= ',im2
+             WRITE(NUMOUT,*) 'zpp_cfc = ',zpp_cfc
+             WRITE(NUMOUT,*) ' '
+         END DO  
+# if defined key_debug_medusa
+         CALL flush(numout)
+# endif
+      ENDIF
+        !
+      !IF( lrst_trc ) THEN
+      !   IF(lwp) WRITE(numout,*)
+      !   IF(lwp) WRITE(numout,*) 'trc_sms_cfc : cumulated input function fields written in ocean restart file ',   &
+      !      &                    'at it= ', kt,' date= ', ndastp
+      !   IF(lwp) WRITE(numout,*) '~~~~'
+      !   DO jn = jp_cfc0, jp_cfc1
+      !      CALL iom_rstput( kt, nitrst, numrtw, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jn) )
+      !   END DO
+      !ENDIF                                            
       !
       IF( lk_iomput ) THEN
@@ -203,4 +269,8 @@
       END IF
       !
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '   CFC - Check: nn_timing = ', nn_timing
+      CALL flush(numout)
+# endif
       IF( nn_timing == 1 )  CALL timing_stop('trc_sms_cfc')
       !
@@ -214,5 +284,5 @@
       !! ** Purpose : sets constants for CFC model
       !!---------------------------------------------------------------------
-      INTEGER :: jn
+      INTEGER :: jl, jn, iyear_beg, iyear_tmp
 
       ! coefficient for CFC11 
@@ -254,13 +324,52 @@
       sca(4,2) =  -0.067430
 
-      IF( ln_rsttr ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' Read specific variables from CFC model '
-         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
-         !
-         DO jn = jp_cfc0, jp_cfc1
-            CALL iom_get( numrtr, jpdom_autoglo, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jn) ) 
-         END DO
+      !!---------------------------------------------
+      !! JPALM -- re-initialize CFC fields and diags if restart a CFC cycle,
+      !!       Or if out of P_cfc range
+      IF (simu_type==1) THEN
+         iyear_tmp = nyear - nyear_res  !! JPALM -- in our spin-up, nyear_res is 1000
+         iyear_beg = MOD( iyear_tmp , 90 )
+         !!---------------------------------------
+         IF ((iyear_beg > 77) .OR. (iyear_beg==0)) THEN
+            qtr_cfc(:,:,:) = 0._wp
+            IF(lwp) THEN
+               WRITE(numout,*) 
+               WRITE(numout,*) 'restart a CFC cycle or out of P_cfc year bounds zero --'
+               WRITE(numout,*) '                          --    set qtr_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set qint_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set trn(CFC) = 0.00   --'
+            ENDIF
+            qtr_cfc(:,:,:) = 0._wp
+            qint_cfc(:,:,:) = 0._wp
+            DO jl = 1, jp_cfc
+              jn = jp_cfc0 + jl - 1
+              trn(:,:,:,jn) = 0._wp
+              trb(:,:,:,jn) = 0._wp
+            END DO
+         ENDIF
+      !!
+      !! 2 -- Hindcast/proj
+      ELSEIF (simu_type==2) THEN
+         iyear_beg = MOD(nyear, 100)
+         IF (iyear_beg < 9)  iyear_beg = iyear_beg + 100
+         IF ((iyear_beg < 30) .OR. (iyear_beg > 107)) THEN
+            qtr_cfc(:,:,:) = 0._wp
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) 'restart a CFC cycle or out of P_cfc year bounds zero --'
+               WRITE(numout,*) '                          --    set qtr_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set qint_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set trn(CFC) = 0.00   --'
+            ENDIF
+            qtr_cfc(:,:,:) = 0._wp
+            qint_cfc(:,:,:) = 0._wp
+            DO jl = 1, jp_cfc
+              jn = jp_cfc0 + jl - 1
+              trn(:,:,:,jn) = 0._wp
+              trb(:,:,:,jn) = 0._wp
+            END DO
+         ENDIF
       ENDIF
+
       IF(lwp) WRITE(numout,*)
       !
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90	(revision 7693)
@@ -0,0 +1,67 @@
+MODULE par_idtra
+   !!======================================================================
+   !!                        ***  par_idtra  ***
+   !! TOP :   set the IDEAL-TRACER parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   USE par_pisces , ONLY : jp_pisces       !: number of tracers in PISCES
+   USE par_pisces , ONLY : jp_pisces_2d    !: number of 2D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_3d    !: number of 3D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_trd   !: number of biological diag in PISCES
+
+   USE par_medusa , ONLY : jp_medusa       !: number of tracers in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_2d    !: number of 2D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_3d    !: number of 3D diag in MEDUSA
+   USE par_medusa , ONLY : jp_medusa_trd   !: number of biological diag in MEDUSA
+
+   IMPLICIT NONE
+
+   INTEGER, PARAMETER ::   jp_lp      =  jp_pisces     +  jp_medusa     !: cumulative number of passive tracers
+   INTEGER, PARAMETER ::   jp_lp_2d   =  jp_pisces_2d  +  jp_medusa_2d  !:
+   INTEGER, PARAMETER ::   jp_lp_3d   =  jp_pisces_3d  +  jp_medusa_3d  !:
+   INTEGER, PARAMETER ::   jp_lp_trd  =  jp_pisces_trd +  jp_medusa_trd !:
+
+#if defined key_idtra
+   !!---------------------------------------------------------------------
+   !!   'key_idtra'   :                                          Ideal tracers
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_idtra     = .TRUE.      !: IDEAL-TRACER flag
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra     =  1          !: number of passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_2d  =  3          !: additional 2d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_3d  =  0          !: additional 3d output arrays ('key_trc_diaadd')
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_trd =  0          !: number of sms trends for IDEAL-TRACER
+
+   ! assign an index in trc arrays for each IDEAL-TRACER prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jpidtra       = jp_lp + 1   !: IDEAL-TRACER
+#else
+   !!---------------------------------------------------------------------
+   !!   Default     :                                       No IDEAL-TRACER tracers
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_idtra     = .FALSE.     !: IDEAL-TRACER flag
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra     =  0          !: No IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_2d  =  0          !: No IDEAL-TRACER additional 2d output arrays
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_3d  =  0          !: No IDEAL-TRACER additional 3d output arrays
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra_trd =  0          !: number of sms trends for IDEAL-TRACER
+#endif
+
+   ! Starting/ending IDEAL-TRACER do-loop indices (N.B. no IDEAL-TRACER : jp_idtra0 > jp_idtra1 the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0     = jp_lp + 1                !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1     = jp_lp + jp_idtra         !: Last  index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0_2d  = jp_lp_2d  + 1            !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1_2d  = jp_lp_2d  + jp_idtra_2d  !: Last  index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0_3d  = jp_lp_3d  + 1            !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1_3d  = jp_lp_3d  + jp_idtra_3d  !: Last  index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra0_trd = jp_lp_trd + 0            !: First index of IDEAL-TRACER tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_idtra1_trd = jp_lp_trd + jp_idtra_trd !: Last  index of IDEAL-TRACER tracers
+
+   !!======================================================================
+END MODULE par_idtra
+
+
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcice_idtra.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcice_idtra.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcice_idtra.F90	(revision 7693)
@@ -0,0 +1,53 @@
+MODULE trcice_idtra
+   !!======================================================================
+   !!                         ***  MODULE trcice_idtra  ***
+   !! TOP :   Main module of the MY_TRC tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!----------------------------------------------------------------------
+#if defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                    IDEAL TRACER tracers
+   !!----------------------------------------------------------------------
+   !! trc_ice_idtra       : MY_TRC model main routine
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE oce_trc         ! Ocean variables
+   USE trc             ! TOP variables
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ice_ini_idtra       ! called by trcice.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_ice_ini_idtra
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ice_idtra  ***
+      !!
+      !! ** Purpose :   main routine of MY_TRC model
+      !!
+      !! ** Method  : -
+      !!----------------------------------------------------------------------
+      !
+      !
+   END SUBROUTINE trc_ice_ini_idtra
+
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No MY_TRC model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ice_ini_idtra             ! Empty routine
+   END SUBROUTINE trc_ice_ini_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcice_idtra
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90	(revision 7693)
@@ -0,0 +1,105 @@
+MODULE trcini_idtra
+   !!======================================================================
+   !!                         ***  MODULE trcini_idtra  ***
+   !! TOP :   initialisation of the IDEAL-TRACER tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trcini.idtra.h90
+   !!----------------------------------------------------------------------
+#if defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                               IDEAL-TRACER tracers
+   !!----------------------------------------------------------------------
+   !! trc_ini_idtra      : IDEAL-TRACER model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE trcsms_idtra    ! IDEAL-TRACER sms trends
+   ! USE par_idtra       ! IDEAL-TRACER parameters
+   ! USE in_out_manager  ! I/O manager
+   ! USE lib_mpp
+   ! USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_idtra   ! called by trcini.F90 module
+
+   INTEGER  ::   inum                   ! unit number
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE trc_ini_idtra
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ini_idtra  ***
+      !!
+      !! ** Purpose :   initialization for idtra model
+      !!
+      !! ** Method  : - Read the namidtra namelist and check the parameter values
+      !!----------------------------------------------------------------------
+      INTEGER  ::    jn, jl 
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_idtra: initialisation of Ideal Tracers model'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~'
+
+      IF( trc_sms_idtra_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trc_ini_idtra:unable to allocate CFC arrays' )
+
+
+      ! Initialization of trn in case of  no restart
+      !----------------------------------------------
+      qtr_idtra(:,:,:) = 0._wp
+      inv_idtra(:,:,:) = 0._wp
+      IF( .NOT. ln_rsttr ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'Initialization of id-tracers ; No restart : '
+            WRITE(numout,*) '                             ; Init field equal 1 at surface - zero elsewhere'
+            WRITE(numout,*) '                             ; qint idtra equal 0 '
+         ENDIF
+         qint_idtra(:,:,:) = 0._wp
+         DO jn = jp_idtra0, jp_idtra1
+             trn(:,:,:,jn) = 0.e0
+             trn(:,:,1,jn) = 1.0
+           IF(lwp) WRITE(numout,*) 'Idealise Tracer initialisation -- jn = ',jn
+         END DO
+      ENDIF
+
+
+      !   Ideal traceur do not need any atmospheric concentration.
+      ! We consider that sucface concentration is equal to 1,
+      ! that it is advectied within the water circulation,
+      ! and that it is regularly degraded as if it was a radiactive tracer (tricium for example)
+      ! But we can play with tha caracteristic time of
+      !--------------------------------------------------------------------
+
+
+
+      IF(lwp) WRITE(numout,*) 'Initialization of IDEAL-TRACER tracers done'
+      IF(lwp) WRITE(numout,*) ' '
+
+   END SUBROUTINE trc_ini_idtra
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                         No IDEAL-TRACER tracers
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_idtra             ! Empty routine
+
+
+   END SUBROUTINE trc_ini_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcini_idtra
+                                                
+
+
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90	(revision 7693)
@@ -0,0 +1,123 @@
+MODULE trcnam_idtra
+   !!======================================================================
+   !!                         ***  MODULE trcnam_idtra  ***
+   !! TOP :   initialisation of some run parameters for IDEAL-TRACER chemical model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) from trcnam.idtra.h90
+   !!----------------------------------------------------------------------
+#if defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                               IDEAL-TRACER tracers
+   !!----------------------------------------------------------------------
+   !! trc_nam_idtra      : IDEAL-TRACER model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE trcsms_idtra    ! IDEAL-TRACER specific variable
+   USE iom             ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_nam_idtra   ! called by trcnam.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nam_idtra
+      !!-------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_nam_idtra  ***
+      !!
+      !! ** Purpose :   Definition some run parameter for IDEAL-TRACER model
+      !!
+      !! ** Method  :   Read the namidtra namelist and check the parameter
+      !!       values called at the first timestep (nit000)
+      !!
+      !! ** input   :   Namelist namidtra
+      !!----------------------------------------------------------------------
+      INTEGER  :: numnatm_ref = -1   ! Logical unit for reference ID-TRA namelist
+      INTEGER  :: numnatm_cfg = -1   ! Logical unit for configuration ID-TRA namelist
+      INTEGER  :: numonc      = -1   ! Logical unit for output namelist
+      INTEGER  :: ios                 ! Local integer output status for namelist read
+      REAL(wp) :: tmp_decay          !! Years ; half time decay of our idealize tracer
+      REAL(wp) :: TDECyr, TDEC   
+      !! ----------------------------------------------------------------
+      NAMELIST/namidtra/tmp_decay
+      !!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+      !! Jpalm -- 4-11-2014
+      !! namelist for idealize tracer
+      !! only thing in namelist is the chosen half time decay
+      !! no atmospheric conditions, cause we do impose a surface concentration of 1,
+      !! and no additionnal diagnostics, 
+      !! because the only thing we are interested in is the water mass concentration on this tracer.
+      !!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_nam_idtra: read IDEAL-TRACER namelist'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      !!
+      !! Open the namelist file :
+      !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      CALL ctl_opn( numnatm_ref, 'namelist_idtra_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      CALL ctl_opn( numnatm_cfg, 'namelist_idtra_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      IF(lwm) CALL ctl_opn( numonc, 'output.namelist.idtra', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      !! Read the namelists :
+      !!~~~~~~~~~~~~~~~~~~~~~~~
+      !! First namelist of our idealize tracer :
+      !! read the decay 1/2 time of our tracer, to define in the namelist.
+      !! tmp_decay = 1y ; 10y ; 100y or 1000y depending of which water mass you want to track
+      !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+      REWIND( numnatm_ref )              ! Namelist namidtra in reference namelist : IDTRA parameters
+      READ  ( numnatm_ref, namidtra, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namidtra in reference namelist', lwp )
+
+      REWIND( numnatm_cfg )              ! Namelist namidtra in configuration namelist : IDTRA parameters
+      READ  ( numnatm_cfg, namidtra, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namidtra in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonc, namidtra )
+
+      IF(lwp) WRITE(numout,*) '   -  half time decay of our idealize tracer : ', tmp_decay
+
+      ! decroissance radioactive du traceur ideal
+      ! ---------------------------------------
+      ! TDECyr = 12.43/LOG(2.)             !! Tricium as example
+       TDECyr = tmp_decay/LOG(2.)          !! Idealise tracer -- with tmp_decay given in the idtracer namelist
+       TDEC = TDECyr*365.*24.*60.*60.      !! translate in second
+       FDEC = EXP( -rdt/TDEC )
+
+
+!! #if defined key_trc_diaadd  && ! defined key_iomput
+      !!
+      !!  -Here you can add tracers names to be read
+      !! in a namelist.
+      !!  -But this is not necessary with the iomput module
+      !! cause names are written in the Iodef file.
+      !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+!! #endif
+
+   END SUBROUTINE trc_nam_idtra
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                                No IDEAL-TRACER
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nam_idtra                      ! Empty routine
+   END  SUBROUTINE  trc_nam_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcnam_idtra
+
+
+
+
+
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90	(revision 7693)
@@ -0,0 +1,259 @@
+MODULE trcsms_idtra
+   !!======================================================================
+   !!                      ***  MODULE trcsms_idtra  ***
+   !! TOP : TRI main model
+   !!======================================================================
+   !! History :    -   !  1999-10  (JC. Dutay)  original code
+   !!             1.0  !  2004-03 (C. Ethe) free form + modularity
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  reorganisation
+   !!----------------------------------------------------------------------
+#if defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                               TRI tracers
+   !!----------------------------------------------------------------------
+   !!   trc_sms_idtra     :  compute and add TRI suface forcing to TRI trends
+   !!   trc_idtra_cst :  sets constants for TRI surface forcing computation
+   !!----------------------------------------------------------------------
+   USE oce_trc      ! Ocean variables
+   USE par_trc      ! TOP parameters
+   USE trc          ! TOP variables
+   USE trd_oce
+   USE trdtrc
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sms_idtra        ! called in ???
+   PUBLIC   trc_sms_idtra_alloc  ! called in ???
+   !
+   INTEGER , PUBLIC    ::   nyear_res      ! restoring time constant (year)
+   INTEGER , PUBLIC    ::   numnatm
+   REAL(wp), PUBLIC    ::   FDEC
+   !
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qtr_idtra  ! flux at surface
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   qint_idtra ! cumulative flux 
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   inv_idtra  ! vertic. inventory
+
+   !                          ! coefficients for conversion
+   REAL(wp) ::  WTEMP
+
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007)
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sms_idtra( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_sms_idtra  ***
+      !!
+      !! ** Purpose :   Compute the surface boundary contition on TRI 11
+      !!             passive tracer associated with air-mer fluxes and add it
+      !!             to the general trend of tracers equations.
+      !!
+      !! ** Method  : - get the atmospheric partial pressure - given in pico -
+      !!              - computation of solubility ( in 1.e-12 mol/l then in 1.e-9 mol/m3)
+      !!              - computation of transfert speed ( given in cm/hour ----> cm/s )
+      !!              - the input function is given by :
+      !!                speed * ( concentration at equilibrium - concentration at surface )
+      !!              - the input function is in pico-mol/m3/s and the
+      !!                TRI concentration in pico-mol/m3
+      !!               
+      !! *** For Idealized Tracers              
+      !!              - no need for any temporal references, 
+      !!              nor any atmospheric concentration, nor air -sea fluxes
+      !!              - Here we fixe surface concentration to 1.0 Tracer-Unit/m3
+      !!              - Then we add a decay (radioactive-like) to this tracer concentration 
+      !!              - the Half life deccay is chosen by the user, depending of the experiment. 
+      !!              
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in )  ::   kt    ! ocean time-step index
+      !!
+      INTEGER                ::   ji, jj, jn, jl, jk
+      REAL(wp)               ::   rlx                 !! relaxation time (1 day)
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('trc_sms_idtra')
+      !
+      rlx = 10./(60. * 60. * 24.)                              !! relaxation time (1/10 day)
+      IF (kt == nittrc000) THEN
+         IF(lwp) WRITE(numout,*) '   trcsms_idtra :'
+         IF(lwp) WRITE(numout,*) '   ~~~~~~~~~~~~~~~~~'
+         IF(lwp) WRITE(numout,*) '   - idtra decay factor : ', FDEC
+         IF(lwp) WRITE(numout,*) '   - relaxation time    : ', rlx
+# if defined key_debug_medusa
+         CALL flush(numout)
+# endif
+      !   CALL idtra_init
+      ENDIF
+
+         !
+      inv_idtra(:,:,:) = 0.0                                   !! init the inventory
+      qtr_idtra(:,:,:) = 0.0                                   !! init the air-sea flux
+      DO jl = 1, jp_idtra
+         jn = jp_idtra0 + jl - 1
+
+      !!   DO jj = 1, jpj
+      !!      DO ji = 1, jpi
+           DO jj = 2,jpjm1
+              DO ji = 2,jpim1
+
+         !! First, a crude version. will be much inproved later.
+             qtr_idtra(ji,jj,jl)  = rlx * (1. - trb(ji,jj,1,jn)) * tmask(ji,jj,1) *   & 
+                                  fse3t(ji,jj,1)                  !! Air-sea Flux
+
+           !! DEBUG-TEST : Set flux equal to 0, see if it induces the pb we see in the MED  
+           !!  qtr_idtra(ji,jj,jl)  = 0.0
+           ENDDO
+         ENDDO
+         tra(:,:,1,jn)      = tra(:,:,1,jn) + ( qtr_idtra(:,:,jl) *  &
+                            tmask(:,:,1) / fse3t(:,:,1) )
+         qint_idtra(:,:,jl) = qint_idtra(:,:,jl) +                   &           
+                              qtr_idtra(:,:,jl) * rdt              !! Cumulative Air-sea Flux
+
+
+         DO jk =1,jpk
+            inv_idtra(:,:,jl) = inv_idtra(:,:,jl) +                  &
+                     (trn(:,:,jk,jn) * fse3t(:,:,jk) * tmask(:,:,jk))  !! vertical inventory
+         ENDDO
+!
+!DECAY of OUR IDEALIZED TRACER
+! ---------------------------------------
+
+         DO  jk =1,jpk
+      !!      DO jj=1,jpj
+      !!        DO  ji =1,jpi
+            DO jj = 2,jpjm1
+               DO ji = 2,jpim1
+            
+                 !! IF (trn(ji,jj,jk,jn) > 0.0) THEN
+                    WTEMP = trn(ji,jj,jk,jn) * (1. - FDEC )
+                    tra(ji,jj,jk,jn) = (tra(ji,jj,jk,jn) - WTEMP/rdt ) * &
+                                     tmask(ji,jj,jk)
+                 !! ENDIF 
+              ENDDO 
+            ENDDO
+         ENDDO
+
+      ENDDO
+    !! jn loop
+!
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '   IDTRA - calculation part - DONE trc_sms_idtra -- '
+      CALL flush(numout)
+# endif
+        !
+        !! restart and diagnostics management -- 
+      !IF( lrst_trc ) THEN
+      !   IF(lwp) WRITE(numout,*)
+      !   IF(lwp) WRITE(numout,*) 'trc_sms_idtra : cumulated input function fields written in ocean restart file ',   &
+      !      &                    'at it= ', kt,' date= ', ndastp
+      !   IF(lwp) WRITE(numout,*) '~~~~'
+      !   !!DO jn = jp_idtra0, jp_idtra1
+      !      CALL iom_rstput( kt, nitrst, numrtw, 'qint_IDTRA', qint_idtra(:,:,1) )
+      !   !!END DO
+ ! if defined key_debug_medusa
+      !   IF(lwp) WRITE(numout,*) '   IDTRA - writing diag-restart - DONE trc_sms_idtra -- '
+      !   CALL flush(numout)
+ ! endif
+      !ENDIF
+      !
+      IF( lk_iomput ) THEN
+         CALL iom_put( "qtrIDTRA"  , qtr_idtra (:,:,1) )
+         CALL iom_put( "qintIDTRA" , qint_idtra(:,:,1) )
+         CALL iom_put( "invIDTRA" , inv_idtra(:,:,1) )
+      ELSE
+         IF( ln_diatrc ) THEN
+            trc2d(:,:,jp_idtra0_2d    ) = qtr_idtra (:,:,1)
+            trc2d(:,:,jp_idtra0_2d + 1) = qint_idtra(:,:,1)
+            trc2d(:,:,jp_idtra0_2d + 2) = inv_idtra(:,:,1)
+         END IF
+      END IF
+      !
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '   IDTRA - writing diag - DONE trc_sms_idtra -- '
+      CALL flush(numout)
+# endif
+      !
+      IF( l_trdtrc ) THEN
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '   IDTRA - writing trends - trc_sms_idtra -- '
+         CALL flush(numout)
+# endif
+          DO jn = jp_idtra0, jp_idtra1
+            CALL trd_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
+          END DO
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '   IDTRA - writing trends - DONE trc_sms_idtra -- '
+         CALL flush(numout)
+# endif
+      END IF
+      !
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '   IDTRA - Check: nn_timing = ', nn_timing 
+         CALL flush(numout)
+# endif
+      IF( nn_timing == 1 )  CALL timing_stop('trc_sms_idtra')
+      !
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '   IDTRA DONE trc_sms_idtra -- '
+      CALL flush(numout)
+# endif
+      !
+   END SUBROUTINE trc_sms_idtra
+
+   SUBROUTINE idtra_init
+      !!---------------------------------------------------------------------
+      !!                     ***  idtra_init  ***
+      !!
+      !! ** Purpose : read restart values for IDTRA model
+      !!---------------------------------------------------------------------
+      INTEGER :: jn
+
+      IF( ln_rsttr ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' Read specific variables from Ideal Tracers model '
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+         !
+         DO jn = jp_idtra0, jp_idtra1
+            CALL iom_get( numrtr, jpdom_autoglo, 'qint_IDTRA', qint_idtra(:,:,jn) )
+         END DO
+      ENDIF
+      IF(lwp) WRITE(numout,*) 'idtra restart variables read -- OK'
+      !
+   END SUBROUTINE idtra_init
+
+   INTEGER FUNCTION trc_sms_idtra_alloc()
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_sms_idtra_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( qtr_idtra (jpi,jpj,jp_idtra) ,     &
+         &      inv_idtra(jpi,jpj,jp_idtra)  ,     &
+         &      qint_idtra(jpi,jpj,jp_idtra) , STAT=trc_sms_idtra_alloc )
+         !
+      IF( trc_sms_idtra_alloc /= 0 ) CALL ctl_warn('trc_sms_idtra_alloc : failed to allocate arrays.')
+      !
+   END FUNCTION trc_sms_idtra_alloc
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                         No TRI tracers
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_sms_idtra( kt )       ! Empty routine
+      WRITE(*,*) 'trc_sms_idtra: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sms_idtra
+#endif
+
+   !!======================================================================
+END MODULE trcsms_idtra
+
+
+
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90	(revision 7693)
@@ -0,0 +1,63 @@
+MODULE trcwri_idtra
+   !!======================================================================
+   !!                       *** MODULE trcwri ***
+   !!    IDEALIZED Tracer :   Output of IDEALIZED Tracer tracers
+   !!======================================================================
+   !! History :   1.0  !  2009-05 (C. Ethe)  Original code
+   !!             1.1  !  2013-05 (A. Yool)  converted for MEDUSA
+   !!----------------------------------------------------------------------
+#if defined key_top && defined key_iomput && defined key_idtra
+   !!----------------------------------------------------------------------
+   !!   'key_idtra'                                           IDEALIZED Tracer model
+   !!----------------------------------------------------------------------
+   !! trc_wri_idtra   :  outputs of concentration fields
+   !!----------------------------------------------------------------------
+   ! USE oce_trc         ! Ocean variables
+   ! USE par_trc         ! TOP parameters
+   USE trc             ! passive tracers common variables
+   ! USE trcsms_idtra    ! IDEALIZE TRACER sms trends
+   USE iom             ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_wri_idtra
+
+CONTAINS
+
+   SUBROUTINE trc_wri_idtra
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_wri_trc  ***
+      !!
+      !! ** Purpose :   output passive tracers fields 
+      !!---------------------------------------------------------------------
+      CHARACTER (len=20)   :: cltra
+      INTEGER              :: jn
+      !!---------------------------------------------------------------------
+
+      ! write the tracer concentrations in the file
+      ! ---------------------------------------
+      DO jn = jp_idtra0, jp_idtra1
+         cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
+         CALL iom_put( cltra, trn(:,:,:,jn) )
+      END DO
+      !
+   END SUBROUTINE trc_wri_idtra
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+   PUBLIC trc_wri_idtra
+CONTAINS
+   SUBROUTINE trc_wri_idtra                     ! Empty routine  
+   END SUBROUTINE trc_wri_idtra
+#endif
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trcwri_idtra
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/gas_transfer.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/gas_transfer.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/gas_transfer.F90	(revision 7693)
@@ -0,0 +1,154 @@
+MODULE gastransfer
+   !!======================================================================
+   !!                         ***  MODULE trcdms_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2015-06  (A. Yool)             added for UKESM1 project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE in_out_manager  ! I/O manager
+
+      IMPLICIT NONE
+      PRIVATE
+
+      PUBLIC   gas_transfer  ! called by trcbio_medusa.F90 module
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+      subroutine gas_transfer(wind, N, eqn, kw660)
+! --------------------------------------------------------------------
+!  Gas transfer velocity
+! --------------------------------------------------------------------
+!
+! Title  : Calculates gas transfer velocity
+! Author : Andrew Yool
+! Date   : 15/10/04
+! 
+! This subroutine uses near-surface wind speed to calculate gas
+! transfer velocity for use in CO2 and O2 exchange calculations.
+!
+! Note that the parameterisation of Wanninkhof quoted here is a
+! truncation of the original equation.  It excludes a chemical
+! enhancement function (based on temperature), although such
+! temperature dependence is reported negligible by Etcheto & 
+! Merlivat (1988).
+!
+! Note also that in calculating scalar wind, the variance of the
+! wind over the period of a timestep is ignored.  Some authors,
+! for instance OCMIP-2, favour including some reference to the
+! variability of wind.  However, their wind fields are averaged
+! over relatively long time periods, and so this issue may be
+! safely (!) ignored here.
+! 
+! AXY (12/06/2015)
+! UPDATED: revised formulation from Wanninkhof (2014) update to
+! original 1992 paper. Full reference is:
+!
+! Wanninkhof, R. (2014). Relationship between wind speed and gas 
+! exchange over the ocean revisited. LIMNOLOGY AND OCEANOGRAPHY-METHODS
+! 12, 351-362, doi:10.4319/lom.2014.12.351
+! 
+! Subroutine inputs are (in order) : 
+!     wind      wind velocity at 10 m (m/s)
+!     N         size of input array (value 1 at this time)
+!     eqn       choice of parameterisation:
+!               1 = Liss & Merlivat (1986)    [approximated]
+!               2 = Wanninkhof (1992)         [sans enhancement]
+!               3 = Nightingale et al. (2000) [good]
+!               4 = Nightingale et al. (2000) [better]
+!               5 = Nightingale et al. (2000) [best]
+!               6 = OCMIP-2                   [sans variability]
+!               7 = Wanninkhof (2014)         [assumes 6h avg winds]
+! (*) k         gas transfer velocity (m/s)
+! 
+! Where (*) is the function output and (+) is a diagnostic output.
+!
+      implicit none
+
+      INTEGER, INTENT(in) :: N, eqn
+! Input variables
+!     real(kind=wp), INTENT(in),  DIMENSION(N) :: wind
+      real(wp), INTENT(in)  :: wind
+!
+! Output variables
+!     real(kind=wp), INTENT(out), DIMENSION(N) :: kw660
+      real(wp), INTENT(out) :: kw660
+!
+!     INTEGER :: eqn
+!
+! Coefficients for various parameterisations
+      real(wp) :: a(7)
+      real(wp) :: b(7)
+!
+!     real(wp), DIMENSION(N) :: tmp_k
+      real(wp) :: tmp_k
+!
+! Values of coefficients
+      data a(1) / 0.166 /  ! Liss & Merlivat (1986)    [approximated]
+      data a(2) / 0.3   /  ! Wanninkhof (1992)         [sans enhancement]
+      data a(3) / 0.23  /  ! Nightingale et al. (2000) [good]
+      data a(4) / 0.23  /  ! Nightingale et al. (2000) [better]
+      data a(5) / 0.222 /  ! Nightingale et al. (2000) [best]
+      data a(6) / 0.337 /  ! OCMIP-2                   [sans variability]
+      data a(7) / 0.251 /  ! Wanninkhof (2014)         [assumes 6h avg winds]
+!
+      data b(1) / 0.133 /
+      data b(2) / 0.0   /
+      data b(3) / 0.0   /
+      data b(4) / 0.1   /
+      data b(5) / 0.333 /
+      data b(6) / 0.0   /
+      data b(7) / 0.0   /
+!
+! Which parameterisation is to be used?
+!     eqn = 7
+!
+! Calculate gas transfer velocity (cm/h)
+      tmp_k = (a(eqn) * wind**2) + (b(eqn) * wind)
+!
+! Convert tmp_k from cm/h to m/s
+      kw660 = tmp_k / (100. * 3600.)
+!
+      return
+
+    end subroutine gas_transfer
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+
+CONTAINS
+
+   SUBROUTINE gas_transfer(wind, N, eqn, kw660)
+      USE par_kind
+
+      REAL(wp), INTENT( in )    :: wind
+      REAL(wp), INTENT( in )    :: kw660
+      INTEGER, INTENT(in) :: N, eqn
+
+      WRITE(*,*) 'gas_transfer: You should not have seen this print! error?', kt
+
+   END SUBROUTINE gas_transfer
+#endif
+
+   !!======================================================================
+END MODULE gastransfer
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_gasflux.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_gasflux.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_gasflux.F90	(revision 7693)
@@ -0,0 +1,242 @@
+MODULE mocsy_gasflux
+
+CONTAINS
+
+! --------------------------------------------------------------------
+!  Schmidt CO2 number
+! --------------------------------------------------------------------
+!
+! Title  : Calculates Schmidt number for ocean uptake of CO2
+! Author : Andrew Yool
+! Date   : 14/10/04
+!
+! This function calculates the Schmidt number for CO2 using sea surface
+! temperature.  The code is based upon that developed as part of the
+! OCMIP-2 project (1998-2000).  The coefficients used are taken from
+! Wanninkhof (1992, JGR, 97, 7373-7382).
+!
+! AXY (12/06/2015)
+! UPDATED: coefficients used below are now those from Wanninkhof (2014)
+! update to original 1992 paper. Full reference is:
+!
+! Winninkhof, R. (2014). Relationship between wind speed and gas 
+! exchange over the ocean revisited. LIMNOLOGY AND OCEANOGRAPHY-METHODS
+! 12, 351-362, doi:10.4319/lom.2014.12.351
+!
+! Check answer for the function at 20 degrees C is 668.
+!
+! Function inputs are (in order) :
+!     t            temperature (degrees C)
+! (*) co2_schmidt  carbon dioxide Schmidt number
+!
+! Where (*) is the function output.
+!
+      subroutine schmidt_co2(pt, N, co2_schmidt)
+
+      USE mocsy_singledouble
+
+      implicit none
+!
+      INTEGER, INTENT(in) :: N
+      real(kind=wp), INTENT(in),  DIMENSION(N) :: pt
+      real(kind=wp), INTENT(out), DIMENSION(N) :: co2_schmidt
+!
+      real(kind=wp)              :: a0, a1, a2, a3, a4
+!
+!     data a0 /    2073.1 /
+!     data a1 /   -125.62 /
+!     data a2 /    3.6276 /
+!     data a3 / -0.043219 /
+!
+      data a0 /    2116.8 /
+      data a1 /   -136.25 /
+      data a2 /    4.7353 /
+      data a3 / -0.092307 /
+      data a4 / 0.0007555 /
+!
+! Wanninkhof (1992)
+!     co2_schmidt = a0 + pt*(a1 + pt*(a2 + pt*a3))
+!
+! Wanninkhof (2014) adds in an extra term
+      co2_schmidt = a0 + pt*(a1 + pt*(a2 + pt*(a3 + pt*a4)))
+!
+      return
+
+      end subroutine schmidt_co2
+
+! --------------------------------------------------------------------
+!  Surface K0
+! --------------------------------------------------------------------
+!
+! Title  : Calculates surface K0 from surface T & S
+! Author : Andrew Yool
+! Date   : 18/06/15
+!
+! This function is derived from code included in the MOCSY package
+! produced by Jim Orr.
+!
+      subroutine surface_K0(ptmp, saln, N, K0)
+
+      USE mocsy_singledouble
+
+      implicit none
+!
+      INTEGER, INTENT(in) :: N
+      real(kind=wp), INTENT(in),  DIMENSION(N) :: ptmp, saln
+      real(kind=wp), INTENT(out), DIMENSION(N) :: K0
+!
+      real(kind=wp), DIMENSION(N) :: tk, invtk, tmp
+      real(kind=wp)               :: a0, a1, a2, a3, a4
+!
+      tk    = ptmp + 273.15d0
+      invtk = 1.0d0 / tk
+      tmp = (9345.17d0*invtk) - 60.2409d0 + (23.3585d0 * LOG(tk/100.0d0))
+      K0 = EXP( tmp + saln*(0.023517d0 - (0.00023656d0*tk) + (0.0047036e-4_wp*tk*tk)) )
+!
+      return
+
+      end subroutine surface_K0
+
+! --------------------------------------------------------------------
+!  Calculate xCO2
+! --------------------------------------------------------------------
+!
+!>    Compute xCO2 from arrays of pCO2atm, in situ T, S, & atm pressure
+SUBROUTINE pCO2atm2xCO2(pCO2atm, temp, salt, Patm, N, xCO2)
+  !    Purpose:
+  !    Compute xCO2 from arrays of pCO2atm, in situ T, S, & atm pressure
+
+  USE mocsy_singledouble
+
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, intent(in) :: N
+
+! INPUT variables
+  !> atmospheric partial pressure of CO2 [uatm] 
+  ! AXY (22/06/15): amended this next line to "in" as that's what it should be!
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: pCO2atm
+  !> in situ temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: temp
+  !> salinity [psu]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: salt
+  !> atmospheric pressure [atm]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: Patm
+!f2py optional , depend(temp) :: n=len(temp)
+
+! OUTPUT variables:
+  !> mole fraction of CO2 [ppm]
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: xCO2
+
+! LOCAL variables:
+  REAL(kind=wp) :: dpCO2atm, dPatm
+  REAL(kind=wp), DIMENSION(N) :: pH20
+  REAL(kind=wp) :: dxCO2
+
+  INTEGER :: i
+
+  call vapress(temp, salt, N, pH20)
+
+  DO i = 1,N
+     dpCO2atm  = DBLE(pCO2atm(i))
+     dPatm     = DBLE(Patm(i))
+     dxCO2     = dpCO2atm / (dPatm - pH20(i))
+     xCO2(i) = REAL(dxCO2)
+  END DO
+
+  RETURN
+END SUBROUTINE pCO2atm2xCO2
+
+! --------------------------------------------------------------------
+!  Calculate pCO2atm
+! --------------------------------------------------------------------
+!
+!>    Compute pCO2atm from arrays of xCO2, in situ T, S, & atm pressure
+SUBROUTINE x2pCO2atm(xCO2, temp, salt, Patm, N, pCO2atm)
+  !    Purpose:
+  !    Compute pCO2atm from arrays of xCO2, in situ T, S, & atm pressure
+
+  USE mocsy_singledouble
+
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, intent(in) :: N
+
+! INPUT variables
+  !> mole fraction of CO2 [ppm]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: xCO2
+  !> in situ temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: temp
+  !> salinity [psu]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: salt
+  !> atmospheric pressure [atm]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: Patm
+!f2py optional , depend(temp) :: n=len(temp)
+
+! OUTPUT variables:
+  !> oceanic partial pressure of CO2 [uatm] 
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: pCO2atm
+
+! LOCAL variables:
+  REAL(kind=wp) :: dxCO2, dPatm
+  REAL(kind=wp), DIMENSION(N) :: pH20
+  REAL(kind=wp) :: dpCO2atm
+
+  INTEGER :: i
+
+! Compute vapor pressure of seawater [in atm]
+  call vapress(temp, salt, N, pH20)
+
+  DO i = 1,N
+     dxCO2     = DBLE(xCO2(i))
+     dPatm     = DBLE(Patm(i))
+     dpCO2atm = (dPatm - pH20(i)) * dxCO2
+     pCO2atm(i) = REAL(dpCO2atm)
+  END DO
+
+  RETURN
+END SUBROUTINE x2pCO2atm
+
+! --------------------------------------------------------------------
+!  Calculate seawater vapor pressure
+! --------------------------------------------------------------------
+!
+!>    Compute vapor pressure of seawater (atm) following preocedure from Weiss & Price (1980)
+SUBROUTINE vapress(temp, salt, N, vpsw)
+  !    Purpose:
+  !    Compute vapor pressure of seawater (atm) following preocedure from Weiss & Price (1980)
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, intent(in) :: N
+
+! INPUT variables
+  !> in situ temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: temp
+  !> salinity [psu]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: salt
+!f2py optional , depend(temp) :: n=len(temp)
+
+! OUTPUT variables:
+  !> vapor pressure of seawater [atm] 
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: vpsw
+
+! LOCAL variables:
+  REAL(kind=wp) :: tk, dsalt
+
+  INTEGER :: i
+
+  DO i = 1,N
+     dsalt = DBLE(salt(i))
+     tk = 273.15d0 + DBLE(temp(i))     !Absolute temperature (Kelvin)
+     vpsw(i) = exp(24.4543d0 - 67.4509d0*(100.0d0/tk) - 4.8489d0*log(tk/100) - 0.000544d0*dsalt)
+  END DO
+
+  RETURN
+END SUBROUTINE vapress
+
+END MODULE mocsy_gasflux
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_mainmod.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_mainmod.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_mainmod.F90	(revision 7693)
@@ -0,0 +1,2063 @@
+MODULE mocsy_mainmod
+
+      USE in_out_manager  ! I/O manager
+
+CONTAINS
+
+! ----------------------------------------------------------------------
+!  SW_ADTG
+! ----------------------------------------------------------------------
+!
+!> \file sw_adtg.f90
+!! \BRIEF 
+!> Module with sw_adtg function - compute adiabatic temp. gradient from S,T,P
+!>  Function to calculate adiabatic temperature gradient as per UNESCO 1983 routines.
+FUNCTION sw_adtg  (s,t,p)
+
+  !     ==================================================================
+  !     Calculates adiabatic temperature gradient as per UNESCO 1983 routines.
+  !     Armin Koehl akoehl@ucsd.edu
+  !     ==================================================================
+  USE mocsy_singledouble
+  IMPLICIT NONE
+  !> salinity [psu (PSU-78)]
+  REAL(kind=wp) :: s
+  !> temperature [degree C (IPTS-68)]
+  REAL(kind=wp) :: t
+  !> pressure [db]
+  REAL(kind=wp) :: p
+
+  REAL(kind=wp) :: a0,a1,a2,a3,b0,b1,c0,c1,c2,c3,d0,d1,e0,e1,e2
+  REAL(kind=wp) :: sref
+
+  REAL(kind=wp) :: sw_adtg
+
+  sref = 35.d0
+  a0 =  3.5803d-5
+  a1 = +8.5258d-6
+  a2 = -6.836d-8
+  a3 =  6.6228d-10
+
+  b0 = +1.8932d-6
+  b1 = -4.2393d-8
+
+  c0 = +1.8741d-8
+  c1 = -6.7795d-10
+  c2 = +8.733d-12
+  c3 = -5.4481d-14
+
+  d0 = -1.1351d-10
+  d1 =  2.7759d-12
+
+  e0 = -4.6206d-13
+  e1 = +1.8676d-14
+  e2 = -2.1687d-16
+
+  sw_adtg =  a0 + (a1 + (a2 + a3*T)*T)*T &
+       + (b0 + b1*T)*(S-sref) &
+       + ( (c0 + (c1 + (c2 + c3*T)*T)*T) + (d0 + d1*T)*(S-sref) )*P &
+       + (  e0 + (e1 + e2*T)*T )*P*P
+
+END FUNCTION sw_adtg
+
+! ----------------------------------------------------------------------
+!  SW_ADTG
+! ----------------------------------------------------------------------
+!
+!> \file sw_ptmp.f90
+!! \BRIEF 
+!> Module with sw_ptmp function - compute potential T from in-situ T
+!> Function to calculate potential temperature [C] from in-situ temperature
+FUNCTION sw_ptmp  (s,t,p,pr)
+
+  !     ==================================================================
+  !     Calculates potential temperature [C] from in-situ Temperature [C]
+  !     From UNESCO 1983 report.
+  !     Armin Koehl akoehl@ucsd.edu
+  !     ==================================================================
+
+  !     Input arguments:
+  !     -------------------------------------
+  !     s  = salinity            [psu      (PSS-78) ]
+  !     t  = temperature         [degree C (IPTS-68)]
+  !     p  = pressure            [db]
+  !     pr = reference pressure  [db]
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+! Input arguments
+  !> salinity [psu (PSS-78)]
+  REAL(kind=wp) :: s
+  !> temperature [degree C (IPTS-68)]
+  REAL(kind=wp) :: t
+  !> pressure [db]
+  REAL(kind=wp) :: p
+  !> reference pressure  [db]  
+  REAL(kind=wp) :: pr
+
+! local arguments
+  REAL(kind=wp) :: del_P ,del_th, th, q
+  REAL(kind=wp) :: onehalf, two, three
+  PARAMETER (onehalf = 0.5d0, two = 2.d0, three = 3.d0 )
+
+! REAL(kind=wp) :: sw_adtg
+! EXTERNAL sw_adtg
+
+! Output 
+  REAL(kind=wp) :: sw_ptmp
+
+  ! theta1
+  del_P  = PR - P
+  del_th = del_P*sw_adtg(S,T,P)
+  th     = T + onehalf*del_th
+  q      = del_th
+
+  ! theta2
+  del_th = del_P*sw_adtg(S,th,P+onehalf*del_P)
+  th     = th + (1.d0 - 1.d0/SQRT(two))*(del_th - q)
+  q      = (two-SQRT(two))*del_th + (-two+three/SQRT(two))*q
+
+  ! theta3
+  del_th = del_P*sw_adtg(S,th,P+onehalf*del_P)
+  th     = th + (1.d0 + 1.d0/SQRT(two))*(del_th - q)
+  q      = (two + SQRT(two))*del_th + (-two-three/SQRT(two))*q
+
+  ! theta4
+  del_th = del_P*sw_adtg(S,th,P+del_P)
+  sw_ptmp     = th + (del_th - two*q)/(two*three)
+
+  RETURN
+END FUNCTION sw_ptmp
+
+
+! ----------------------------------------------------------------------
+!  SW_TEMP
+! ----------------------------------------------------------------------
+!
+!> \file sw_temp.f90
+!! \BRIEF 
+!> Module with sw_temp function - compute in-situ T from potential T
+!> Function to compute in-situ temperature [C] from potential temperature [C]
+FUNCTION sw_temp( s, t, p, pr )
+  !     =============================================================
+  !     SW_TEMP
+  !     Computes in-situ temperature [C] from potential temperature [C]
+  !     Routine available in seawater.f (used for MIT GCM)
+  !     Downloaded seawater.f (on 17 April 2009) from
+  !     http://ecco2.jpl.nasa.gov/data1/beaufort/MITgcm/bin/
+  !     =============================================================
+
+  !     REFERENCES:
+  !     Fofonoff, P. and Millard, R.C. Jr
+  !     Unesco 1983. Algorithms for computation of fundamental properties of
+  !     seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp.
+  !     Eqn.(31) p.39
+
+  !     Bryden, H. 1973.
+  !     "New Polynomials for thermal expansion, adiabatic temperature gradient
+  !     and potential temperature of sea water."
+  !     DEEP-SEA RES., 1973, Vol20,401-408.
+  !     =============================================================
+
+  !     Simple modifications: J. C. Orr, 16 April 2009
+  !     - combined fortran code from MITgcm site & simplification in
+  !       CSIRO code (matlab equivalent) from Phil Morgan
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !     Input arguments:
+  !     -----------------------------------------------
+  !     s  = salinity              [psu      (PSS-78) ]
+  !     t  = potential temperature [degree C (IPTS-68)]
+  !     p  = pressure              [db]
+  !     pr = reference pressure    [db]
+
+  !> salinity [psu (PSS-78)]
+  REAL(kind=wp) ::   s
+  !> potential temperature [degree C (IPTS-68)]
+  REAL(kind=wp) ::   t
+  !> pressure [db]
+  REAL(kind=wp) ::   p
+  !> reference pressure [db]
+  REAL(kind=wp) ::   pr
+
+  REAL(kind=wp) ::  ds, dt, dp, dpr
+  REAL(kind=wp) :: dsw_temp
+
+  REAL(kind=wp) ::   sw_temp
+! EXTERNAL sw_ptmp
+! REAL(kind=wp) ::   sw_ptmp
+
+  ds = DBLE(s)
+  dt = DBLE(t)
+  dp = DBLE(p)
+  dpr = DBLE(pr)
+
+  !    Simple solution
+  !    (see https://svn.mpl.ird.fr/us191/oceano/tags/V0/lib/matlab/seawater/sw_temp.m)
+  !    Carry out inverse calculation by swapping P_ref (pr) and Pressure (p)
+  !    in routine that is normally used to compute potential temp from temp
+  dsw_temp = sw_ptmp(ds, dt, dpr, dp)
+  sw_temp = REAL(dsw_temp)
+
+  !    The above simplification works extremely well (compared to Table in 1983 report)
+  !    whereas the sw_temp routine from MIT GCM site does not seem to work right
+
+  RETURN
+END FUNCTION sw_temp
+
+! ----------------------------------------------------------------------
+!  TPOT
+! ----------------------------------------------------------------------
+!
+!> \file tpot.f90
+!! \BRIEF 
+!>    Module with tpot subroutine - compute potential T from in situ T,S,P
+!>    Compute potential temperature from arrays of in situ temp, salinity, and pressure.
+!!    This subroutine is needed because sw_ptmp is a function (using scalars not arrays)
+SUBROUTINE tpot(salt, tempis, press, pressref, N, tempot)
+  !    Purpose:
+  !    Compute potential temperature from arrays of in situ temp, salinity, and pressure.
+  !    Needed because sw_ptmp is a function
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, intent(in) :: N
+
+! INPUT variables
+  !> salinity [psu]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: salt
+  !> in situ temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: tempis
+  !> pressure [db]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: press
+!f2py optional , depend(salt) :: n=len(salt)
+  !> pressure reference level [db]
+  REAL(kind=wp), INTENT(in) :: pressref
+
+! OUTPUT variables:
+  !> potential temperature [C] for pressref
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: tempot
+
+  REAL(kind=wp) :: dsalt, dtempis, dpress, dpressref
+  REAL(kind=wp) :: dtempot
+
+  INTEGER :: i
+
+! REAL(kind=wp) :: sw_ptmp
+! EXTERNAL sw_ptmp
+
+  DO i = 1,N
+     dsalt     = DBLE(salt(i))
+     dtempis   = DBLE(tempis(i))
+     dpress    = DBLE(press(i))
+     dpressref = DBLE(pressref)
+
+     dtempot   = sw_ptmp(dsalt, dtempis, dpress, dpressref)
+
+     tempot(i) = REAL(dtempot)
+  END DO
+
+  RETURN
+END SUBROUTINE tpot
+
+! ----------------------------------------------------------------------
+!  TIS
+! ----------------------------------------------------------------------
+!
+!> \file tis.f90
+!! \BRIEF 
+!>    Module with tis subroutine - compute in situ T from S,T,P
+!>    Compute in situ temperature from arrays of potential temp, salinity, and pressure.
+!!    This subroutine is needed because sw_temp is a function (using scalars not arrays)
+SUBROUTINE tis(salt, tempot, press, pressref, N, tempis)
+  !    Purpose:
+  !    Compute in situ temperature from arrays of in situ temp, salinity, and pressure.
+  !    Needed because sw_temp is a function
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, intent(in) :: N
+
+! INPUT variables
+  !> salinity [psu]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: salt
+  !> potential temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: tempot
+  !> pressure [db]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: press
+!f2py optional , depend(salt) :: n=len(salt)
+  !> pressure reference level [db]
+  REAL(kind=wp), INTENT(in) :: pressref
+
+! OUTPUT variables:
+  !> in situ temperature [C] 
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: tempis
+
+! REAL(kind=wp) :: dsalt, dtempis, dpress, dpressref
+! REAL(kind=wp) :: dtempot
+
+  INTEGER :: i
+
+! REAL(kind=wp) :: sw_temp
+! REAL(kind=wp) :: sw_temp
+! EXTERNAL sw_temp
+
+  DO i = 1,N
+    !dsalt     = DBLE(salt(i))
+    !dtempot   = DBLE(tempot(i))
+    !dpress    = DBLE(press(i))
+    !dpressref = DBLE(pressref)
+    !dtempis   = sw_temp(dsalt, dtempot, dpress, dpressref)
+    !tempis(i) = REAL(dtempis)
+
+     tempis   = sw_temp(salt(i), tempot(i), press(i), pressref)
+  END DO
+
+  RETURN
+END SUBROUTINE tis
+
+! ----------------------------------------------------------------------
+!  P80
+! ----------------------------------------------------------------------
+!
+!> \file p80.f90
+!! \BRIEF 
+!> Module with p80 function - compute pressure from depth
+!>     Function to compute pressure from depth using Saunder's (1981) formula with eos80.
+FUNCTION p80(dpth,xlat)
+
+  !     Compute Pressure from depth using Saunder's (1981) formula with eos80.
+
+  !     Reference:
+  !     Saunders, Peter M. (1981) Practical conversion of pressure
+  !     to depth, J. Phys. Ooceanogr., 11, 573-574, (1981)
+
+  !     Coded by:
+  !     R. Millard
+  !     March 9, 1983
+  !     check value: p80=7500.004 dbars at lat=30 deg., depth=7321.45 meters
+
+  !     Modified (slight format changes + added ref. details):
+  !     J. Orr, 16 April 2009
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+! Input variables:
+  !> depth [m]
+  REAL(kind=wp), INTENT(in) :: dpth
+  !> latitude [degrees]
+  REAL(kind=wp), INTENT(in) :: xlat
+
+! Output variable:
+  !> pressure [db]
+  REAL(kind=wp) :: p80
+
+! Local variables:
+  REAL(kind=wp) :: pi
+  REAL(kind=wp) :: plat, d, c1
+
+  pi=3.141592654
+
+  plat = ABS(xlat*pi/180.)
+  d  = SIN(plat)
+  c1 = 5.92e-3+d**2 * 5.25e-3
+
+  p80 = ((1-c1)-SQRT(((1-c1)**2)-(8.84e-6*dpth))) / 4.42e-6
+
+  RETURN
+END FUNCTION p80
+
+! ----------------------------------------------------------------------
+!  RHO
+! ----------------------------------------------------------------------
+!
+!> \file rho.f90
+!! \BRIEF 
+!> Module with rho function - computes in situ density from S, T, P
+!> Function to compute in situ density from salinity (psu), in situ temperature (C), & pressure (bar)
+FUNCTION rho(salt, temp, pbar)
+
+  ! Compute in situ density from salinity (psu), in situ temperature (C), & pressure (bar)
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !> salinity [psu]
+  REAL(kind=wp) :: salt
+  !> in situ temperature (C)
+  REAL(kind=wp) :: temp
+  !> pressure (bar) [Note units: this is NOT in decibars]
+  REAL(kind=wp) :: pbar
+
+  REAL(kind=wp) :: s, t, p
+! REAL(kind=wp) :: t68
+  REAL(kind=wp) :: X
+  REAL(kind=wp) :: rhow, rho0
+  REAL(kind=wp) :: a, b, c
+  REAL(kind=wp) :: Ksbmw, Ksbm0, Ksbm
+  REAL(kind=wp) :: drho
+
+  REAL(kind=wp) :: rho
+
+  !     Input arguments:
+  !     -------------------------------------
+  !     s  = salinity            [psu      (PSS-78) ]
+  !     t  = in situ temperature [degree C (IPTS-68)]
+  !     p  = pressure            [bar] !!!!  (not in [db]
+
+  s = DBLE(salt)
+  t = DBLE(temp)
+  p = DBLE(pbar)
+
+! Convert the temperature on today's "ITS 90" scale to older IPTS 68 scale
+! (see Dickson et al., Best Practices Guide, 2007, Chap. 5, p. 7, including footnote)
+! According to Best-Practices guide, line above should be commented & 2 lines below should be uncommented
+! Guide's answer of rho (s=35, t=25, p=0) = 1023.343 is for temperature given on ITPS-68 scale
+! t68 = (T - 0.0002) / 0.99975
+! X = t68
+! Finally, don't do the ITS-90 to IPTS-68 conversion (T input var now already on IPTS-68 scale)
+  X = T
+
+! Density of pure water
+  rhow = 999.842594d0 + 6.793952e-2_wp*X          &
+       -9.095290e-3_wp*X*X + 1.001685e-4_wp*X**3  &
+       -1.120083e-6_wp*X**4 + 6.536332e-9_wp*X**5
+
+! Density of seawater at 1 atm, P=0
+  A = 8.24493e-1_wp - 4.0899e-3_wp*X                         &
+       + 7.6438e-5_wp*X*X - 8.2467e-7_wp*X**3 + 5.3875e-9_wp*X**4
+  B = -5.72466e-3_wp + 1.0227e-4_wp*X - 1.6546e-6_wp*X*X
+  C = 4.8314e-4_wp
+
+  rho0 = rhow + A*S + B*S*SQRT(S) + C*S**2.0d0
+
+! Secant bulk modulus of pure water
+! The secant bulk modulus is the average change in pressure
+! divided by the total change in volume per unit of initial volume.
+  Ksbmw = 19652.21d0 + 148.4206d0*X - 2.327105d0*X*X &
+       + 1.360477e-2_wp*X**3 - 5.155288e-5_wp*X**4
+
+! Secant bulk modulus of seawater at 1 atm
+  Ksbm0 = Ksbmw + S*( 54.6746d0 - 0.603459d0*X + 1.09987e-2_wp*X**2 &
+       - 6.1670e-5_wp*X**3) &
+       + S*SQRT(S)*( 7.944e-2_wp + 1.6483e-2_wp*X - 5.3009e-4_wp*X**2)
+
+! Secant bulk modulus of seawater at S,T,P
+  Ksbm = Ksbm0 &
+       + P*(3.239908d0 + 1.43713e-3_wp*X + 1.16092e-4_wp*X**2 - 5.77905e-7_wp*X**3) &
+       + P*S*(2.2838e-3_wp - 1.0981e-5_wp*X - 1.6078e-6_wp*X**2) &
+       + P*S*SQRT(S)*1.91075e-4_wp &
+       + P*P*(8.50935e-5_wp - 6.12293e-6_wp*X + 5.2787e-8_wp*X**2) &
+       + P*P*S*(-9.9348e-7_wp + 2.0816e-8_wp*X + 9.1697e-10_wp*X**2)
+
+! Density of seawater at S,T,P
+  drho = rho0/(1.0d0 - P/Ksbm)
+  rho = REAL(drho)
+
+  RETURN
+END FUNCTION rho
+
+! ----------------------------------------------------------------------
+!  RHOINSITU
+! ----------------------------------------------------------------------
+!
+!> \file rhoinsitu.f90
+!! \BRIEF 
+!> Module with rhoinsitu subroutine - compute in situ density from S, Tis, P
+!>     Compute in situ density from salinity (psu), in situ temperature (C), & pressure (db).
+!!     This subroutine is needed because rho is a function (using scalars not arrays)
+SUBROUTINE rhoinsitu(salt, tempis, pdbar, N, rhois)
+
+  !     Purpose:
+  !     Compute in situ density from salinity (psu), in situ temperature (C), & pressure (db)
+  !     Needed because rho is a function
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  INTEGER :: N
+
+! INPUT variables
+  ! salt   = salinity [psu]
+  ! tempis = in situ temperature [C]
+  ! pdbar  = pressure [db]
+
+  !> salinity [psu]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: salt
+  !> in situ temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: tempis
+  !> pressure [db]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: pdbar
+!f2py optional , depend(salt) :: n=len(salt)
+
+! OUTPUT variables:
+  ! rhois  = in situ density
+
+  !> in situ density [kg/m3]
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: rhois
+
+! Local variables
+  INTEGER :: i
+
+! REAL(kind=wp) ::  rho
+! EXTERNAL rho
+
+  DO i = 1,N
+     rhois(i) = rho(salt(i), tempis(i), pdbar(i)/10.)
+  END DO
+
+  RETURN
+END SUBROUTINE rhoinsitu
+
+! ----------------------------------------------------------------------
+!  DEPTH2PRESS
+! ----------------------------------------------------------------------
+!
+!> \file depth2press.f90
+!! \BRIEF 
+!> Module with depth2press subroutine - converts depth to pressure
+!! with Saunders (1981) formula
+!>     Compute pressure [db] from depth [m] & latitude [degrees north].
+!!     This subroutine is needed because p80 is a function (using scalars not arrays)
+SUBROUTINE depth2press(depth, lat, pdbar, N)
+
+  !     Purpose:
+  !     Compute pressure [db] from depth [m] & latitude [degrees north].
+  !     Needed because p80 is a function 
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, intent(in) :: N
+
+! INPUT variables
+  !> depth [m]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: depth
+  !> latitude [degrees]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: lat
+!f2py optional , depend(depth) :: n=len(depth)
+
+! OUTPUT variables:
+  !> pressure [db]
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: pdbar
+
+  !     Local variables
+  INTEGER :: i
+
+! REAL(kind=wp) ::  p80
+! EXTERNAL p80
+
+  DO i = 1,N
+     pdbar(i) = p80(depth(i), lat(i))
+  END DO
+
+  RETURN
+END SUBROUTINE depth2press
+
+! ----------------------------------------------------------------------
+!  CONSTANTS
+! ----------------------------------------------------------------------
+!
+!> \file constants.f90
+!! \BRIEF 
+!> Module with contants subroutine - computes carbonate system constants
+!! from S,T,P 
+!> Compute thermodynamic constants
+!! FROM temperature, salinity, and pressure (1D arrays)
+SUBROUTINE constants(K0, K1, K2, Kb, Kw, Ks, Kf, Kspc, Kspa,  &
+                     K1p, K2p, K3p, Ksi,                      &
+                     St, Ft, Bt,                              &
+                     temp, sal, Patm,                         &
+                     depth, lat, N,                           &
+                     optT, optP, optB, optK1K2, optKf, optGAS)
+
+  !   Purpose:
+  !     Compute thermodynamic constants
+  !     FROM: temperature, salinity, and pressure (1D arrays)
+
+  !     INPUT variables:
+  !     ================
+  !     Patm    = atmospheric pressure [atm]
+  !     depth   = depth [m]     (with optP='m', i.e., for a z-coordinate model vertical grid is depth, not pressure)
+  !             = pressure [db] (with optP='db')
+  !     lat     = latitude [degrees] (needed to convert depth to pressure, i.e., when optP='m')
+  !             = dummy array (unused when optP='db')
+  !     temp    = potential temperature [degrees C] (with optT='Tpot', i.e., models carry tempot, not temp)
+  !             = in situ   temperature [degrees C] (with optT='Tinsitu', e.g., for data)
+  !     sal     = salinity in [psu]
+  !     ---------
+  !     optT: choose in situ vs. potential temperature as input
+  !     ---------
+  !     NOTE: Carbonate chem calculations require IN-SITU temperature (not potential Temperature)
+  !       -> 'Tpot' means input is pot. Temperature (in situ Temp "tempis" is computed)
+  !       -> 'Tinsitu' means input is already in-situ Temperature, not pot. Temp ("tempis" not computed)
+  !     ---------
+  !     optP: choose depth (m) vs pressure (db) as input
+  !     ---------
+  !       -> 'm'  means "depth" input is in "m" (thus in situ Pressure "p" [db] is computed)
+  !       -> 'db' means "depth" input is already in situ pressure [db], not m (p = depth)
+  !     ---------
+  !     optB:
+  !     ---------
+  !       -> 'u74' means use classic formulation of Uppström (1974) for total Boron
+  !       -> 'l10' means use newer   formulation of Lee et al. (2010) for total Boron
+  !     ---------
+  !     optK1K2:
+  !     ---------
+  !       -> 'l'   means use Lueker et al. (2000) formulations for K1 & K2 (recommended by Dickson et al. 2007)
+  !                **** BUT this should only be used when 2 < T < 35 and 19 < S < 43
+  !       -> 'm10' means use Millero (2010) formulation for K1 & K2 (see Dickson et al., 2007)
+  !                **** Valid for 0 < T < 50°C and 1 < S < 50 psu
+  !     -----------
+  !     optKf:
+  !     ----------
+  !       -> 'pf' means use Perez & Fraga (1987) formulation for Kf (recommended by Dickson et al., 2007)
+  !               **** BUT Valid for  9 < T < 33°C and 10 < S < 40.
+  !       -> 'dg' means use Dickson & Riley (1979) formulation for Kf (recommended by Dickson & Goyet, 1994)
+  !     -----------
+  !     optGAS: choose in situ vs. potential fCO2 and pCO2
+  !     ---------
+  !       PRESSURE corrections for K0 and the fugacity coefficient (Cf) 
+  !       -> 'Pzero'   = 'zero order' fCO2 and pCO2 (typical approach, which is flawed)
+  !                      considers in situ T & only atm pressure (hydrostatic=0)
+  !       -> 'Ppot'    = 'potential' fCO2 and pCO2 (water parcel brought adiabatically to the surface)
+  !                      considers potential T & only atm pressure (hydrostatic press = 0)
+  !       -> 'Pinsitu' = 'in situ' fCO2 and pCO2 (accounts for huge effects of pressure)
+  !                      considers in situ T & total pressure (atm + hydrostatic)
+  !     ---------
+
+  !     OUTPUT variables:
+  !     =================
+  !     K0, K1, K2, Kb, Kw, Ks, Kf, Kspc, Kspa, K1p, K2p, K3p, Ksi
+  !     St, Ft, Bt
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+! Input variables
+  !>     number of records
+  INTEGER, INTENT(in) :: N
+  !> in <b>situ temperature</b> (when optT='Tinsitu', typical data) 
+  !! OR <b>potential temperature</b> (when optT='Tpot', typical models) [degree C]
+  REAL(kind=wp), INTENT(in),    DIMENSION(N) :: temp
+  !> depth in <b>meters</b> (when optP='m') or <b>decibars</b> (when optP='db')
+  REAL(kind=wp), INTENT(in),    DIMENSION(N) :: depth
+  !> latitude <b>[degrees north]</b>
+  REAL(kind=wp), INTENT(in),    DIMENSION(N) :: lat
+  !> salinity <b>[psu]</b>
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: sal
+!f2py optional , depend(sal) :: n=len(sal)
+
+  !> atmospheric pressure <b>[atm]</b>
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: Patm
+
+  !> for temp input, choose \b 'Tinsitu' for in situ Temp or 
+  !! \b 'Tpot' for potential temperature (in situ Temp is computed, needed for models)
+  CHARACTER(7), INTENT(in) :: optT
+  !> for depth input, choose \b "db" for decibars (in situ pressure) or \b "m" for meters (pressure is computed, needed for models)
+  CHARACTER(2), INTENT(in) :: optP
+  !> for total boron, choose either \b 'u74' (Uppstrom, 1974) or \b 'l10' (Lee et al., 2010).
+  !! The 'l10' formulation is based on 139 measurements (instead of 20),
+  !! uses a more accurate method, and
+  !! generally increases total boron in seawater by 4% 
+!f2py character*3 optional, intent(in) :: optB='l10'
+  CHARACTER(3), OPTIONAL, INTENT(in) :: optB
+  !> for Kf, choose either \b 'pf' (Perez & Fraga, 1987) or \b 'dg' (Dickson & Riley, 1979)
+!f2py character*2 optional, intent(in) :: optKf='pf'
+  CHARACTER(2), OPTIONAL, INTENT(in) :: optKf
+  !> for K1,K2 choose either \b 'l' (Lueker et al., 2000) or \b 'm10' (Millero, 2010) 
+!f2py character*3 optional, intent(in) :: optK1K2='l'
+  CHARACTER(3), OPTIONAL, INTENT(in) :: optK1K2
+  !> for K0,fugacity coefficient choose either \b 'Ppot' (no pressure correction) or \b 'Pinsitu' (with pressure correction) 
+  !! 'Ppot'    - for 'potential' fCO2 and pCO2 (water parcel brought adiabatically to the surface)
+  !! 'Pinsitu' - for 'in situ' values of fCO2 and pCO2, accounting for pressure on K0 and Cf
+  !! with 'Pinsitu' the fCO2 and pCO2 will be many times higher in the deep ocean
+!f2py character*7 optional, intent(in) :: optGAS='Pinsitu'
+  CHARACTER(7), OPTIONAL, INTENT(in) :: optGAS
+
+! Ouput variables
+  !> solubility of CO2 in seawater (Weiss, 1974), also known as K0
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: K0
+  !> K1 for the dissociation of carbonic acid from Lueker et al. (2000) or Millero (2010), depending on optK1K2
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: K1
+  !> K2 for the dissociation of carbonic acid from Lueker et al. (2000) or Millero (2010), depending on optK1K2
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: K2
+  !> equilibrium constant for dissociation of boric acid 
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Kb
+  !> equilibrium constant for the dissociation of water (Millero, 1995)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Kw
+  !> equilibrium constant for the dissociation of bisulfate (Dickson, 1990)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Ks
+  !> equilibrium constant for the dissociation of hydrogen fluoride 
+  !! either from Dickson and Riley (1979) or from Perez and Fraga (1987), depending on optKf
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Kf
+  !> solubility product for calcite (Mucci, 1983)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Kspc
+  !> solubility product for aragonite (Mucci, 1983)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Kspa
+  !> 1st dissociation constant for phosphoric acid (Millero, 1995)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: K1p
+  !> 2nd dissociation constant for phosphoric acid (Millero, 1995)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: K2p
+  !> 3rd dissociation constant for phosphoric acid (Millero, 1995)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: K3p
+  !> equilibrium constant for the dissociation of silicic acid (Millero, 1995)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Ksi
+  !> total sulfate (Morris & Riley, 1966)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: St
+  !> total fluoride  (Riley, 1965)
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Ft
+  !> total boron
+  !! from either Uppstrom (1974) or Lee et al. (2010), depending on optB
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: Bt
+
+! Local variables
+  REAL(kind=wp) :: ssal
+  REAL(kind=wp) :: p
+  REAL(kind=wp) :: tempot, tempis68, tempot68
+  REAL(kind=wp) :: tempis
+  REAL(kind=wp) :: is, invtk, dlogtk, is2, s2, sqrtis
+  REAL(kind=wp) :: Ks_0p, Kf_0p
+  REAL(kind=wp) :: total2free, free2SWS, total2SWS, SWS2total
+  REAL(kind=wp) :: total2free_0p, free2SWS_0p, total2SWS_0p
+! REAL(kind=wp) :: free2SWS, free2SWS_0p
+
+  REAL(kind=wp) :: dtempot, dtempot68
+  REAL(kind=wp) :: R
+
+  REAL(kind=wp) :: pK1o, ma1, mb1, mc1, pK1
+  REAL(kind=wp) :: pK2o, ma2, mb2, mc2, pK2
+
+  REAL(kind=wp), DIMENSION(12) :: a0, a1, a2, b0, b1, b2
+  REAL(kind=wp), DIMENSION(12) :: deltav, deltak, lnkpok0
+  REAL(kind=wp) :: tmp, nK0we74
+
+  INTEGER :: i, icount, ipc
+
+  REAL(kind=wp) :: t, tk, tk0, prb
+  REAL(kind=wp) :: s, sqrts, s15, scl
+
+  REAL(kind=wp) :: Phydro_atm, Patmd, Ptot, Rgas_atm, vbarCO2
+
+! Arrays to pass optional arguments into or use defaults (Dickson et al., 2007)
+  CHARACTER(3) :: opB
+  CHARACTER(2) :: opKf
+  CHARACTER(3) :: opK1K2
+  CHARACTER(7) :: opGAS
+
+  ! CONSTANTS
+  ! =========
+  ! Constants in formulation for Pressure effect on K's (Millero, 95)
+  ! with corrected coefficients for Kb, Kw, Ksi, etc.
+
+  ! index: 1) K1 , 2) K2, 3) Kb, 4) Kw, 5) Ks, 6) Kf, 7) Kspc, 8) Kspa,
+  !            9) K1P, 10) K2P, 11) K3P, 12) Ksi
+
+  DATA a0 /-25.5_wp, -15.82_wp, -29.48_wp, -20.02_wp, &
+          -18.03_wp,  -9.78_wp, -48.76_wp, -45.96_wp, &
+          -14.51_wp, -23.12_wp, -26.57_wp, -29.48_wp/
+  DATA a1 /0.1271_wp, -0.0219_wp, 0.1622_wp, 0.1119_wp, &
+           0.0466_wp, -0.0090_wp, 0.5304_wp, 0.5304_wp, &
+           0.1211_wp, 0.1758_wp, 0.2020_wp, 0.1622_wp/
+  DATA a2 /     0.0_wp,       0.0_wp, -2.608e-3_wp, -1.409e-3_wp, &
+           0.316e-3_wp, -0.942e-3_wp,  0.0_wp,       0.0_wp, &
+          -0.321e-3_wp, -2.647e-3_wp, -3.042e-3_wp, -2.6080e-3_wp/
+  DATA b0 /-3.08e-3_wp, 1.13e-3_wp,  -2.84e-3_wp,   -5.13e-3_wp, &
+           -4.53e-3_wp, -3.91e-3_wp, -11.76e-3_wp, -11.76e-3_wp, &
+           -2.67e-3_wp, -5.15e-3_wp,  -4.08e-3_wp,  -2.84e-3_wp/
+  DATA b1 /0.0877e-3_wp, -0.1475e-3_wp, 0.0_wp,       0.0794e-3_wp, &
+           0.09e-3_wp,    0.054e-3_wp,  0.3692e-3_wp, 0.3692e-3_wp, &
+           0.0427e-3_wp,  0.09e-3_wp,   0.0714e-3_wp, 0.0_wp/
+  DATA b2 /12*0.0_wp/
+
+! Set defaults for optional arguments (in Fortran 90)
+! Note:  Optional arguments with f2py (python) are set above with 
+!        the !f2py statements that precede each type declaraion
+  IF (PRESENT(optB)) THEN
+    opB = optB
+  ELSE
+    opB = 'l10'
+  ENDIF
+  IF (PRESENT(optKf)) THEN
+    opKf = optKf
+  ELSE
+    opKf = 'pf'
+  ENDIF
+  IF (PRESENT(optK1K2)) THEN
+    opK1K2 = optK1K2
+  ELSE
+    opK1K2 = 'l'
+  ENDIF
+  IF (PRESENT(optGAS)) THEN
+    opGAS = optGAS
+  ELSE
+    opGAS = 'Pinsitu'
+  ENDIF
+
+  R = 83.14472_wp
+
+  icount = 0
+  DO i = 1, N
+     icount = icount + 1
+!    ===============================================================
+!    Convert model depth -> press; convert model Theta -> T in situ
+!    ===============================================================
+!    * Model temperature tracer is usually "potential temperature"
+!    * Model vertical grid is usually in meters
+!    BUT carbonate chem routines require pressure & in-situ T
+!    Thus before computing chemistry, if appropriate,
+!    convert these 2 model vars (input to this routine)
+!     - depth [m] => convert to pressure [db]
+!     - potential temperature (C) => convert to in-situ T (C)
+!    -------------------------------------------------------
+!    1)  Compute pressure [db] from depth [m] and latitude [degrees] (if input is m, for models)
+     IF (trim(optP) == 'm' ) THEN
+!       Compute pressure [db] from depth [m] and latitude [degrees]
+        p = p80(depth(i), lat(i))
+     ELSEIF (trim(optP) == 'db' ) THEN
+!       In this case (where optP = 'db'), p is input & output (no depth->pressure conversion needed)
+        p = depth(i)
+     ELSE
+        PRINT *,"optP must be 'm' or 'db'"
+        STOP
+     ENDIF
+
+!    2) Convert potential T to in-situ T (if input is Tpot, i.e. case for models):
+     IF (trim(optT) == 'Tpot' .OR. trim(optT) == 'tpot') THEN
+        tempot = temp(i)
+!       This is the case for most models and some data
+!       a) Convert the pot. temp on today's "ITS 90" scale to older IPTS 68 scale
+!          (see Dickson et al., Best Practices Guide, 2007, Chap. 5, p. 7, including footnote)
+        tempot68 = (tempot - 0.0002) / 0.99975
+!       b) Compute "in-situ Temperature" from "Potential Temperature" (both on IPTS 68)
+        tempis68 = sw_temp(sal(i), tempot68, p, 0.0_wp )
+!       c) Convert the in-situ temp on older IPTS 68 scale to modern scale (ITS 90)
+        tempis = 0.99975*tempis68 + 0.0002
+!       Note: parts (a) and (c) above are tiny corrections;
+!             part  (b) is a big correction for deep waters (but zero at surface)
+     ELSEIF (trim(optT) == 'Tinsitu' .OR. trim(optT) == 'tinsitu') THEN
+!       When optT = 'Tinsitu', tempis is input & output (no tempot needed)
+        tempis    = temp(i)
+        tempis68  = (temp(i) - 0.0002) / 0.99975
+!       dtempot68 = sw_ptmp(DBLE(sal(i)), DBLE(tempis68), DBLE(p), 0.0_wp)
+        dtempot68 = sw_ptmp(sal(i), tempis68, p, 0.0_wp)
+        dtempot   = 0.99975*dtempot68 + 0.0002
+     ELSE
+        PRINT *,"optT must be either 'Tpot' or 'Tinsitu'"
+        PRINT *,"you specified optT =", trim(optT) 
+        STOP
+     ENDIF
+
+!    Compute constants:
+     IF (temp(i) >= -5. .AND. temp(i) < 1.0e+2) THEN
+!       Test to indicate if any of input variables are unreasonable
+        IF (      sal(i) < 0.  .OR.  sal(i) > 1e+3) THEN
+           PRINT *, 'i, icount, temp, sal =', i, icount, temp(i), sal(i)
+        ENDIF
+!       Zero out negative salinity (prev case for OCMIP2 model w/ slightly negative S in some coastal cells)
+        IF (sal(i) < 0.0) THEN
+           ssal = 0.0
+        ELSE
+           ssal = sal(i)
+        ENDIF
+
+!       Absolute temperature (Kelvin) and related values
+        t = DBLE(tempis)
+        tk = 273.15d0 + t
+        invtk=1.0d0/tk
+        dlogtk=LOG(tk)
+
+!       Atmospheric pressure
+        Patmd = DBLE(Patm(i))
+
+!       Hydrostatic pressure (prb is in bars)
+        prb = DBLE(p) / 10.0d0
+
+!       Salinity and simply related values
+        s = DBLE(ssal)
+        s2=s*s
+        sqrts=SQRT(s)
+        s15=s**1.5d0
+        scl=s/1.80655d0
+
+!       Ionic strength:
+        is = 19.924d0*s/(1000.0d0 - 1.005d0*s)
+        is2 = is*is
+        sqrtis = SQRT(is)
+
+!       Total concentrations for sulfate, fluoride, and boron
+
+!       Sulfate: Morris & Riley (1966)
+        St(i) = 0.14d0 * scl/96.062d0
+
+!       Fluoride:  Riley (1965)
+        Ft(i) = 0.000067d0 * scl/18.9984d0
+
+!       Boron:
+        IF (trim(opB) == 'l10') THEN
+!          New formulation from Lee et al (2010)
+           Bt(i) = 0.0002414d0 * scl/10.811d0
+        ELSEIF (trim(opB) == 'u74') THEN
+!          Classic formulation from Uppström (1974)
+           Bt(i) = 0.000232d0  * scl/10.811d0
+        ELSE
+           PRINT *,"optB must be 'l10' or 'u74'"
+           STOP
+        ENDIF
+
+!       K0 (K Henry)
+!       CO2(g) <-> CO2(aq.)
+!       K0  = [CO2]/ fCO2
+!       Weiss (1974)   [mol/kg/atm]
+        IF     (trim(opGAS) == 'Pzero'   .OR. trim(opGAS) == 'pzero') THEN
+           tk0 = tk                   !in situ temperature (K) for K0 calculation
+           Ptot = Patmd               !total pressure (in atm) = atmospheric pressure ONLY
+        ELSEIF (trim(opGAS) == 'Ppot'    .OR. trim(opGAS) == 'ppot') THEN
+           tk0 = dtempot + 273.15d0   !potential temperature (K) for K0 calculation as needed for potential fCO2 & pCO2
+           Ptot = Patmd               !total pressure (in atm) = atmospheric pressure ONLY
+        ELSEIF (trim(opGAS) == 'Pinsitu' .OR. trim(opGAS) == 'pinsitu') THEN
+           tk0 = tk                     !in situ temperature (K) for K0 calculation
+           Phydro_atm = prb / 1.01325d0 !convert hydrostatic pressure from bar to atm (1.01325 bar / atm)
+           Ptot = Patmd + Phydro_atm    !total pressure (in atm) = atmospheric pressure + hydrostatic pressure
+        ELSE
+           PRINT *, "optGAS must be 'Pzero', 'Ppot', or 'Pinsitu'"
+           STOP
+        ENDIF
+        tmp = 9345.17d0/tk0 - 60.2409d0 + 23.3585d0 * LOG(tk0/100.0d0)
+        nK0we74 = tmp + s*(0.023517d0 - 0.00023656d0*tk0 + 0.0047036e-4_wp*tk0*tk0)
+        K0(i) = EXP(nK0we74)
+
+!       K1 = [H][HCO3]/[H2CO3]
+!       K2 = [H][CO3]/[HCO3]
+        IF (trim(opK1K2) == 'l') THEN
+!         Mehrbach et al. (1973) refit, by Lueker et al. (2000) (total pH scale)
+          K1(i) = 10.0d0**(-1.0d0*(3633.86d0*invtk - 61.2172d0 + 9.6777d0*dlogtk  &
+                  - 0.011555d0*s + 0.0001152d0*s2))
+          K2(i) = 10.0d0**(-1*(471.78d0*invtk + 25.9290d0 - 3.16967d0*dlogtk      &
+                  - 0.01781d0*s + 0.0001122d0*s2))
+        ELSEIF (trim(opK1K2) == 'm10') THEN
+!         Millero (2010, Mar. Fresh Wat. Res.) (total pH scale)
+!         pK1o = 6320.813d0*invtk + 19.568224d0*dlogtk -126.34048d0
+!         ma1 = 13.4051d0*sqrts + 0.03185d0*s - (5.218e-5)*s2
+!         mb1 = -531.095d0*sqrts - 5.7789d0*s
+!         mc1 = -2.0663d0*sqrts
+!         pK1 = pK1o + ma1 + mb1*invtk + mc1*dlogtk
+!         K1(i) = 10.0d0**(-pK1) 
+
+!         pK2o = 5143.692d0*invtk + 14.613358d0*dlogtk -90.18333d0
+!         ma2 = 21.5724d0*sqrts + 0.1212d0*s - (3.714e-4)*s2
+!         mb2 = -798.292d0*sqrts - 18.951d0*s
+!         mc2 = -3.403d0*sqrts
+!         pK2 = pK2o + ma2 + mb2*invtk + mc2*dlogtk
+!         K2(i) = 10.0d0**(-pK2)
+
+!         Millero (2010, Mar. Fresh Wat. Res.) (seawater pH scale)
+          pK1o = 6320.813d0*invtk + 19.568224d0*dlogtk -126.34048d0
+          ma1 = 13.4038d0*sqrts + 0.03206d0*s - (5.242e-5)*s2
+          mb1 = -530.659d0*sqrts - 5.8210d0*s
+          mc1 = -2.0664d0*sqrts
+          pK1 = pK1o + ma1 + mb1*invtk + mc1*dlogtk
+          K1(i) = 10.0d0**(-pK1) 
+
+          pK2o = 5143.692d0*invtk + 14.613358d0*dlogtk -90.18333d0
+          ma2 = 21.3728d0*sqrts + 0.1218d0*s - (3.688e-4)*s2
+          mb2 = -788.289d0*sqrts - 19.189d0*s
+          mc2 = -3.374d0*sqrts
+          pK2 = pK2o + ma2 + mb2*invtk + mc2*dlogtk
+          K2(i) = 10.0d0**(-pK2)
+        ELSE
+           PRINT *, "optK1K2 must be either 'l' or 'm10'"
+           STOP
+        ENDIF
+
+!       Kb = [H][BO2]/[HBO2]
+!       (total scale)
+!       Millero p.669 (1995) using data from Dickson (1990)
+        Kb(i) = EXP((-8966.90d0 - 2890.53d0*sqrts - 77.942d0*s +  &
+                1.728d0*s15 - 0.0996d0*s2)*invtk +              &
+                (148.0248d0 + 137.1942d0*sqrts + 1.62142d0*s) +   &
+                (-24.4344d0 - 25.085d0*sqrts - 0.2474d0*s) *      &
+                dlogtk + 0.053105d0*sqrts*tk)
+
+!       K1p = [H][H2PO4]/[H3PO4]
+!       (seawater scale)
+!       DOE(1994) eq 7.2.20 with footnote using data from Millero (1974)
+!       Millero (1995), p.670, eq. 65
+!       Use Millero equation's 115.540 constant instead of 115.525 (Dickson et al., 2007).
+!       The latter is only an crude approximation to convert to Total scale (by subtracting 0.015)
+!       And we want to stay on the SWS scale anyway for the pressure correction later.
+        K1p(i) = EXP(-4576.752d0*invtk + 115.540d0 - 18.453d0*dlogtk +  &
+                 (-106.736d0*invtk + 0.69171d0) * sqrts +             &
+                 (-0.65643d0*invtk - 0.01844d0) * s)
+
+!       K2p = [H][HPO4]/[H2PO4]
+!       (seawater scale)
+!       DOE(1994) eq 7.2.23 with footnote using data from Millero (1974))
+!       Millero (1995), p.670, eq. 66
+!       Use Millero equation's 172.1033 constant instead of 172.0833 (Dickson et al., 2007).
+!       The latter is only an crude approximation to convert to Total scale (by subtracting 0.015)
+!       And we want to stay on the SWS scale anyway for the pressure correction later.
+        K2p(i) = EXP(-8814.715d0*invtk + 172.1033d0 - 27.927d0*dlogtk +  &
+                 (-160.340d0*invtk + 1.3566d0)*sqrts +                 &
+                 (0.37335d0*invtk - 0.05778d0)*s)
+
+!       K3p = [H][PO4]/[HPO4]
+!       (seawater scale)
+!       DOE(1994) eq 7.2.26 with footnote using data from Millero (1974)
+!       Millero (1995), p.670, eq. 67
+!       Use Millero equation's 18.126 constant instead of 18.141 (Dickson et al., 2007).
+!       The latter is only an crude approximation to convert to Total scale (by subtracting 0.015)
+!       And we want to stay on the SWS scale anyway for the pressure correction later.
+        K3p(i) = EXP(-3070.75d0*invtk - 18.126d0 +            &
+                 (17.27039d0*invtk + 2.81197d0) *             &
+                 sqrts + (-44.99486d0*invtk - 0.09984d0) * s)
+
+!       Ksi = [H][SiO(OH)3]/[Si(OH)4]
+!       (seawater scale)
+!       Millero (1995), p.671, eq. 72
+!       Use Millero equation's 117.400 constant instead of 117.385 (Dickson et al., 2007).
+!       The latter is only an crude approximation to convert to Total scale (by subtracting 0.015)
+!       And we want to stay on the SWS scale anyway for the pressure correction later.
+        Ksi(i) = EXP(-8904.2d0*invtk  + 117.400d0 - 19.334d0*dlogtk +  &
+                 (-458.79d0*invtk + 3.5913d0) * sqrtis +             &
+                 (188.74d0*invtk - 1.5998d0) * is +                  &
+                 (-12.1652d0*invtk + 0.07871d0) * is2 +              &
+                 LOG(1.0 - 0.001005d0*s))
+
+!       Kw = [H][OH]
+!       (seawater scale)
+!       Millero (1995) p.670, eq. 63 from composite data
+!       Use Millero equation's 148.9802 constant instead of 148.9652 (Dickson et al., 2007).
+!       The latter is only an crude approximation to convert to Total scale (by subtracting 0.015)
+!       And we want to stay on the SWS scale anyway for the pressure correction later.
+        Kw(i) = EXP(-13847.26d0*invtk + 148.9802d0 - 23.6521d0*dlogtk +  &
+               (118.67d0*invtk - 5.977d0 + 1.0495d0 * dlogtk) *          &
+               sqrts - 0.01615d0 * s)
+
+!       Ks = [H][SO4]/[HSO4]
+!       (free scale)
+!       Dickson (1990, J. chem. Thermodynamics 22, 113)
+        Ks_0p = EXP(-4276.1d0*invtk + 141.328d0 - 23.093d0*dlogtk          &
+                + (-13856.d0*invtk + 324.57d0 - 47.986d0*dlogtk) * sqrtis  &
+                + (35474.d0*invtk - 771.54 + 114.723d0*dlogtk) * is      &
+                - 2698.d0*invtk*is**1.5 + 1776.d0*invtk*is2              &
+                + LOG(1.0d0 - 0.001005d0*s))
+
+!       Kf = [H][F]/[HF]
+!       (total scale)
+        IF (trim(opKf) == 'dg') THEN
+!          Dickson and Riley (1979) -- change pH scale to total (following Dickson & Goyet, 1994)
+           Kf_0p = EXP(1590.2d0*invtk - 12.641d0 + 1.525d0*sqrtis +  &
+                   LOG(1.0d0 - 0.001005d0*s) +                     &
+                   LOG(1.0d0 + St(i)/Ks_0p))
+        ELSEIF (trim(opKf) == 'pf') THEN
+!          Perez and Fraga (1987) - Already on Total scale (no need for last line above)
+!          Formulation as given in Dickson et al. (2007)
+           Kf_0p = EXP(874.d0*invtk - 9.68d0 + 0.111d0*sqrts)
+        ELSE
+           PRINT *, "optKf must be either 'dg' or 'pf'"
+           STOP
+        ENDIF
+
+!       Kspc (calcite) - apparent solubility product of calcite
+!       (no scale)
+!       Kspc = [Ca2+] [CO32-] when soln is in equilibrium w/ calcite
+!       Mucci 1983 mol/kg-soln
+        Kspc(i) = 10d0**(-171.9065d0 - 0.077993d0*tk + 2839.319d0/tk    &
+                 + 71.595d0*LOG10(tk)                             &
+                 + (-0.77712d0 + 0.0028426d0*tk + 178.34d0/tk)*sqrts  &
+                 -0.07711d0*s + 0.0041249d0*s15 )
+
+
+!       Kspa (aragonite) - apparent solubility product of aragonite
+!       (no scale)
+!       Kspa = [Ca2+] [CO32-] when soln is in equilibrium w/ aragonite
+!       Mucci 1983 mol/kg-soln
+        Kspa(i) = 10.d0**(-171.945d0 - 0.077993d0*tk + 2903.293d0/tk &
+             +71.595d0*LOG10(tk) &
+             +(-0.068393d0 + 0.0017276d0*tk + 88.135d0/tk)*sqrts &
+             -0.10018d0*s + 0.0059415d0*s15 )
+
+!       Pressure effect on K0 based on Weiss (1974, equation 5)
+        Rgas_atm = 82.05736_wp      ! (cm3 * atm) / (mol * K)  CODATA (2006)
+        vbarCO2 = 32.3_wp           ! partial molal volume (cm3 / mol) from Weiss (1974, Appendix, paragraph 3)
+        K0(i) = K0(i) * exp( ((1-Ptot)*vbarCO2)/(Rgas_atm*tk0) )   ! Weiss (1974, equation 5)
+
+!       Pressure effect on all other K's (based on Millero, (1995)
+!           index: K1(1), K2(2), Kb(3), Kw(4), Ks(5), Kf(6), Kspc(7), Kspa(8),
+!                  K1p(9), K2p(10), K3p(11), Ksi(12)
+        DO ipc = 1, 12
+           deltav(ipc)  =  a0(ipc) + a1(ipc) *t + a2(ipc) *t*t
+           deltak(ipc)   = (b0(ipc)  + b1(ipc) *t + b2(ipc) *t*t)
+           lnkpok0(ipc)  = (-(deltav(ipc)) &
+                +(0.5d0*deltak(ipc) * prb) &
+                )                         * prb/(R*tk)
+        END DO
+
+!       Pressure correction on Ks (Free scale)
+        Ks(i) = Ks_0p*EXP(lnkpok0(5))
+!       Conversion factor total -> free scale
+        total2free     = 1.d0/(1.d0 + St(i)/Ks(i))   ! Kfree = Ktotal*total2free
+!       Conversion factor total -> free scale at pressure zero
+        total2free_0p  = 1.d0/(1.d0 + St(i)/Ks_0p)   ! Kfree = Ktotal*total2free
+
+!       Pressure correction on Kf
+!       Kf must be on FREE scale before correction
+        Kf_0p = Kf_0p * total2free_0p   !Convert from Total to Free scale (pressure 0)
+        Kf(i) = Kf_0p * EXP(lnkpok0(6)) !Pressure correction (on Free scale)
+        Kf(i) = Kf(i)/total2free        !Convert back from Free to Total scale
+
+!       Convert between seawater and total hydrogen (pH) scales
+        free2SWS  = 1.d0 + St(i)/Ks(i) + Ft(i)/(Kf(i)*total2free)  ! using Kf on free scale
+        total2SWS = total2free * free2SWS                          ! KSWS = Ktotal*total2SWS
+        SWS2total = 1.d0 / total2SWS
+!       Conversion at pressure zero
+        free2SWS_0p  = 1.d0 + St(i)/Ks_0p + Ft(i)/(Kf_0p)  ! using Kf on free scale
+        total2SWS_0p = total2free_0p * free2SWS_0p         ! KSWS = Ktotal*total2SWS
+
+!       Convert from Total to Seawater scale before pressure correction
+!       Must change to SEAWATER scale: K1, K2, Kb
+        IF (trim(optK1K2) == 'l') THEN
+          K1(i)  = K1(i)*total2SWS_0p
+          K2(i)  = K2(i)*total2SWS_0p
+          !This conversion is unnecessary for the K1,K2 from Millero (2010),
+          !since we use here the formulation already on the seawater scale
+        ENDIF
+        Kb(i)  = Kb(i)*total2SWS_0p
+
+!       Already on SEAWATER scale: K1p, K2p, K3p, Kb, Ksi, Kw
+
+!       Other contants (keep on another scale):
+!          - K0         (independent of pH scale, already pressure corrected)
+!          - Ks         (already on Free scale;   already pressure corrected)
+!          - Kf         (already on Total scale;  already pressure corrected)
+!          - Kspc, Kspa (independent of pH scale; pressure-corrected below)
+
+!       Perform actual pressure correction (on seawater scale)
+        K1(i)   = K1(i)*EXP(lnkpok0(1))
+        K2(i)   = K2(i)*EXP(lnkpok0(2))
+        Kb(i)   = Kb(i)*EXP(lnkpok0(3))
+        Kw(i)   = Kw(i)*EXP(lnkpok0(4))
+        Kspc(i) = Kspc(i)*EXP(lnkpok0(7))
+        Kspa(i) = Kspa(i)*EXP(lnkpok0(8))
+        K1p(i)  = K1p(i)*EXP(lnkpok0(9))
+        K2p(i)  = K2p(i)*EXP(lnkpok0(10))
+        K3p(i)  = K3p(i)*EXP(lnkpok0(11))
+        Ksi(i)  = Ksi(i)*EXP(lnkpok0(12))
+
+!       Convert back to original total scale:
+        K1(i)  = K1(i) *SWS2total
+        K2(i)  = K2(i) *SWS2total
+        K1p(i) = K1p(i)*SWS2total
+        K2p(i) = K2p(i)*SWS2total
+        K3p(i) = K3p(i)*SWS2total
+        Kb(i)  = Kb(i) *SWS2total
+        Ksi(i) = Ksi(i)*SWS2total
+        Kw(i)  = Kw(i) *SWS2total
+
+     ELSE
+
+        K0(i)   = 1.e20_wp
+        K1(i)   = 1.e20_wp
+        K2(i)   = 1.e20_wp
+        Kb(i)   = 1.e20_wp
+        Kw(i)   = 1.e20_wp
+        Ks(i)   = 1.e20_wp
+        Kf(i)   = 1.e20_wp
+        Kspc(i) = 1.e20_wp
+        Kspa(i) = 1.e20_wp
+        K1p(i)  = 1.e20_wp
+        K2p(i)  = 1.e20_wp
+        K3p(i)  = 1.e20_wp
+        Ksi(i)  = 1.e20_wp
+        Bt(i)   = 1.e20_wp
+        Ft(i)   = 1.e20_wp
+        St(i)   = 1.e20_wp
+
+     ENDIF
+
+  END DO
+
+  RETURN
+END SUBROUTINE constants
+
+! ----------------------------------------------------------------------
+!  VARSOLVER
+! ----------------------------------------------------------------------
+!
+!> \file varsolver.f90
+!! \BRIEF 
+!> Module with varsolver subroutine - solve for pH and other carbonate system variables
+!>    Solve for pH and other carbonate system variables (with input from vars routine)
+SUBROUTINE varsolver(ph, pco2, fco2, co2, hco3, co3, OmegaA, OmegaC,             &
+                    temp, salt, ta, tc, pt, sit,                                 &
+                    Bt, St, Ft,                                                  &
+                    K0, K1, K2, Kb, Kw, Ks, Kf, Kspc, Kspa, K1p, K2p, K3p, Ksi,  & 
+                    Patm, Phydro_bar, rhodum, optGAS                             )
+
+  !   Purpose: Solve for pH and other carbonate system variables (with input from vars routine)
+
+  !     INPUT variables:
+  !     ================
+  !     temp    = in situ temperature [degrees C]
+  !     ta      = total alkalinity                     in [eq/m^3] or [eq/kg]   based on optCON in calling routine (vars)
+  !     tc      = dissolved inorganic carbon           in [mol/m^3] or [mol/kg] based on optCON in calling routine (vars)
+  !     pt      = total dissolved inorganic phosphorus in [mol/m^3] or [mol/kg] based on optCON in calling routine (vars)
+  !     sit     = total dissolved inorganic silicon    in [mol/m^3] or [mol/kg] based on optCON in calling routine (vars)
+  !     Bt      = total dissolved inorganic boron      computed in calling routine (vars)
+  !     St      = total dissolved inorganic sulfur     computed in calling routine (vars)
+  !     Ft      = total dissolved inorganic fluorine   computed in calling routine (vars)
+  !     K's     = K0, K1, K2, Kb, Kw, Ks, Kf, Kspc, Kspa, K1p, K2p, K3p, Ksi 
+  !     Patm    = atmospheric pressure [atm]
+  !     Phydro_bar = hydrostatic pressure [bar]
+  !     rhodum  = density factor as computed in calling routine  (vars)
+  !     -----------
+  !     optGAS: choose in situ vs. potential fCO2 and pCO2 (default optGAS = 'Pinsitu')
+  !     ---------
+  !       PRESSURE & T corrections for K0 and the fugacity coefficient (Cf) 
+  !       -> 'Pzero'   = 'zero order' fCO2 and pCO2 (typical approach, which is flawed)
+  !                      considers in situ T & only atm pressure (hydrostatic=0)
+  !       -> 'Ppot'    = 'potential' fCO2 and pCO2 (water parcel brought adiabatically to the surface)
+  !                      considers potential T & only atm pressure (hydrostatic press = 0)
+  !       -> 'Pinsitu' = 'in situ' fCO2 and pCO2 (accounts for huge effects of pressure)
+  !                      considers in situ T & total pressure (atm + hydrostatic)
+  !     ---------
+
+  !     OUTPUT variables:
+  !     =================
+  !     ph   = pH on total scale
+  !     pco2 = CO2 partial pressure (uatm)
+  !     fco2 = CO2 fugacity (uatm)
+  !     co2  = aqueous CO2 concentration in [mol/kg] or [mol/m^3] determined by rhodum (depends on optCON in calling routine)
+  !     hco3 = bicarbonate (HCO3-) concentration in [mol/kg] or [mol/m^3] determined by rhodum
+  !     co3  = carbonate (CO3--) concentration in [mol/kg] or [mol/m^3] determined by rhodum
+  !     OmegaA = Omega for aragonite, i.e., the aragonite saturation state
+  !     OmegaC = Omega for calcite, i.e., the   calcite saturation state
+
+  USE mocsy_singledouble
+  USE mocsy_phsolvers
+
+  IMPLICIT NONE
+
+! Input variables
+  !> <b>in situ temperature</b> [degrees C]
+  REAL(kind=wp), INTENT(in) :: temp
+  !> <b>salinity</b> [on the practical salinity scale, dimensionless]
+  REAL(kind=wp), INTENT(in) :: salt
+  !> total alkalinity in <b>[eq/m^3]</b> OR in <b>[eq/kg]</b>, depending on optCON in calling routine
+  REAL(kind=wp), INTENT(in) :: ta
+  !> dissolved inorganic carbon in <b>[mol/m^3]</b> OR in <b>[mol/kg]</b>, depending on optCON in calling routine
+  REAL(kind=wp), INTENT(in) :: tc
+  !> phosphate concentration in <b>[mol/m^3]</b> OR in <b>[mol/kg]</b>, depending on optCON in calling routine
+  REAL(kind=wp), INTENT(in) :: pt
+  !> total dissolved inorganic silicon concentration in <b>[mol/m^3]</b> OR in <b>[mol/kg]</b>, depending on optCON in calling routine
+  REAL(kind=wp), INTENT(in) :: sit
+  !> total boron from either Uppstrom (1974) or Lee et al. (2010), depending on optB in calling routine
+  REAL(kind=wp), INTENT(in) :: Bt
+  !> total sulfate (Morris & Riley, 1966)
+  REAL(kind=wp), INTENT(in) :: St
+  !> total fluoride  (Riley, 1965)
+  REAL(kind=wp), INTENT(in) :: Ft
+  !> solubility of CO2 in seawater (Weiss, 1974), also known as K0
+  REAL(kind=wp), INTENT(in) :: K0
+  !> K1 for the dissociation of carbonic acid from Lueker et al. (2000) or Millero (2010), depending on optK1K2
+  REAL(kind=wp), INTENT(in) :: K1
+  !> K2 for the dissociation of carbonic acid from Lueker et al. (2000) or Millero (2010), depending on optK1K2
+  REAL(kind=wp), INTENT(in) :: K2
+  !> equilibrium constant for dissociation of boric acid 
+  REAL(kind=wp), INTENT(in) :: Kb
+  !> equilibrium constant for the dissociation of water (Millero, 1995)
+  REAL(kind=wp), INTENT(in) :: Kw
+  !> equilibrium constant for the dissociation of bisulfate (Dickson, 1990)
+  REAL(kind=wp), INTENT(in) :: Ks
+  !> equilibrium constant for the dissociation of hydrogen fluoride 
+  !! from Dickson and Riley (1979) or Perez and Fraga (1987), depending on optKf
+  REAL(kind=wp), INTENT(in) :: Kf
+  !> solubility product for calcite (Mucci, 1983)
+  REAL(kind=wp), INTENT(in) :: Kspc
+  !> solubility product for aragonite (Mucci, 1983)
+  REAL(kind=wp), INTENT(in) :: Kspa
+  !> 1st dissociation constant for phosphoric acid (Millero, 1995)
+  REAL(kind=wp), INTENT(in) :: K1p
+  !> 2nd dissociation constant for phosphoric acid (Millero, 1995)
+  REAL(kind=wp), INTENT(in) :: K2p
+  !> 3rd dissociation constant for phosphoric acid (Millero, 1995)
+  REAL(kind=wp), INTENT(in) :: K3p
+  !> equilibrium constant for the dissociation of silicic acid (Millero, 1995)
+  REAL(kind=wp), INTENT(in) :: Ksi
+  !> total atmospheric pressure <b>[atm]</b>
+  REAL(kind=wp), INTENT(in) :: Patm
+  !> total hydrostatic pressure <b>[bar]</b>
+  REAL(kind=wp), INTENT(in) :: Phydro_bar
+  !> density factor as computed incalling routine  (vars)
+  REAL(kind=wp), INTENT(in) :: rhodum
+  !> for K0,fugacity coefficient choose either \b 'Ppot' (no pressure correction) or \b 'Pinsitu' (with pressure correction) 
+  !! 'Ppot'    - for 'potential' fCO2 and pCO2 (water parcel brought adiabatically to the surface)
+  !! 'Pinsitu' - for 'in situ' values of fCO2 and pCO2, accounting for pressure on K0 and Cf
+  !! with 'Pinsitu' the fCO2 and pCO2 will be many times higher in the deep ocean
+!f2py character*7 optional, intent(in) :: optGAS='Pinsitu'
+  CHARACTER(7), OPTIONAL, INTENT(in) :: optGAS
+
+! Output variables:
+  !> pH on the <b>total scale</b>
+  REAL(kind=wp), INTENT(out) :: ph
+  !> CO2 partial pressure <b>[uatm]</b>
+  REAL(kind=wp), INTENT(out) :: pco2
+  !> CO2 fugacity <b>[uatm]</b>
+  REAL(kind=wp), INTENT(out) :: fco2
+  !> aqueous CO2* concentration, either in <b>[mol/m^3]</b> or <b>[mol/kg</b>] depending on choice for optCON
+  REAL(kind=wp), INTENT(out) :: co2
+  !> bicarbonate ion (HCO3-) concentration, either in <b>[mol/m^3]</b> or <b>[mol/kg]</b> depending on choice for optCON
+  REAL(kind=wp), INTENT(out) :: hco3
+  !> carbonate ion (CO3--) concentration, either in <b>[mol/m^3]</b> or <b>[mol/kg]</b> depending on choice for optCON
+  REAL(kind=wp), INTENT(out) :: co3
+  !> Omega for aragonite, i.e., the aragonite saturation state
+  REAL(kind=wp), INTENT(out) :: OmegaA
+  !> Omega for calcite, i.e., the calcite saturation state
+  REAL(kind=wp), INTENT(out) :: OmegaC
+
+! Local variables
+  REAL(kind=wp) :: Phydro_atm, Ptot
+  REAL(kind=wp) :: Rgas_atm, B, Del, xCO2approx, xc2, fugcoeff
+  REAL(kind=wp) :: tk, tk0
+  real(kind=wp) :: temp68, tempot, tempot68
+  REAL(kind=wp) :: Hinit, H
+  REAL(kind=wp) :: HSO4, HF, HSI, HPO4
+  REAL(kind=wp) :: ab, aw, ac
+  REAL(kind=wp) :: cu, cb, cc
+  REAL(kind=wp) :: Ca
+! Array to pass optional arguments
+  CHARACTER(7) :: opGAS
+
+  IF (PRESENT(optGAS)) THEN
+    opGAS = optGAS
+  ELSE
+    opGAS = 'Pinsitu'
+  ENDIF
+
+! Compute pH from constants and total concentrations
+! - use SolveSAPHE v1.0.1 routines from Munhoven (2013, GMD) modified to use mocsy's Ks instead of its own
+! 1) Compute best starting point for H+ calculation
+  call ahini_for_at(ta, tc, Bt, K1, K2, Kb, Hinit)
+! 2) Solve for H+ using above result as the initial H+ value
+  H = solve_at_general(ta, tc, Bt,                                         & 
+                       pt,     sit,                                        &
+                       St, Ft,                                             &
+                       K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi,     &
+                       Hinit)
+! 3) Calculate pH from from H+ concentration (mol/kg)
+  IF (H > 0.d0) THEN
+     pH = -1.*LOG10(H)
+  ELSE
+     pH = 1.e20_wp
+  ENDIF
+
+! Compute carbonate Alk (Ac) by difference: from total Alk and other Alk components
+  HSO4 = St/(1.0d0 + Ks/(H/(1.0d0 + St/Ks)))
+  HF = 1.0d0/(1.0d0 + Kf/H)
+  HSI = 1.0d0/(1.0d0 + H/Ksi)
+  HPO4 = (K1p*K2p*(H + 2.*K3p) - H**3) /                &
+  (H**3 + K1p*H**2 + K1p*K2p*H + K1p*K2p*K3p)
+  ab = Bt/(1.0d0 + H/Kb)
+  aw = Kw/H - H/(1.0d0 + St/Ks)
+  ac = ta + hso4 - sit*hsi - ab - aw + Ft*hf - pt*hpo4
+
+! Calculate CO2*, HCO3-, & CO32- (in mol/kg soln) from Ct, Ac, H+, K1, & K2
+  cu = (2.0d0 * tc - ac) / (2.0d0 + K1 / H)
+  cb = K1 * cu / H
+  cc = K2 * cb / H
+
+! When optCON = 'mol/m3' in calling routine (vars), then:
+! convert output var concentrations from mol/kg to mol/m^3
+! e.g., for case when drho = 1028, multiply by [1.028 kg/L  x  1000 L/m^3])
+  co2  = cu * rhodum
+  hco3 = cb * rhodum
+  co3  = cc * rhodum
+
+! Determine CO2 fugacity [uatm]
+! NOTE: equation just below requires CO2* in mol/kg
+  fCO2 = cu * 1.e6_wp/K0
+
+! Determine CO2 partial pressure from CO2 fugacity [uatm]
+  tk = 273.15d0 + temp
+  !Compute EITHER "potential pCO2" OR "in situ pCO2" (T and P used for calculations will differ)
+  IF     (trim(opGAS) == 'Pzero'   .OR. trim(opGAS) == 'pzero') THEN
+     tk0 = tk                 !in situ temperature (K) for K0 calculation
+     Ptot = Patm              !total pressure (in atm) = atmospheric pressure ONLY
+  ELSEIF (trim(opGAS) == 'Ppot' .OR. trim(opGAS) == 'ppot') THEN
+     !Use potential temperature and atmospheric pressure (water parcel adiabatically brought back to surface)
+     !temp68 = (temp - 0.0002d0) / 0.99975d0          !temp = in situ T; temp68 is same converted to ITPS-68 scale
+     !tempot68 = sw_ptmp(salt, temp68, Phydro_bar*10d0, 0.0d0) !potential temperature (C)
+     !tempot   = 0.99975*tempot68 + 0.0002
+     !tk0 = tempot + 273.15d0  !potential temperature (K) for fugacity coeff. calc as needed for potential fCO2 & pCO2
+     tempot = sw_ptmp(salt, temp, Phydro_bar*10._wp, 0.0_wp) !potential temperature (C)
+     tk0 = tempot + 273.15d0  !potential temperature (K) for fugacity coeff. calc as needed for potential fCO2 & pCO2
+     Ptot = Patm              !total pressure (in atm) = atmospheric pressure ONLY
+  ELSEIF (trim(opGAS) == 'Pinsitu' .OR. trim(opGAS) == 'pinsitu') THEN
+     !Use in situ temperature and total pressure 
+     tk0 = tk                             !in situ temperature (K) for fugacity coefficient calculation
+     Phydro_atm = Phydro_bar / 1.01325d0  !convert hydrostatic pressure from bar to atm (1.01325 bar / atm)
+     Ptot = Patm + Phydro_atm            !total pressure (in atm) = atmospheric pressure + hydrostatic pressure
+  ELSE
+     PRINT *, "optGAS must be 'Pzero', 'Ppot', or 'Pinsitu'"
+     STOP
+  ENDIF
+
+! Now that we have T and P in the right form, continue with calculation of fugacity coefficient (and pCO2)
+  Rgas_atm = 82.05736_wp      ! (cm3 * atm) / (mol * K)  CODATA (2006)
+! To compute fugcoeff, we need 3 other terms (B, Del, xc2) in addition to 3 others above (tk, Ptot, Rgas_atm)
+  B = -1636.75d0 + 12.0408d0*tk0 - 0.0327957d0*(tk0*tk0) + 0.0000316528d0*(tk0*tk0*tk0)
+  Del = 57.7d0 - 0.118d0*tk0
+! "x2" term often neglected (assumed = 1) in applications of Weiss's (1974) equation 9
+! x2 = 1 - x1 = 1 - xCO2 (it is very close to 1, but not quite)
+! Let's assume that xCO2 = fCO2. Resulting fugcoeff is identical to 8th digit after the decimal.
+  xCO2approx = fCO2 * 1.e-6_wp
+  IF (trim(opGAS) == 'Pinsitu' .OR. trim(opGAS) == 'pinsitu') THEN
+!    xCO2approx = 400.0e-6_wp      !a simple test (gives about same result as seacarb for pCO2insitu)
+!    approximate surface xCO2 ~ surface fCO2 (i.e., in situ fCO2 d by exponential pressure correction)
+     xCO2approx = xCO2approx * exp( ((1-Ptot)*32.3_wp)/(82.05736_wp*tk0) )   ! of K0 press. correction, see Weiss (1974, equation 5)
+  ENDIF
+  xc2 = (1.0d0 - xCO2approx)**2 
+  fugcoeff = exp( Ptot*(B + 2.0d0*xc2*Del)/(Rgas_atm*tk0) )
+  pCO2 = fCO2 / fugcoeff
+
+! Determine Omega Calcite et Aragonite
+! OmegaA = ((0.01028d0*salt/35.0d0)*cc) / Kspa
+! OmegaC = ((0.01028d0*salt/35.0d0)*cc) / Kspc
+! - see comments from Munhoven on the best value "0.02128" which differs slightly from the best practices guide (0.02127)
+  Ca = (0.02128d0/40.078d0) * salt/1.80655d0
+  OmegaA = (Ca*cc) / Kspa
+  OmegaC = (Ca*cc) / Kspc
+
+  RETURN
+END SUBROUTINE varsolver
+
+! ----------------------------------------------------------------------
+!  VARS
+! ----------------------------------------------------------------------
+!
+!> \file vars.f90
+!! \BRIEF 
+!> Module with vars subroutine - compute carbonate system vars from DIC,Alk,T,S,P,nuts
+!>    Computes standard carbonate system variables (pH, CO2*, HCO3- and CO32-, OmegaA, OmegaC, R)
+!!    as 1D arrays FROM
+!!    temperature, salinity, pressure,
+!!    total alkalinity (ALK), dissolved inorganic carbon (DIC),
+!!    silica and phosphate concentrations (all 1-D arrays)
+SUBROUTINE vars(ph, pco2, fco2, co2, hco3, co3, OmegaA, OmegaC, BetaD, rhoSW, p, tempis,  &
+                temp, sal, alk, dic, sil, phos, Patm, depth, lat, N,                      &
+                optCON, optT, optP, optB, optK1K2, optKf, optGAS                          )
+
+  !   Purpose:
+  !     Computes other standard carbonate system variables (pH, CO2*, HCO3- and CO32-, OmegaA, OmegaC, R)
+  !     as 1D arrays
+  !     FROM:
+  !     temperature, salinity, pressure,
+  !     total alkalinity (ALK), dissolved inorganic carbon (DIC),
+  !     silica and phosphate concentrations (all 1-D arrays)
+
+  !     INPUT variables:
+  !     ================
+  !     Patm    = atmospheric pressure [atm]
+  !     depth   = depth [m]     (with optP='m', i.e., for a z-coordinate model vertical grid is depth, not pressure)
+  !             = pressure [db] (with optP='db')
+  !     lat     = latitude [degrees] (needed to convert depth to pressure, i.e., when optP='m')
+  !             = dummy array (unused when optP='db')
+  !     temp    = potential temperature [degrees C] (with optT='Tpot', i.e., models carry tempot, not in situ temp)
+  !             = in situ   temperature [degrees C] (with optT='Tinsitu', e.g., for data)
+  !     sal     = salinity in [psu]
+  !     alk     = total alkalinity in [eq/m^3] with optCON = 'mol/m3'
+  !             =               [eq/kg]  with optCON = 'mol/kg'
+  !     dic     = dissolved inorganic carbon [mol/m^3] with optCON = 'mol/m3'
+  !             =                            [mol/kg]  with optCON = 'mol/kg'
+  !     sil     = silica    [mol/m^3] with optCON = 'mol/m3'
+  !             =           [mol/kg]  with optCON = 'mol/kg'
+  !     phos    = phosphate [mol/m^3] with optCON = 'mol/m3'
+  !             =           [mol/kg]  with optCON = 'mol/kg'
+  !     INPUT options:
+  !     ==============
+  !     -----------
+  !     optCON: choose input & output concentration units - mol/kg (data) vs. mol/m^3 (models)
+  !     -----------
+  !       -> 'mol/kg' for DIC, ALK, sil, & phos given on mokal scale, i.e., in mol/kg  (std DATA units)
+  !       -> 'mol/m3' for DIC, ALK, sil, & phos given in mol/m^3 (std MODEL units)
+  !     -----------
+  !     optT: choose in situ vs. potential temperature as input
+  !     ---------
+  !     NOTE: Carbonate chem calculations require IN-SITU temperature (not potential Temperature)
+  !       -> 'Tpot' means input is pot. Temperature (in situ Temp "tempis" is computed)
+  !       -> 'Tinsitu' means input is already in-situ Temperature, not pot. Temp ("tempis" not computed)
+  !     ---------
+  !     optP: choose depth (m) vs pressure (db) as input
+  !     ---------
+  !       -> 'm'  means "depth" input is in "m" (thus in situ Pressure "p" [db] is computed)
+  !       -> 'db' means "depth" input is already in situ pressure [db], not m (thus p = depth)
+  !     ---------
+  !     optB: choose total boron formulation - Uppström (1974) vs. Lee et al. (2010)
+  !     ---------
+  !       -> 'u74' means use classic formulation of Uppström (1974) for total Boron
+  !       -> 'l10' means use newer   formulation of Lee et al. (2010) for total Boron
+  !     ---------
+  !     optK1K2:
+  !     ---------
+  !       -> 'l'   means use Lueker et al. (2000) formulations for K1 & K2 (recommended by Dickson et al. 2007)
+  !                **** BUT this should only be used when 2 < T < 35 and 19 < S < 43
+  !       -> 'm10' means use Millero (2010) formulation for K1 & K2 (see Dickson et al., 2007)
+  !                **** Valid for 0 < T < 50°C and 1 < S < 50 psu
+  !     ----------
+  !     optKf:
+  !     ----------
+  !       -> 'pf' means use Perez & Fraga (1987) formulation for Kf (recommended by Dickson et al., 2007)
+  !               **** BUT Valid for  9 < T < 33°C and 10 < S < 40.
+  !       -> 'dg' means use Dickson & Riley (1979) formulation for Kf (recommended by Dickson & Goyet, 1994)
+  !     -----------
+  !     optGAS: choose in situ vs. potential fCO2 and pCO2
+  !     ---------
+  !       PRESSURE corrections for K0 and the fugacity coefficient (Cf) 
+  !       -> 'Pzero'   = 'zero order' fCO2 and pCO2 (typical approach, which is flawed)
+  !                      considers in situ T & only atm pressure (hydrostatic=0)
+  !       -> 'Ppot'    = 'potential' fCO2 and pCO2 (water parcel brought adiabatically to the surface)
+  !                      considers potential T & only atm pressure (hydrostatic press = 0)
+  !       -> 'Pinsitu' = 'in situ' fCO2 and pCO2 (accounts for huge effects of pressure)
+  !                      considers in situ T & total pressure (atm + hydrostatic)
+  !     ---------
+
+  !     OUTPUT variables:
+  !     =================
+  !     ph   = pH on total scale
+  !     pco2 = CO2 partial pressure (uatm)
+  !     fco2 = CO2 fugacity (uatm)
+  !     co2  = aqueous CO2 concentration in [mol/kg] or [mol/m^3] depending on optCON
+  !     hco3 = bicarbonate (HCO3-) concentration in [mol/kg] or [mol/m^3] depending on optCON
+  !     co3  = carbonate (CO3--) concentration in [mol/kg] or [mol/m^3] depending on optCON
+  !     OmegaA = Omega for aragonite, i.e., the aragonite saturation state
+  !     OmegaC = Omega for calcite, i.e., the   calcite saturation state
+  !     BetaD = Revelle factor   dpCO2/pCO2 / dDIC/DIC
+  !     rhoSW  = in-situ density of seawater; rhoSW = f(s, t, p)
+  !     p = pressure [decibars]; p = f(depth, latitude) if computed from depth [m] OR p = depth if [db]
+  !     tempis  = in-situ temperature [degrees C]
+
+  USE mocsy_singledouble
+
+  IMPLICIT NONE
+
+! Input variables
+  !>     number of records
+  INTEGER, INTENT(in) :: N
+  !> either <b>in situ temperature</b> (when optT='Tinsitu', typical data) 
+  !! OR <b>potential temperature</b> (when optT='Tpot', typical models) <b>[degree C]</b>
+  REAL(kind=wp), INTENT(in),    DIMENSION(N) :: temp
+  !> salinity <b>[psu]</b>
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: sal
+  !> total alkalinity in <b>[eq/m^3]</b> (when optCON = 'mol/m3') OR in <b>[eq/kg]</b>  (when optCON = 'mol/kg')
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: alk
+  !> dissolved inorganic carbon in <b>[mol/m^3]</b> (when optCON = 'mol/m3') OR in <b>[mol/kg]</b> (when optCON = 'mol/kg')
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: dic
+  !> SiO2 concentration in <b>[mol/m^3]</b> (when optCON = 'mol/m3') OR in <b>[mol/kg]</b> (when optCON = 'mol/kg')
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: sil
+  !> phosphate concentration in <b>[mol/m^3]</b> (when optCON = 'mol/m3') OR in <b>[mol/kg]</b> (when optCON = 'mol/kg')
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: phos
+!f2py optional , depend(sal) :: n=len(sal)
+  !> atmospheric pressure <b>[atm]</b>
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: Patm
+  !> depth in \b meters (when optP='m') or \b decibars (when optP='db')
+  REAL(kind=wp), INTENT(in),    DIMENSION(N) :: depth
+  !> latitude <b>[degrees north]</b>
+  REAL(kind=wp), INTENT(in),    DIMENSION(N) :: lat
+
+  !> choose either \b 'mol/kg' (std DATA units) or \b 'mol/m3' (std MODEL units) to select 
+  !! concentration units for input (for alk, dic, sil, phos) & output (co2, hco3, co3)
+  CHARACTER(6), INTENT(in) :: optCON
+  !> choose \b 'Tinsitu' for in situ temperature or \b 'Tpot' for potential temperature (in situ Temp is computed, needed for models)
+  CHARACTER(7), INTENT(in) :: optT
+  !> for depth input, choose \b "db" for decibars (in situ pressure) or \b "m" for meters (pressure is computed, needed for models)
+  CHARACTER(2), INTENT(in) :: optP
+  !> for total boron, choose either \b 'u74' (Uppstrom, 1974) or \b 'l10' (Lee et al., 2010).
+  !! The 'l10' formulation is based on 139 measurements (instead of 20), 
+  !! uses a more accurate method, and
+  !! generally increases total boron in seawater by 4% 
+!f2py character*3 optional, intent(in) :: optB='l10'
+  CHARACTER(3), OPTIONAL, INTENT(in) :: optB
+  !> for Kf, choose either \b 'pf' (Perez & Fraga, 1987) or \b 'dg' (Dickson & Riley, 1979)
+!f2py character*2 optional, intent(in) :: optKf='pf'
+  CHARACTER(2), OPTIONAL, INTENT(in) :: optKf
+  !> for K1,K2 choose either \b 'l' (Lueker et al., 2000) or \b 'm10' (Millero, 2010) 
+!f2py character*3 optional, intent(in) :: optK1K2='l'
+  CHARACTER(3), OPTIONAL, INTENT(in) :: optK1K2
+  !> for K0,fugacity coefficient choose either \b 'Ppot' (no pressure correction) or \b 'Pinsitu' (with pressure correction) 
+  !! 'Ppot'    - for 'potential' fCO2 and pCO2 (water parcel brought adiabatically to the surface)
+  !! 'Pinsitu' - for 'in situ' values of fCO2 and pCO2, accounting for pressure on K0 and Cf
+  !! with 'Pinsitu' the fCO2 and pCO2 will be many times higher in the deep ocean
+!f2py character*7 optional, intent(in) :: optGAS='Pinsitu'
+  CHARACTER(7), OPTIONAL, INTENT(in) :: optGAS
+
+! Output variables:
+  !> pH on the <b>total scale</b>
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: ph
+  !> CO2 partial pressure <b>[uatm]</b>
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: pco2
+  !> CO2 fugacity <b>[uatm]</b>
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: fco2
+  !> aqueous CO2* concentration, either in <b>[mol/m^3]</b> or <b>[mol/kg</b>] depending on choice for optCON
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: co2
+  !> bicarbonate ion (HCO3-) concentration, either in <b>[mol/m^3]</b> or <b>[mol/kg]</b> depending on choice for optCON
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: hco3
+  !> carbonate ion (CO3--) concentration, either in <b>[mol/m^3]</b> or <b>[mol/kg]</b> depending on choice for optCON
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: co3
+  !> Omega for aragonite, i.e., the aragonite saturation state
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: OmegaA
+  !> Omega for calcite, i.e., the calcite saturation state
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: OmegaC
+  !> Revelle factor, i.e., dpCO2/pCO2 / dDIC/DIC
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: BetaD
+  !> in-situ density of seawater; rhoSW = f(s, t, p) in <b>[kg/m3]</b>
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: rhoSW
+  !> pressure <b>[decibars]</b>; p = f(depth, latitude) if computed from depth [m] (when optP='m') OR p = depth [db] (when optP='db')
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: p
+  !> in-situ temperature \b <b>[degrees C]</b>
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: tempis
+
+! Local variables
+  REAL(kind=wp) :: ssal, salk, sdic, ssil, sphos
+
+  REAL(kind=wp) :: tempot, tempis68, tempot68
+! REAL(kind=wp) :: dtempot, dtempot68
+  REAL(kind=wp) :: drho
+
+  REAL(kind=wp) :: K0, K1, K2, Kb, Kw, Ks, Kf, Kspc
+  REAL(kind=wp) :: Kspa, K1p, K2p, K3p, Ksi
+  REAL(kind=wp) :: St, Ft, Bt
+
+  REAL(kind=wp), DIMENSION(1) :: aK0, aK1, aK2, aKb, aKw, aKs, aKf, aKspc
+  REAL(kind=wp), DIMENSION(1) :: aKspa, aK1p, aK2p, aK3p, aKsi
+  REAL(kind=wp), DIMENSION(1) :: aSt, aFt, aBt
+
+  REAL(kind=wp) :: Patmd, Ptot, Rgas_atm, B, Del, xCO2approx, xc2, fugcoeff
+  REAL(kind=wp) :: Phydro_atm
+
+  INTEGER :: i, icount
+
+  REAL(kind=wp) :: t, tk, prb
+  REAL(kind=wp) :: s
+  REAL(kind=wp) :: tc, ta
+  REAL(kind=wp) :: sit, pt
+  REAL(kind=wp) :: Hinit
+  REAL(kind=wp) :: ah1
+
+  REAL(kind=wp) :: HSO4, HF, HSI, HPO4
+  REAL(kind=wp) :: ab, aw, ac, ah2, erel
+
+  REAL(kind=wp) :: cu, cb, cc
+
+  REAL(kind=wp), DIMENSION(2) :: dicdel, pco2del
+  REAL(kind=wp) :: dx, Rf
+  REAL(kind=wp) :: dph, dpco2, dfco2, dco2, dhco3, dco3, dOmegaA, dOmegaC
+
+  INTEGER :: kcomp
+  INTEGER :: j, minusplus
+
+! Arrays to pass optional arguments into or use defaults (Dickson et al., 2007)
+  CHARACTER(3) :: opB
+  CHARACTER(2) :: opKf
+  CHARACTER(3) :: opK1K2
+  CHARACTER(7) :: opGAS
+
+! Set defaults for optional arguments (in Fortran 90)
+! Note:  Optional arguments with f2py (python) are set above with 
+!        the !f2py statements that precede each type declaraion
+  IF (PRESENT(optB)) THEN
+!   print *,"optB present:"
+!   print *,"optB = ", optB 
+    opB = optB
+  ELSE
+!   Default is Lee et al (2010) for total boron
+!   print *,"optB NOT present:"
+    opB = 'l10'
+!   print *,"opB = ", opB 
+  ENDIF
+  IF (PRESENT(optKf)) THEN
+!   print *,"optKf = ", optKf
+    opKf = optKf
+  ELSE
+!   print *,"optKf NOT present:"
+!   Default is Perez & Fraga (1987) for Kf
+    opKf = 'pf'
+!   print *,"opKf = ", opKf
+  ENDIF
+  IF (PRESENT(optK1K2)) THEN
+!   print *,"optK1K2 = ", optK1K2
+    opK1K2 = optK1K2
+  ELSE
+!   print *,"optK1K2 NOT present:"
+!   Default is Lueker et al. 2000) for K1 & K2
+    opK1K2 = 'l'
+!   print *,"opK1K2 = ", opK1K2
+  ENDIF
+  IF (PRESENT(optGAS)) THEN
+    opGAS = optGAS
+  ELSE
+    opGAS = 'Pinsitu'
+  ENDIF
+
+  icount = 0
+  DO i = 1, N
+     icount = icount + 1
+!    ===============================================================
+!    Convert model depth -> press; convert model Theta -> T in situ
+!    ===============================================================
+!    * Model temperature tracer is usually "potential temperature"
+!    * Model vertical grid is usually in meters
+!    BUT carbonate chem routines require pressure & in-situ T
+!    Thus before computing chemistry, if appropriate,
+!    convert these 2 model vars (input to this routine)
+!    - depth [m] => convert to pressure [db]
+!    - potential temperature (C) => convert to in-situ T (C)
+!    -------------------------------------------------------
+!    1)  Compute pressure [db] from depth [m] and latitude [degrees] (if input is m, for models)
+     !print *,"optP =", optP, "end"
+     IF (trim(optP) == 'm' ) THEN
+!       Compute pressure [db] from depth [m] and latitude [degrees]
+        p(i) = p80(depth(i), lat(i))
+     ELSEIF (trim(optP) == 'db') THEN
+!       In this case (where optP = 'db'), p is input & output (no depth->pressure conversion needed)
+        p(i) = depth(i)
+     ELSE
+        !print *,"optP =", optP, "end"
+        PRINT *,"optP must be either 'm' or 'db'"
+        STOP
+     ENDIF
+
+!    2) Convert potential T to in-situ T (if input is Tpot, i.e. case for models):
+     IF (trim(optT) == 'Tpot' .OR. trim(optT) == 'tpot') THEN
+        tempot = temp(i)
+!       This is the case for most models and some data
+!       a) Convert the pot. temp on today's "ITS 90" scale to older IPTS 68 scale
+!          (see Dickson et al., Best Practices Guide, 2007, Chap. 5, p. 7, including footnote)
+        tempot68 = (tempot - 0.0002) / 0.99975
+!       b) Compute "in-situ Temperature" from "Potential Temperature" (both on IPTS 68)
+        tempis68 = sw_temp(sal(i), tempot68, p(i), 0.0_wp )
+!       c) Convert the in-situ temp on older IPTS 68 scale to modern scale (ITS 90)
+        tempis(i) = 0.99975*tempis68 + 0.0002
+!       Note: parts (a) and (c) above are tiny corrections;
+!             part  (b) is a big correction for deep waters (but zero at surface)
+     ELSEIF (trim(optT) == 'Tinsitu' .OR. trim(optT) == 'tinsitu') THEN
+!       When optT = 'Tinsitu', tempis is input & output (no tempot needed)
+        tempis(i) = temp(i)
+        tempis68  = (temp(i) - 0.0002) / 0.99975
+!       dtempot68 = sw_ptmp(DBLE(sal(i)), DBLE(tempis68), DBLE(p), 0.0d0)
+!       dtempot   = 0.99975*dtempot68 + 0.0002
+     ELSE
+        PRINT *,"optT must be either 'Tpot' or 'Tinsitu'"
+        PRINT *,"you specified optT =", trim(optT) 
+        STOP
+     ENDIF
+
+!    ================================================================
+!    Carbonate chemistry computations
+!    ================================================================
+     IF (dic(i) > 0. .AND. dic(i) < 1.0e+4) THEN
+!       Test to indicate if any of input variables are unreasonable
+        IF (       sal(i) < 0.   &
+             .OR.  alk(i) < 0.   &
+             .OR.  dic(i) < 0.   &
+             .OR.  sil(i) < 0.   &
+             .OR. phos(i) < 0.   &
+             .OR.  sal(i) > 1e+3 &
+             .OR.  alk(i) > 1e+3 &
+             .OR.  dic(i) > 1e+3 &
+             .OR.  sil(i) > 1e+3 &
+             .OR. phos(i) > 1e+3) THEN
+           PRINT *, 'i, icount, tempot, sal,    alk,    dic,    sil,    phos =', &
+                     i, icount, tempot, sal(i), alk(i), dic(i), sil(i), phos(i)
+        ENDIF
+!       Zero out any negative salinity, phosphate, silica, dic, and alk
+        IF (sal(i) < 0.0) THEN
+           ssal = 0.0
+        ELSE
+           ssal = sal(i)
+        ENDIF
+        IF (phos(i) < 0.0) THEN
+           sphos = 0.0
+        ELSE
+           sphos = phos(i)
+        ENDIF
+        IF (sil(i) < 0.0) THEN
+           ssil = 0.0
+        ELSE
+           ssil = sil(i)
+        ENDIF
+        IF (dic(i) < 0.0) THEN
+          sdic = 0.0
+        ELSE
+          sdic = dic(i)
+        ENDIF
+        IF (alk(i) < 0.0) THEN
+          salk = 0.0
+        ELSE
+          salk = alk(i)
+        ENDIF
+
+!       Absolute temperature (Kelvin) & related variables
+        t  = DBLE(tempis(i))
+        tk = 273.15d0 + t
+
+!       Atmospheric pressure
+        Patmd = DBLE(Patm(i))
+!       Hydrostatic pressure (prb is in bars)
+        prb = DBLE(p(i)) / 10.0d0
+        Phydro_atm = prb / 1.01325d0  ! convert hydrostatic pressure from bar to atm (1.01325 bar / atm)
+!       Total pressure [atm]
+        IF     (trim(opGAS) == 'Pzero'     .OR. trim(opGAS) == 'pzero') THEN
+           Ptot = Patmd               ! total pressure (in atm) = atmospheric pressure ONLY
+        ELSEIF (trim(opGAS) == 'Ppot'    .OR. trim(opGAS) == 'ppot') THEN
+           Ptot = Patmd               ! total pressure (in atm) = atmospheric pressure ONLY
+        ELSEIF (trim(opGAS) == 'Pinsitu' .OR. trim(opGAS) == 'pinsitu') THEN
+           Ptot = Patmd + Phydro_atm   ! total pressure (in atm) = atmospheric pressure + hydrostatic pressure
+        ELSE
+           PRINT *, "optGAS must be 'Pzero', 'Ppot', or 'Pinsitu'"
+           STOP
+        ENDIF
+
+!       Salinity (equivalent array in double precision)
+        s = DBLE(ssal)
+
+!       Get all equilibrium constants and total concentrations of SO4, F, B
+        CALL constants(aK0, aK1, aK2, aKb, aKw, aKs, aKf, aKspc, aKspa,  &
+                       aK1p, aK2p, aK3p, aKsi,                           &
+                       aSt, aFt, aBt,                                    &
+                       temp(i), sal(i), Patm(i),                         &
+                       depth(i), lat(i), 1,                              &
+                       optT, optP, opB, opK1K2, opKf, opGAS              )
+
+!       Unlike f77, in F90 we can't assign an array (dimen=1) to a scalar in a routine argument
+!       Thus, set scalar constants equal to array (dimension=1) values required as arguments
+        K0 = aK0(1) ; K1 = aK1(1) ; K2 = aK2(1) ; Kb = aKb(1) ; Kw = aKw(1) 
+        Ks = aKs(1) ; Kf = aKs(1) ; Kspc = aKspc(1) ; Kspa = aKspa(1) 
+        K1p = aK1p(1) ; K2p = aK2p(1) ; K3p = aK3p(1) ; Ksi = aKsi(1)
+        St = aSt(1) ; Ft = aFt(1) ; Bt = aBt(1)
+
+!       Compute in-situ density [kg/m^3]
+        rhoSW(i) =  rho(ssal, tempis68, prb)
+
+!       Either convert units of DIC and ALK (MODEL case) or not (DATA case)
+        IF     (trim(optCON) == 'mol/kg') THEN
+!          No conversion:
+!          print *,'DIC and ALK already given in mol/kg (std DATA units)'
+           drho = 1.
+        ELSEIF (trim(optCON) == 'mol/m3') THEN
+!          Do conversion:
+!          print *,"DIC and ALK given in mol/m^3 (std MODEL units)"
+           drho = DBLE(rhoSW(i))
+        ELSE
+           PRINT *,"optCON must be either 'mol/kg' or 'mol/m3'"
+           STOP
+        ENDIF
+
+        tc  = DBLE(sdic)/drho
+        ta  = DBLE(salk)/drho
+        sit = DBLE(ssil)/drho
+        pt  = DBLE(sphos)/drho
+
+!       Solve for pH and all other variables
+!       ------------------------------------
+        CALL varsolver(dph, dpco2, dfco2, dco2, dhco3, dco3, dOmegaA, dOmegaC,     &
+                      t, s, ta, tc, pt, sit,                                       &
+                      Bt, St, Ft,                                                  &
+                      K0, K1, K2, Kb, Kw, Ks, Kf, Kspc, Kspa, K1p, K2p, K3p, Ksi,  & 
+                      Patmd, prb, drho, opGAS                                     )
+
+!       Convert all output variables from double to single precision
+        pH(i)     = REAL(dph)
+        co2(i)    = REAL(dco2)
+        hco3(i)   = REAL(dhco3)
+        co3(i)    = REAL(dco3)
+        fCO2(i)   = REAL(dfCO2)
+        pCO2(i)   = REAL(dpCO2)
+        OmegaA(i) = REAL(dOmegaA)
+        OmegaC(i) = REAL(dOmegaC)
+
+!       Compute Revelle factor numerically (derivative using centered-difference scheme)
+        DO j=1,2
+           minusplus = (-1)**j
+           dx = 0.1 * 1e-6         ! Numerical tests found for DIC that optimal dx = 0.1 umol/kg (0.1e-6 mol/kg)
+           dicdel(j) = tc + DBLE(minusplus)*dx/2.0d0
+            CALL varsolver(dph, dpco2, dfco2, dco2, dhco3, dco3, dOmegaA, dOmegaC, &
+               t, s, ta, dicdel(j), pt, sit,                                       &
+               Bt, St, Ft,                                                         &
+               K0, K1, K2, Kb, Kw, Ks, Kf, Kspc, Kspa, K1p, K2p, K3p, Ksi,         & 
+               Patmd, prb, drho, optGAS                                            )
+            pco2del(j) = dpco2
+        END DO
+       !Classic finite centered difference formula for derivative (2nd order accurate)
+        Rf = (pco2del(2) - pco2del(1)) / (dicdel(2) - dicdel(1))       ! dpCO2/dDIC
+       !Rf = (pco2del(2) - pco2del(1)) / (dx)                          ! dpCO2/dDIC (same as just above)
+        Rf = Rf * tc / dpco2                                           ! R = (dpCO2/dDIC) * (DIC/pCO2)
+
+        BetaD(i) = REAL(Rf)
+
+     ELSE
+
+        ph(i)     = 1.e20_wp
+        pco2(i)   = 1.e20_wp
+        fco2(i)   = 1.e20_wp
+        co2(i)    = 1.e20_wp
+        hco3(i)   = 1.e20_wp
+        co3(i)    = 1.e20_wp
+        OmegaA(i) = 1.e20_wp
+        OmegaC(i) = 1.e20_wp
+        BetaD(i)  = 1.e20_wp
+        rhoSW(i)  = 1.e20_wp
+        p(i)      = 1.e20_wp
+        tempis(i) = 1.e20_wp
+
+     ENDIF
+
+  END DO
+
+  RETURN
+END SUBROUTINE vars
+
+! ----------------------------------------------------------------------
+!  P2FCO2
+! ----------------------------------------------------------------------
+!
+!> \file p2fCO2.f90
+!! \BRIEF 
+!>    Module with p2fCO2 subroutine - compute fCO2 from pCO2, in situ T, atm pressure, hydrostatic pressure
+!>    Compute fCO2 from arrays of pCO2, in situ temp, atm pressure, & hydrostatic pressure
+SUBROUTINE p2fCO2(pCO2, temp, Patm, p, N, fCO2)
+  !    Purpose:
+  !    Compute fCO2 from arrays of pCO2, in situ temp, atm pressure, & hydrostatic pressure
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, INTENT(in) :: N
+
+! INPUT variables
+  !> oceanic partial pressure of CO2 [uatm]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: pCO2
+  !> in situ temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: temp
+  !> atmospheric pressure [atm]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: Patm
+  !> hydrostatic pressure [db]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: p
+!f2py optional , depend(pCO2) :: n=len(pCO2)
+
+! OUTPUT variables:
+  !> fugacity of CO2 [uatm] 
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: fCO2
+
+! LOCAL variables:
+  REAL(kind=wp) :: dpCO2, dtemp, tk, dPatm, prb
+  REAL(kind=wp) :: Ptot, Rgas_atm, B, Del, xCO2approx, xc2, fugcoeff
+  REAL(kind=wp) :: dfCO2
+
+  INTEGER :: i
+
+! REAL(kind=wp) :: sw_ptmp
+! EXTERNAL sw_ptmp
+
+  DO i = 1,N
+     dpCO2     = DBLE(pCO2(i))
+     dtemp     = DBLE(temp(i))
+     dPatm     = DBLE(Patm(i))
+     tk = 273.15d0 + DBLE(temp(i))     !Absolute temperature (Kelvin)
+     prb = DBLE(p(i)) / 10.0d0         !Pressure effect (prb is in bars)
+     Ptot = dPatm + prb/1.01325d0      !Total pressure (atmospheric + hydrostatic) [atm]
+     Rgas_atm = 82.05736_wp            !R in (cm3 * atm) / (mol * K)  from CODATA (2006)
+!    To compute fugcoeff, we need 3 other terms (B, Del, xc2) as well as 3 others above (tk, Ptot, Rgas_atm)
+     B = -1636.75d0 + 12.0408d0*tk - 0.0327957d0*(tk*tk) + 0.0000316528d0*(tk*tk*tk)
+     Del = 57.7d0 - 0.118d0*tk
+!    "x2" term often neglected (assumed = 1) in applications of Weiss's (1974) equation 9
+!    x2 = 1 - x1 = 1 - xCO2 (it is very close to 1, but not quite)
+!    Let's assume that xCO2 = pCO2. Resulting fugcoeff is identical to 8th digit after the decimal.
+     xCO2approx = dpCO2 * 1.e-6_wp
+     xc2 = (1.0d0 - xCO2approx)**2 
+     fugcoeff = EXP( Ptot*(B + 2.0d0*xc2*Del)/(Rgas_atm*tk) )
+     dfCO2 = dpCO2 * fugcoeff
+     fCO2(i) = REAL(dfCO2)
+  END DO
+
+  RETURN
+END SUBROUTINE p2fCO2
+
+! ----------------------------------------------------------------------
+!  P2FCO2
+! ----------------------------------------------------------------------
+!
+!> \file f2pCO2.f90
+!! \BRIEF 
+!>    Module with f2pCO2 subroutine - compute pCO2 from fCO2, in situ T, atm pressure, hydrostatic pressure
+!>    Compute pCO2 from arrays of fCO2, in situ temp, atm pressure, & hydrostatic pressure
+SUBROUTINE f2pCO2(fCO2, temp, Patm, p, N, pCO2)
+  !    Purpose:
+  !    Compute pCO2 from arrays of fCO2, in situ temp, atm pressure, & hydrostatic pressure
+
+  USE mocsy_singledouble
+  IMPLICIT NONE
+
+  !> number of records
+  INTEGER, intent(in) :: N
+
+! INPUT variables
+  !> oceanic fugacity of CO2 [uatm]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: fCO2
+  !> in situ temperature [C]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: temp
+  !> atmospheric pressure [atm]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: Patm
+  !> hydrostatic pressure [db]
+  REAL(kind=wp), INTENT(in), DIMENSION(N) :: p
+!f2py optional , depend(pCO2) :: n=len(pCO2)
+
+! OUTPUT variables:
+  !> oceanic partial pressure of CO2 [uatm] 
+  REAL(kind=wp), INTENT(out), DIMENSION(N) :: pCO2
+
+! LOCAL variables:
+  REAL(kind=wp) :: dfCO2, dtemp, tk, dPatm, prb
+  REAL(kind=wp) :: Ptot, Rgas_atm, B, Del, xCO2approx, xc2, fugcoeff
+  REAL(kind=wp) :: dpCO2
+
+  INTEGER :: i
+
+! REAL(kind=wp) :: sw_ptmp
+! EXTERNAL sw_ptmp
+
+  DO i = 1,N
+     dfCO2     = DBLE(fCO2(i))
+     dtemp     = DBLE(temp(i))
+     dPatm     = DBLE(Patm(i))
+     tk = 273.15d0 + DBLE(temp(i))     !Absolute temperature (Kelvin)
+     prb = DBLE(p(i)) / 10.0d0         !Pressure effect (prb is in bars)
+     Ptot = dPatm + prb/1.01325d0      !Total pressure (atmospheric + hydrostatic) [atm]
+     Rgas_atm = 82.05736_wp            !R in (cm3 * atm) / (mol * K)  from CODATA (2006)
+!    To compute fugcoeff, we need 3 other terms (B, Del, xc2) as well as 3 others above (tk, Ptot, Rgas_atm)
+     B = -1636.75d0 + 12.0408d0*tk - 0.0327957d0*(tk*tk) + 0.0000316528d0*(tk*tk*tk)
+     Del = 57.7d0 - 0.118d0*tk
+!    "x2" term often neglected (assumed = 1) in applications of Weiss's (1974) equation 9
+!    x2 = 1 - x1 = 1 - xCO2 (it is very close to 1, but not quite)
+!    Let's assume that xCO2 = fCO2. Resulting fugcoeff is identical to 8th digit after the decimal.
+     xCO2approx = dfCO2 * 1.e-6_wp
+     xc2 = (1.0d0 - xCO2approx)**2 
+     fugcoeff = exp( Ptot*(B + 2.0d0*xc2*Del)/(Rgas_atm*tk) )
+     dpCO2 = dfCO2 / fugcoeff
+     pCO2(i) = REAL(dpCO2)
+  END DO
+
+  RETURN
+END SUBROUTINE f2pCO2
+
+END MODULE mocsy_mainmod
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_phsolvers.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_phsolvers.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_phsolvers.F90	(revision 7693)
@@ -0,0 +1,860 @@
+!> \file mocsy_phsolvers.f90
+!! \BRIEF 
+!> Module with routines needed to solve pH-total alkalinity equation (Munhoven, 2013, GMD)
+MODULE mocsy_phsolvers
+!   Module of fastest solvers from Munhoven (2013, Geosci. Model Dev., 6, 1367-1388)
+!   ! Taken from SolveSAPHE (mod_phsolvers.F90) & adapted very slightly for use with mocsy
+!   ! SolveSaphe is distributed under the GNU Lesser General Public License
+!   ! mocsy is distributed under the MIT License
+!
+! Modifications J. C. Orr, LSCE/IPSL, CEA-CNRS-UVSQ, France, 11 Sep 2014:
+! 1) kept only the 3 fastest solvers (atgen, atsec, atfast) and routines which they call
+! 2) reduced vertical white space: deleted many blank lines & comment lines that served as divisions
+! 3) converted name from .F90 to .f90, deleting a few optional preprocesse if statements
+! 4) read in mocsy computed equilibrium constants (as arguments) instead of USE MOD_CHEMCONST
+! 5) converted routine names from upper case to lower case
+! 6) commented out arguments and equations for NH4 and H2S acid systems
+
+USE mocsy_singledouble
+IMPLICIT NONE
+
+! General parameters
+REAL(KIND=wp), PARAMETER :: pp_rdel_ah_target = 1.E-8_wp
+REAL(KIND=wp), PARAMETER :: pp_ln10 = 2.302585092994045684018_wp
+
+! Maximum number of iterations for each method
+INTEGER, PARAMETER :: jp_maxniter_atgen    = 50
+INTEGER, PARAMETER :: jp_maxniter_atsec    = 50
+INTEGER, PARAMETER :: jp_maxniter_atfast   = 50
+
+! Bookkeeping variables for each method
+! - SOLVE_AT_GENERAL
+INTEGER :: niter_atgen    = jp_maxniter_atgen
+
+! - SOLVE_AT_GENERAL_SEC
+INTEGER :: niter_atsec    = jp_maxniter_atsec
+
+! - SOLVE_AT_FAST (variant of SOLVE_AT_GENERAL w/o bracketing
+INTEGER :: niter_atfast   = jp_maxniter_atfast
+
+! Keep the following functions private to avoid conflicts with
+! other modules that provide similar ones.
+!PRIVATE AHINI_FOR_AT
+
+CONTAINS
+!===============================================================================
+SUBROUTINE anw_infsup(p_dictot, p_bortot,                                     &
+                      p_po4tot, p_siltot,                                     &
+                      p_so4tot, p_flutot,                                     &
+                      p_alknw_inf, p_alknw_sup)
+
+! Subroutine returns the lower and upper bounds of "non-water-selfionization"
+! contributions to total alkalinity (the infimum and the supremum), i.e
+! inf(TA - [OH-] + [H+]) and sup(TA - [OH-] + [H+])
+
+USE mocsy_singledouble
+IMPLICIT NONE
+
+! Argument variables
+REAL(KIND=wp), INTENT(IN)  :: p_dictot
+REAL(KIND=wp), INTENT(IN)  :: p_bortot
+REAL(KIND=wp), INTENT(IN)  :: p_po4tot
+REAL(KIND=wp), INTENT(IN)  :: p_siltot
+!REAL(KIND=wp), INTENT(IN)  :: p_nh4tot
+!REAL(KIND=wp), INTENT(IN)  :: p_h2stot
+REAL(KIND=wp), INTENT(IN)  :: p_so4tot
+REAL(KIND=wp), INTENT(IN)  :: p_flutot
+REAL(KIND=wp), INTENT(OUT) :: p_alknw_inf
+REAL(KIND=wp), INTENT(OUT) :: p_alknw_sup
+
+p_alknw_inf =  -p_po4tot - p_so4tot - p_flutot
+p_alknw_sup =   p_dictot + p_dictot + p_bortot &
+              + p_po4tot + p_po4tot + p_siltot !&
+!             + p_nh4tot + p_h2stot
+
+RETURN
+END SUBROUTINE anw_infsup
+
+!===============================================================================
+
+FUNCTION equation_at(p_alktot, p_h,       p_dictot, p_bortot,                 &
+                     p_po4tot, p_siltot,                                      &
+                     p_so4tot, p_flutot,                                      &
+                     K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi,          &
+                     p_deriveqn)
+
+USE mocsy_singledouble
+IMPLICIT NONE
+REAL(KIND=wp) :: equation_at
+
+! Argument variables
+REAL(KIND=wp), INTENT(IN)            :: p_alktot
+REAL(KIND=wp), INTENT(IN)            :: p_h
+REAL(KIND=wp), INTENT(IN)            :: p_dictot
+REAL(KIND=wp), INTENT(IN)            :: p_bortot
+REAL(KIND=wp), INTENT(IN)            :: p_po4tot
+REAL(KIND=wp), INTENT(IN)            :: p_siltot
+!REAL(KIND=wp), INTENT(IN)            :: p_nh4tot
+!REAL(KIND=wp), INTENT(IN)            :: p_h2stot
+REAL(KIND=wp), INTENT(IN)            :: p_so4tot
+REAL(KIND=wp), INTENT(IN)            :: p_flutot
+REAL(KIND=wp), INTENT(IN)            :: K0, K1, K2, Kb, Kw, Ks, Kf
+REAL(KIND=wp), INTENT(IN)            :: K1p, K2p, K3p, Ksi
+REAL(KIND=wp), INTENT(OUT), OPTIONAL :: p_deriveqn
+
+! Local variables 
+!-----------------
+REAL(KIND=wp) :: znumer_dic, zdnumer_dic, zdenom_dic, zalk_dic, zdalk_dic
+REAL(KIND=wp) :: znumer_bor, zdnumer_bor, zdenom_bor, zalk_bor, zdalk_bor
+REAL(KIND=wp) :: znumer_po4, zdnumer_po4, zdenom_po4, zalk_po4, zdalk_po4
+REAL(KIND=wp) :: znumer_sil, zdnumer_sil, zdenom_sil, zalk_sil, zdalk_sil
+REAL(KIND=wp) :: znumer_nh4, zdnumer_nh4, zdenom_nh4, zalk_nh4, zdalk_nh4
+REAL(KIND=wp) :: znumer_h2s, zdnumer_h2s, zdenom_h2s, zalk_h2s, zdalk_h2s
+REAL(KIND=wp) :: znumer_so4, zdnumer_so4, zdenom_so4, zalk_so4, zdalk_so4
+REAL(KIND=wp) :: znumer_flu, zdnumer_flu, zdenom_flu, zalk_flu, zdalk_flu
+REAL(KIND=wp) ::                                      zalk_wat, zdalk_wat
+REAL(KIND=wp) :: aphscale
+
+! TOTAL H+ scale: conversion factor for Htot = aphscale * Hfree
+aphscale = 1._wp + p_so4tot/Ks
+
+! H2CO3 - HCO3 - CO3 : n=2, m=0
+znumer_dic = 2._wp*K1*K2 + p_h*       K1
+zdenom_dic =       K1*K2 + p_h*(      K1 + p_h)
+zalk_dic   = p_dictot * (znumer_dic/zdenom_dic)
+
+! B(OH)3 - B(OH)4 : n=1, m=0
+znumer_bor =       Kb
+zdenom_bor =       Kb + p_h
+zalk_bor   = p_bortot * (znumer_bor/zdenom_bor)
+
+! H3PO4 - H2PO4 - HPO4 - PO4 : n=3, m=1
+znumer_po4 = 3._wp*K1p*K2p*K3p + p_h*(2._wp*K1p*K2p + p_h* K1p)
+zdenom_po4 =       K1p*K2p*K3p + p_h*(      K1p*K2p + p_h*(K1p + p_h))
+zalk_po4   = p_po4tot * (znumer_po4/zdenom_po4 - 1._wp) ! Zero level of H3PO4 = 1
+
+! H4SiO4 - H3SiO4 : n=1, m=0
+znumer_sil =       Ksi
+zdenom_sil =       Ksi + p_h
+zalk_sil   = p_siltot * (znumer_sil/zdenom_sil)
+
+! NH4 - NH3 : n=1, m=0
+!znumer_nh4 =       api1_nh4
+!zdenom_nh4 =       api1_nh4 + p_h
+!zalk_nh4   = p_nh4tot * (znumer_nh4/zdenom_nh4)
+! Note: api1_nh4 = Knh4
+
+! H2S - HS : n=1, m=0
+!znumer_h2s =       api1_h2s
+!zdenom_h2s =       api1_h2s + p_h
+!zalk_h2s   = p_h2stot * (znumer_h2s/zdenom_h2s)
+! Note: api1_h2s = Kh2s
+
+! HSO4 - SO4 : n=1, m=1
+znumer_so4 =       Ks
+zdenom_so4 =       Ks + p_h
+zalk_so4   = p_so4tot * (znumer_so4/zdenom_so4 - 1._wp)
+
+! HF - F : n=1, m=1
+znumer_flu =       Kf
+zdenom_flu =       Kf + p_h
+zalk_flu   = p_flutot * (znumer_flu/zdenom_flu - 1._wp)
+
+! H2O - OH
+zalk_wat   = Kw/p_h - p_h/aphscale
+
+equation_at =    zalk_dic + zalk_bor + zalk_po4 + zalk_sil &
+               + zalk_so4 + zalk_flu                       &
+               + zalk_wat - p_alktot
+
+IF(PRESENT(p_deriveqn)) THEN
+   ! H2CO3 - HCO3 - CO3 : n=2
+   zdnumer_dic = K1*K1*K2 + p_h*(4._wp*K1*K2               &
+                          + p_h*       K1    )
+   zdalk_dic   = -p_dictot*(zdnumer_dic/zdenom_dic**2)
+
+   ! B(OH)3 - B(OH)4 : n=1
+   zdnumer_bor = Kb
+   zdalk_bor   = -p_bortot*(zdnumer_bor/zdenom_bor**2)
+
+   ! H3PO4 - H2PO4 - HPO4 - PO4 : n=3
+   zdnumer_po4 = K1p*K2p*K1p*K2p*K3p + p_h*(4._wp*K1p*K1p*K2p*K3p                &
+                                     + p_h*(9._wp*K1p*K2p*K3p + K1p*K1p*K2p      &
+                                     + p_h*(4._wp*K1p*K2p                        &
+                                     + p_h*       K1p)))
+   zdalk_po4   = -p_po4tot * (zdnumer_po4/zdenom_po4**2)
+
+   ! H4SiO4 - H3SiO4 : n=1
+   zdnumer_sil = Ksi
+   zdalk_sil   = -p_siltot * (zdnumer_sil/zdenom_sil**2)
+
+!  ! NH4 - NH3 : n=1
+!  zdnumer_nh4 = Knh4
+!  zdalk_nh4   = -p_nh4tot * (zdnumer_nh4/zdenom_nh4**2)
+
+!  ! H2S - HS : n=1
+!  zdnumer_h2s = api1_h2s
+!  zdalk_h2s   = -p_h2stot * (zdnumer_h2s/zdenom_h2s**2)
+
+   ! HSO4 - SO4 : n=1
+   zdnumer_so4 = Ks
+   zdalk_so4   = -p_so4tot * (zdnumer_so4/zdenom_so4**2)
+
+   ! HF - F : n=1
+   zdnumer_flu = Kf
+   zdalk_flu   = -p_flutot * (zdnumer_flu/zdenom_flu**2)
+
+!  p_deriveqn =   zdalk_dic + zdalk_bor + zdalk_po4 + zdalk_sil &
+!               + zdalk_nh4 + zdalk_h2s + zdalk_so4 + zdalk_flu &
+!               - Kw/p_h**2 - 1._wp/aphscale
+   p_deriveqn =   zdalk_dic + zdalk_bor + zdalk_po4 + zdalk_sil &
+                                        + zdalk_so4 + zdalk_flu &
+                - Kw/p_h**2 - 1._wp/aphscale
+ENDIF
+RETURN
+END FUNCTION equation_at
+
+!===============================================================================
+
+SUBROUTINE ahini_for_at(p_alkcb, p_dictot, p_bortot, K1, K2, Kb, p_hini)
+
+! Subroutine returns the root for the 2nd order approximation of the
+! DIC -- B_T -- A_CB equation for [H+] (reformulated as a cubic polynomial)
+! around the local minimum, if it exists.
+
+! Returns * 1E-03_wp if p_alkcb <= 0
+!         * 1E-10_wp if p_alkcb >= 2*p_dictot + p_bortot
+!         * 1E-07_wp if 0 < p_alkcb < 2*p_dictot + p_bortot
+!                    and the 2nd order approximation does not have a solution
+
+!USE MOD_CHEMCONST, ONLY : api1_dic, api2_dic, api1_bor
+
+USE mocsy_singledouble
+IMPLICIT NONE
+
+! Argument variables 
+!--------------------
+REAL(KIND=wp), INTENT(IN)   ::  p_alkcb, p_dictot, p_bortot
+REAL(KIND=wp), INTENT(IN)   ::  K1, K2, Kb
+REAL(KIND=wp), INTENT(OUT)  ::  p_hini
+
+! Local variables 
+!-----------------
+REAL(KIND=wp)  ::  zca, zba
+REAL(KIND=wp)  ::  zd, zsqrtd, zhmin
+REAL(KIND=wp)  ::  za2, za1, za0
+
+IF (p_alkcb <= 0._wp) THEN
+  p_hini = 1.e-3_wp
+ELSEIF (p_alkcb >= (2._wp*p_dictot + p_bortot)) THEN
+  p_hini = 1.e-10_wp
+ELSE
+  zca = p_dictot/p_alkcb
+  zba = p_bortot/p_alkcb
+
+  ! Coefficients of the cubic polynomial
+  za2 = Kb*(1._wp - zba) + K1*(1._wp-zca)
+  za1 = K1*Kb*(1._wp - zba - zca) + K1*K2*(1._wp - (zca+zca))
+  za0 = K1*K2*Kb*(1._wp - zba - (zca+zca))
+                                        ! Taylor expansion around the minimum
+  zd = za2*za2 - 3._wp*za1              ! Discriminant of the quadratic equation
+                                        ! for the minimum close to the root
+
+  IF(zd > 0._wp) THEN                   ! If the discriminant is positive
+    zsqrtd = SQRT(zd)
+    IF(za2 < 0) THEN
+      zhmin = (-za2 + zsqrtd)/3._wp
+    ELSE
+      zhmin = -za1/(za2 + zsqrtd)
+    ENDIF
+    p_hini = zhmin + SQRT(-(za0 + zhmin*(za1 + zhmin*(za2 + zhmin)))/zsqrtd)
+  ELSE
+    p_hini = 1.e-7_wp
+  ENDIF
+
+ENDIF
+RETURN
+END SUBROUTINE ahini_for_at
+
+!===============================================================================
+
+FUNCTION solve_at_general(p_alktot, p_dictot, p_bortot,                       &
+                          p_po4tot, p_siltot,                                 &
+                          p_so4tot, p_flutot,                                 &
+                          K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi,     &
+                          p_hini,   p_val)
+
+! Universal pH solver that converges from any given initial value,
+! determines upper an lower bounds for the solution if required
+
+USE mocsy_singledouble
+IMPLICIT NONE
+REAL(KIND=wp) :: SOLVE_AT_GENERAL
+
+! Argument variables 
+!--------------------
+REAL(KIND=wp), INTENT(IN)            :: p_alktot
+REAL(KIND=wp), INTENT(IN)            :: p_dictot
+REAL(KIND=wp), INTENT(IN)            :: p_bortot
+REAL(KIND=wp), INTENT(IN)            :: p_po4tot
+REAL(KIND=wp), INTENT(IN)            :: p_siltot
+!REAL(KIND=wp), INTENT(IN)            :: p_nh4tot
+!REAL(KIND=wp), INTENT(IN)            :: p_h2stot
+REAL(KIND=wp), INTENT(IN)            :: p_so4tot
+REAL(KIND=wp), INTENT(IN)            :: p_flutot
+REAL(KIND=wp), INTENT(IN)            :: K0, K1, K2, Kb, Kw, Ks, Kf
+REAL(KIND=wp), INTENT(IN)            :: K1p, K2p, K3p, Ksi
+REAL(KIND=wp), INTENT(IN), OPTIONAL  :: p_hini
+REAL(KIND=wp), INTENT(OUT), OPTIONAL :: p_val
+
+! Local variables 
+!-----------------
+REAL(KIND=wp)  ::  zh_ini, zh, zh_prev, zh_lnfactor
+REAL(KIND=wp)  ::  zalknw_inf, zalknw_sup
+REAL(KIND=wp)  ::  zh_min, zh_max
+REAL(KIND=wp)  ::  zdelta, zh_delta
+REAL(KIND=wp)  ::  zeqn, zdeqndh, zeqn_absmin
+REAL(KIND=wp)  ::  aphscale
+LOGICAL        :: l_exitnow
+REAL(KIND=wp), PARAMETER :: pz_exp_threshold = 1.0_wp
+
+! TOTAL H+ scale: conversion factor for Htot = aphscale * Hfree
+aphscale = 1._wp + p_so4tot/Ks
+
+IF(PRESENT(p_hini)) THEN
+   zh_ini = p_hini
+ELSE
+   CALL ahini_for_at(p_alktot, p_dictot, p_bortot, K1, K2, Kb, zh_ini)
+ENDIF
+
+ CALL anw_infsup(p_dictot, p_bortot,                                           &
+                 p_po4tot, p_siltot,                                           &
+                 p_so4tot, p_flutot,                                           &
+                 zalknw_inf, zalknw_sup)
+
+zdelta = (p_alktot-zalknw_inf)**2 + 4._wp*Kw/aphscale
+
+IF(p_alktot >= zalknw_inf) THEN
+   zh_min = 2._wp*Kw /( p_alktot-zalknw_inf + SQRT(zdelta) )
+ELSE
+   zh_min = aphscale*(-(p_alktot-zalknw_inf) + SQRT(zdelta) ) / 2._wp
+ENDIF
+
+zdelta = (p_alktot-zalknw_sup)**2 + 4._wp*Kw/aphscale
+
+IF(p_alktot <= zalknw_sup) THEN
+   zh_max = aphscale*(-(p_alktot-zalknw_sup) + SQRT(zdelta) ) / 2._wp
+ELSE
+   zh_max = 2._wp*Kw /( p_alktot-zalknw_sup + SQRT(zdelta) )
+ENDIF
+
+zh = MAX(MIN(zh_max, zh_ini), zh_min)
+niter_atgen        = 0                 ! Reset counters of iterations
+zeqn_absmin        = HUGE(1._wp)
+
+DO
+   IF(niter_atgen >= jp_maxniter_atgen) THEN
+      zh = -1._wp
+      EXIT
+   ENDIF
+
+   zh_prev = zh
+   zeqn = equation_at(p_alktot, zh,       p_dictot, p_bortot,                  &
+                      p_po4tot, p_siltot,                                      &
+                      p_so4tot, p_flutot,                                      &
+                      K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi,          &
+                      P_DERIVEQN = zdeqndh)
+
+   ! Adapt bracketing interval
+   IF(zeqn > 0._wp) THEN
+      zh_min = zh_prev
+   ELSEIF(zeqn < 0._wp) THEN
+      zh_max = zh_prev
+   ELSE
+      ! zh is the root; unlikely but, one never knows
+      EXIT
+   ENDIF
+
+   ! Now determine the next iterate zh
+   niter_atgen = niter_atgen + 1
+
+   IF(ABS(zeqn) >= 0.5_wp*zeqn_absmin) THEN
+      ! if the function evaluation at the current point is
+      ! not decreasing faster than with a bisection step (at least linearly)
+      ! in absolute value take one bisection step on [ph_min, ph_max]
+      ! ph_new = (ph_min + ph_max)/2d0
+      !
+      ! In terms of [H]_new:
+      ! [H]_new = 10**(-ph_new)
+      !         = 10**(-(ph_min + ph_max)/2d0)
+      !         = SQRT(10**(-(ph_min + phmax)))
+      !         = SQRT(zh_max * zh_min)
+      zh = SQRT(zh_max * zh_min)
+      zh_lnfactor = (zh - zh_prev)/zh_prev ! Required to test convergence below
+   ELSE
+      ! dzeqn/dpH = dzeqn/d[H] * d[H]/dpH
+      !           = -zdeqndh * LOG(10) * [H]
+      ! \Delta pH = -zeqn/(zdeqndh*d[H]/dpH) = zeqn/(zdeqndh*[H]*LOG(10))
+      !
+      ! pH_new = pH_old + \deltapH
+      !
+      ! [H]_new = 10**(-pH_new)
+      !         = 10**(-pH_old - \Delta pH)
+      !         = [H]_old * 10**(-zeqn/(zdeqndh*[H]_old*LOG(10)))
+      !         = [H]_old * EXP(-LOG(10)*zeqn/(zdeqndh*[H]_old*LOG(10)))
+      !         = [H]_old * EXP(-zeqn/(zdeqndh*[H]_old))
+
+      zh_lnfactor = -zeqn/(zdeqndh*zh_prev)
+
+      IF(ABS(zh_lnfactor) > pz_exp_threshold) THEN
+         zh          = zh_prev*EXP(zh_lnfactor)
+      ELSE
+         zh_delta    = zh_lnfactor*zh_prev
+         zh          = zh_prev + zh_delta
+      ENDIF
+
+      IF( zh < zh_min ) THEN
+         ! if [H]_new < [H]_min
+         ! i.e., if ph_new > ph_max then
+         ! take one bisection step on [ph_prev, ph_max]
+         ! ph_new = (ph_prev + ph_max)/2d0
+         ! In terms of [H]_new:
+         ! [H]_new = 10**(-ph_new)
+         !         = 10**(-(ph_prev + ph_max)/2d0)
+         !         = SQRT(10**(-(ph_prev + phmax)))
+         !         = SQRT([H]_old*10**(-ph_max))
+         !         = SQRT([H]_old * zh_min)
+         zh                = SQRT(zh_prev * zh_min)
+         zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
+      ENDIF
+
+      IF( zh > zh_max ) THEN
+         ! if [H]_new > [H]_max
+         ! i.e., if ph_new < ph_min, then
+         ! take one bisection step on [ph_min, ph_prev]
+         ! ph_new = (ph_prev + ph_min)/2d0
+         ! In terms of [H]_new:
+         ! [H]_new = 10**(-ph_new)
+         !         = 10**(-(ph_prev + ph_min)/2d0)
+         !         = SQRT(10**(-(ph_prev + ph_min)))
+         !         = SQRT([H]_old*10**(-ph_min))
+         !         = SQRT([H]_old * zhmax)
+         zh                = SQRT(zh_prev * zh_max)
+         zh_lnfactor       = (zh - zh_prev)/zh_prev ! Required to test convergence below
+      ENDIF
+   ENDIF
+
+   zeqn_absmin = MIN( ABS(zeqn), zeqn_absmin)
+
+   ! Stop iterations once |\delta{[H]}/[H]| < rdel
+   ! <=> |(zh - zh_prev)/zh_prev| = |EXP(-zeqn/(zdeqndh*zh_prev)) -1| < rdel
+   ! |EXP(-zeqn/(zdeqndh*zh_prev)) -1| ~ |zeqn/(zdeqndh*zh_prev)|
+
+   ! Alternatively:
+   ! |\Delta pH| = |zeqn/(zdeqndh*zh_prev*LOG(10))|
+   !             ~ 1/LOG(10) * |\Delta [H]|/[H]
+   !             < 1/LOG(10) * rdel
+
+   ! Hence |zeqn/(zdeqndh*zh)| < rdel
+
+   ! rdel <-- pp_rdel_ah_target
+
+   l_exitnow = (ABS(zh_lnfactor) < pp_rdel_ah_target)
+
+   IF(l_exitnow) EXIT
+ENDDO
+
+solve_at_general = zh
+
+IF(PRESENT(p_val)) THEN
+   IF(zh > 0._wp) THEN
+      p_val = equation_at(p_alktot, zh,       p_dictot, p_bortot,              &
+                          p_po4tot, p_siltot,                                  &
+                          p_so4tot, p_flutot,                                  &
+                          K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi)    
+   ELSE
+      p_val = HUGE(1._wp)
+   ENDIF
+ENDIF
+RETURN
+END FUNCTION solve_at_general
+
+!===============================================================================
+
+FUNCTION solve_at_general_sec(p_alktot, p_dictot, p_bortot,                   &
+                              p_po4tot, p_siltot,                             &
+                              p_so4tot, p_flutot,                             &
+                              K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi, &
+                              p_hini,   p_val) 
+
+! Universal pH solver that converges from any given initial value,
+! determines upper an lower bounds for the solution if required
+
+!USE MOD_CHEMCONST, ONLY: api1_wat, aphscale
+USE mocsy_singledouble
+IMPLICIT NONE
+REAL(KIND=wp) :: SOLVE_AT_GENERAL_SEC
+
+! Argument variables 
+REAL(KIND=wp), INTENT(IN)            :: p_alktot
+REAL(KIND=wp), INTENT(IN)            :: p_dictot
+REAL(KIND=wp), INTENT(IN)            :: p_bortot
+REAL(KIND=wp), INTENT(IN)            :: p_po4tot
+REAL(KIND=wp), INTENT(IN)            :: p_siltot
+!REAL(KIND=wp), INTENT(IN)            :: p_nh4tot
+!REAL(KIND=wp), INTENT(IN)            :: p_h2stot
+REAL(KIND=wp), INTENT(IN)            :: p_so4tot
+REAL(KIND=wp), INTENT(IN)            :: p_flutot
+REAL(KIND=wp), INTENT(IN)            :: K0, K1, K2, Kb, Kw, Ks, Kf
+REAL(KIND=wp), INTENT(IN)            :: K1p, K2p, K3p, Ksi
+REAL(KIND=wp), INTENT(IN), OPTIONAL  :: p_hini
+REAL(KIND=wp), INTENT(OUT), OPTIONAL :: p_val
+
+! Local variables
+REAL(KIND=wp)  ::  zh_ini, zh, zh_1, zh_2, zh_delta
+REAL(KIND=wp)  ::  zalknw_inf, zalknw_sup
+REAL(KIND=wp)  ::  zh_min, zh_max
+REAL(KIND=wp)  ::  zeqn, zeqn_1, zeqn_2, zeqn_absmin
+REAL(KIND=wp)  ::  zdelta
+REAL(KIND=wp)  ::  aphscale
+LOGICAL        ::  l_exitnow
+
+! TOTAL H+ scale: conversion factor for Htot = aphscale * Hfree
+aphscale = 1._wp + p_so4tot/Ks
+
+IF(PRESENT(p_hini)) THEN
+   zh_ini = p_hini
+ELSE
+   CALL ahini_for_at(p_alktot, p_dictot, p_bortot, K1, K2, Kb, zh_ini)
+ENDIF
+
+ CALL anw_infsup(p_dictot, p_bortot,                                      &
+                 p_po4tot, p_siltot,                                      &
+                 p_so4tot, p_flutot,                                      &
+                 zalknw_inf, zalknw_sup)
+
+zdelta = (p_alktot-zalknw_inf)**2 + 4._wp*Kw/aphscale
+
+IF(p_alktot >= zalknw_inf) THEN
+   zh_min = 2._wp*Kw /( p_alktot-zalknw_inf + SQRT(zdelta) )
+ELSE
+   zh_min = aphscale*(-(p_alktot-zalknw_inf) + SQRT(zdelta) ) / 2._wp
+ENDIF
+
+zdelta = (p_alktot-zalknw_sup)**2 + 4._wp*Kw/aphscale
+
+IF(p_alktot <= zalknw_sup) THEN
+   zh_max = aphscale*(-(p_alktot-zalknw_sup) + SQRT(zdelta) ) / 2._wp
+ELSE
+   zh_max = 2._wp*Kw /( p_alktot-zalknw_sup + SQRT(zdelta) )
+ENDIF
+
+zh = MAX(MIN(zh_max, zh_ini), zh_min)
+niter_atsec        = 0                 ! Reset counters of iterations
+
+! Prepare the secant iterations: two initial (zh, zeqn) pairs are required
+! We have the starting value, that needs to be completed by the evaluation
+! of the equation value it produces.
+
+! Complete the initial value with its equation evaluation
+! (will take the role of the $n-2$ iterate at the first secant evaluation)
+
+niter_atsec = 0                        ! zh_2 is the initial value;
+
+zh_2   = zh
+zeqn_2 = equation_at(p_alktot, zh_2,     p_dictot, p_bortot,                 &
+                     p_po4tot, p_siltot,                                     &
+                     p_so4tot, p_flutot,                                     &
+                     K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi)
+
+zeqn_absmin        = ABS(zeqn_2)
+
+! Adapt bracketing interval and heuristically set zh_1
+IF(zeqn_2 < 0._wp) THEN
+                                       ! If zeqn_2 < 0, then we adjust zh_max:
+                                       ! we can be sure that zh_min < zh_2 < zh_max.
+   zh_max = zh_2
+                                       ! for zh_1, try 25% (0.1 pH units) below the current zh_max,
+                                       ! but stay above SQRT(zh_min*zh_max), which would be equivalent
+                                       ! to a bisection step on [pH@zh_min, pH@zh_max]
+   zh_1   = MAX(zh_max/1.25_wp, SQRT(zh_min*zh_max))
+ELSEIF(zeqn_2 > 0._wp) THEN
+                                       ! If zeqn_2 < 0, then we adjust zh_min:
+                                       ! we can be sure that zh_min < zh_2 < zh_max.
+   zh_min = zh_2
+                                       ! for zh_1, try 25% (0.1 pH units) above the current zh_min,
+                                       ! but stay below SQRT(zh_min*zh_max) which would be equivalent
+                                       ! to a bisection step on [pH@zh_min, pH@zh_max]
+   zh_1   = MIN(zh_min*1.25_wp, SQRT(zh_min*zh_max))
+ELSE ! we have got the root; unlikely, but one never knows
+   solve_at_general_sec = zh_2
+   IF(PRESENT(p_val)) p_val = zeqn_2
+   RETURN
+ENDIF
+
+! We now have the first pair completed (zh_2, zeqn_2).
+! Define the second one (zh_1, zeqn_1), which is also the first iterate.
+! zh_1 has already been set above
+niter_atsec = 1                        ! Update counter of iterations
+
+zeqn_1 = equation_at(p_alktot, zh_1,       p_dictot, p_bortot,                 &
+                     p_po4tot, p_siltot,                                       &
+                     p_so4tot, p_flutot,                                       &
+                     K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi)
+
+! Adapt bracketing interval: we know that zh_1 <= zh <= zh_max (if zeqn_1 > 0)
+! or zh_min <= zh <= zh_1 (if zeqn_1 < 0), so this can always be done
+IF(zeqn_1 > 0._wp) THEN
+   zh_min = zh_1
+ELSEIF(zeqn_1 < 0._wp) THEN
+   zh_max = zh_1
+ELSE ! zh_1 is the root
+   solve_at_general_sec = zh_1
+   IF(PRESENT(p_val)) p_val = zeqn_1
+ENDIF
+
+IF(ABS(zeqn_1) > zeqn_absmin) THEN     ! Swap zh_2 and zh_1 if ABS(zeqn_2) < ABS(zeqn_1)
+                                       ! so that zh_2 and zh_1 lead to decreasing equation
+                                       ! values (in absolute value)
+   zh     = zh_1
+   zeqn   = zeqn_1
+   zh_1   = zh_2
+   zeqn_1 = zeqn_2
+   zh_2   = zh
+   zeqn_2 = zeqn
+ELSE
+   zeqn_absmin = ABS(zeqn_1)
+ENDIF
+
+! Pre-calculate the first secant iterate (this is the second iterate)
+niter_atsec = 2
+
+zh_delta = -zeqn_1/((zeqn_2-zeqn_1)/(zh_2 - zh_1))
+zh = zh_1 + zh_delta
+
+! Make sure that zh_min < zh < zh_max (if not,
+! bisect around zh_1 which is the best estimate)
+IF (zh > zh_max) THEN                  ! this can only happen if zh_2 < zh_1
+                                       ! and zeqn_2 > zeqn_1 > 0
+   zh = SQRT(zh_1*zh_max)
+ENDIF
+
+IF (zh < zh_min) THEN                  ! this can only happen if zh_2 > zh_1
+                                       ! and zeqn_2 < zeqn_1 < 0
+   zh = SQRT(zh_1*zh_min)
+ENDIF
+
+DO
+   IF(niter_atsec >= jp_maxniter_atsec) THEN
+      zh = -1._wp
+      EXIT
+   ENDIF
+
+   zeqn = equation_at(p_alktot, zh,       p_dictot, p_bortot,                  &
+                      p_po4tot, p_siltot,                                      &
+                      p_so4tot, p_flutot,                                      &
+                      K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi)
+
+   ! Adapt bracketing interval: since initially, zh_min <= zh <= zh_max
+   ! we are sure that zh will improve either bracket, depending on the sign
+   ! of zeqn
+   IF(zeqn > 0._wp) THEN
+     zh_min = zh
+   ELSEIF(zeqn < 0._wp) THEN
+     zh_max = zh
+   ELSE
+     ! zh is the root
+     EXIT
+   ENDIF
+
+   ! start calculation of next iterate
+   niter_atsec = niter_atsec + 1
+
+   zh_2   = zh_1
+   zeqn_2 = zeqn_1
+   zh_1   = zh
+   zeqn_1 = zeqn
+
+   IF(ABS(zeqn) >= 0.5_wp*zeqn_absmin) THEN
+      ! if the function evaluation at the current point
+      ! is not decreasing faster in absolute value than
+      ! we may expect for a bisection step, then take
+      ! one bisection step on [ph_min, ph_max]
+      ! ph_new = (ph_min + ph_max)/2d0
+      ! In terms of [H]_new:
+      ! [H]_new = 10**(-ph_new)
+      !         = 10**(-(ph_min + ph_max)/2d0)
+      !         = SQRT(10**(-(ph_min + phmax)))
+      !         = SQRT(zh_max * zh_min)
+      zh                = SQRT(zh_max * zh_min)
+      zh_delta           = zh - zh_1
+   ELSE
+      ! \Delta H = -zeqn_1*(h_2 - h_1)/(zeqn_2 - zeqn_1) 
+      ! H_new = H_1 + \Delta H
+      zh_delta = -zeqn_1/((zeqn_2-zeqn_1)/(zh_2 - zh_1))
+      zh       = zh_1 + zh_delta
+
+      IF( zh < zh_min ) THEN
+         ! if [H]_new < [H]_min
+         ! i.e., if ph_new > ph_max then
+         ! take one bisection step on [ph_prev, ph_max]
+         ! ph_new = (ph_prev + ph_max)/2d0
+         ! In terms of [H]_new:
+         ! [H]_new = 10**(-ph_new)
+         !         = 10**(-(ph_prev + ph_max)/2d0)
+         !         = SQRT(10**(-(ph_prev + phmax)))
+         !         = SQRT([H]_old*10**(-ph_max))
+         !         = SQRT([H]_old * zh_min)
+         zh                = SQRT(zh_1 * zh_min)
+         zh_delta          = zh - zh_1
+      ENDIF
+
+      IF( zh > zh_max ) THEN
+         ! if [H]_new > [H]_max
+         ! i.e., if ph_new < ph_min, then
+         ! take one bisection step on [ph_min, ph_prev]
+         ! ph_new = (ph_prev + ph_min)/2d0
+         ! In terms of [H]_new:
+         ! [H]_new = 10**(-ph_new)
+         !         = 10**(-(ph_prev + ph_min)/2d0)
+         !         = SQRT(10**(-(ph_prev + ph_min)))
+         !         = SQRT([H]_old*10**(-ph_min))
+         !         = SQRT([H]_old * zhmax)
+         zh                 = SQRT(zh_1 * zh_max)
+         zh_delta           = zh - zh_1
+      ENDIF
+   ENDIF
+
+   zeqn_absmin = MIN(ABS(zeqn), zeqn_absmin)
+
+   ! Stop iterations once |([H]-[H_1])/[H_1]| < rdel
+   l_exitnow = (ABS(zh_delta) < pp_rdel_ah_target*zh_1)
+
+   IF(l_exitnow) EXIT
+ENDDO
+
+SOLVE_AT_GENERAL_SEC = zh
+
+IF(PRESENT(p_val)) THEN
+   IF(zh > 0._wp) THEN
+      p_val = equation_at(p_alktot, zh,       p_dictot, p_bortot,              &
+                          p_po4tot, p_siltot,                                  &
+                          p_so4tot, p_flutot,                                  &
+                          K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi)
+   ELSE
+     p_val = HUGE(1._wp)
+   ENDIF
+ENDIF
+
+RETURN
+END FUNCTION SOLVE_AT_GENERAL_SEC
+
+!===============================================================================
+
+FUNCTION SOLVE_AT_FAST(p_alktot, p_dictot, p_bortot,                          &
+                       p_po4tot, p_siltot,                                    &
+                       p_so4tot, p_flutot,                                    & 
+                       K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi,        &
+                       p_hini,   p_val)
+
+! Fast version of SOLVE_AT_GENERAL, without any bounds checking.
+
+USE mocsy_singledouble
+IMPLICIT NONE
+REAL(KIND=wp) :: SOLVE_AT_FAST
+
+! Argument variables 
+REAL(KIND=wp), INTENT(IN)            :: p_alktot
+REAL(KIND=wp), INTENT(IN)            :: p_dictot
+REAL(KIND=wp), INTENT(IN)            :: p_bortot
+REAL(KIND=wp), INTENT(IN)            :: p_po4tot
+REAL(KIND=wp), INTENT(IN)            :: p_siltot
+!REAL(KIND=wp), INTENT(IN)            :: p_nh4tot
+!REAL(KIND=wp), INTENT(IN)            :: p_h2stot
+REAL(KIND=wp), INTENT(IN)            :: p_so4tot
+REAL(KIND=wp), INTENT(IN)            :: p_flutot
+REAL(KIND=wp), INTENT(IN)            :: K0, K1, K2, Kb, Kw, Ks, Kf
+REAL(KIND=wp), INTENT(IN)            :: K1p, K2p, K3p, Ksi
+REAL(KIND=wp), INTENT(IN), OPTIONAL  :: p_hini
+REAL(KIND=wp), INTENT(OUT), OPTIONAL :: p_val
+
+! Local variables
+REAL(KIND=wp)  ::  zh_ini, zh, zh_prev, zh_lnfactor
+REAL(KIND=wp)  ::  zhdelta
+REAL(KIND=wp)  ::  zeqn, zdeqndh
+!REAL(KIND=wp)  ::  aphscale
+LOGICAL        :: l_exitnow
+REAL(KIND=wp), PARAMETER :: pz_exp_threshold = 1.0_wp
+
+! TOTAL H+ scale: conversion factor for Htot = aphscale * Hfree
+!aphscale = 1._wp + p_so4tot/Ks
+
+IF(PRESENT(p_hini)) THEN
+   zh_ini = p_hini
+ELSE
+   CALL AHINI_FOR_AT(p_alktot, p_dictot, p_bortot, K1, K2, Kb, zh_ini)
+ENDIF
+zh = zh_ini
+
+niter_atfast    = 0                 ! Reset counters of iterations
+DO
+   niter_atfast = niter_atfast + 1
+   IF(niter_atfast > jp_maxniter_atfast) THEN
+      zh = -1._wp
+      EXIT
+   ENDIF
+
+   zh_prev = zh
+
+   zeqn = equation_at(p_alktot, zh,       p_dictot, p_bortot,                  &
+                      p_po4tot, p_siltot,                                      &
+                      p_so4tot, p_flutot,                                      & 
+                      K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi,          &
+                      P_DERIVEQN = zdeqndh)
+
+   IF(zeqn == 0._wp) EXIT               ! zh is the root
+
+   zh_lnfactor = -zeqn/(zdeqndh*zh_prev)
+   IF(ABS(zh_lnfactor) > pz_exp_threshold) THEN
+      zh          = zh_prev*EXP(zh_lnfactor)
+   ELSE
+      zhdelta     = zh_lnfactor*zh_prev
+      zh          = zh_prev + zhdelta
+   ENDIF
+
+   ! Stop iterations once |\delta{[H]}/[H]| < rdel
+   ! <=> |(zh - zh_prev)/zh_prev| = |EXP(-zeqn/(zdeqndh*zh_prev)) -1| < rdel
+   ! |EXP(-zeqn/(zdeqndh*zh_prev)) -1| ~ |zeqn/(zdeqndh*zh_prev)|
+
+   ! Alternatively:
+   ! |\Delta pH| = |zeqn/(zdeqndh*zh_prev*LOG(10))|
+   !             ~ 1/LOG(10) * |\Delta [H]|/[H]
+   !             < 1/LOG(10) * rdel
+
+   ! Hence |zeqn/(zdeqndh*zh)| < rdel
+
+   ! rdel <- pp_rdel_ah_target
+
+   l_exitnow = (ABS(zh_lnfactor) < pp_rdel_ah_target)
+
+   IF(l_exitnow) EXIT
+ENDDO
+
+SOLVE_AT_FAST = zh
+
+IF(PRESENT(p_val)) THEN
+   IF(zh > 0._wp) THEN
+      p_val = equation_at(p_alktot, zh,       p_dictot, p_bortot,              &
+                          p_po4tot, p_siltot,                                  &
+                          p_so4tot, p_flutot,                                  &
+                          K0, K1, K2, Kb, Kw, Ks, Kf, K1p, K2p, K3p, Ksi)
+   ELSE
+      p_val = HUGE(1._wp)
+   ENDIF
+ENDIF
+
+RETURN
+END FUNCTION solve_at_fast
+!===============================================================================
+
+END MODULE mocsy_phsolvers
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_singledouble.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_singledouble.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_singledouble.F90	(revision 7693)
@@ -0,0 +1,11 @@
+!> \file mocsy_singledouble.f90
+!! \BRIEF 
+!> Module that defines single and double precision - used by all other modules
+MODULE mocsy_singledouble
+! INTEGER, PARAMETER :: r4 = SELECTED_REAL_KIND(6)
+! INTEGER, PARAMETER :: r8 = SELECTED_REAL_KIND(12)
+  INTEGER, PARAMETER :: r4 = KIND(1.0)
+  INTEGER, PARAMETER :: r8 = KIND(1.0d0)
+! INTEGER, PARAMETER :: wp = KIND(1.0d0)
+  INTEGER, PARAMETER :: wp = SELECTED_REAL_KIND(12,307)
+END MODULE mocsy_singledouble
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_wrapper.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_wrapper.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_wrapper.F90	(revision 7693)
@@ -0,0 +1,338 @@
+MODULE mocsy_wrapper
+   !!======================================================================
+   !!                         ***  MODULE mocsy_wrapper  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2015-06  (A. Yool)             added for UKESM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam && defined key_mocsy
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA carbonate chemistry
+   !!----------------------------------------------------------------------
+   !!   trc_co2_medusa        :  
+   !!----------------------------------------------------------------------
+
+   USE mocsy_mainmod
+   USE mocsy_gasflux
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC mocsy_interface  ! called in trc_bio_medusa
+   PUBLIC mocsy_carbchem   ! called in trc_bio_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+! The following is a map of the subroutines contained within this module
+! - mocsy_interface
+!    - CALLS mocsy_carbchem
+!
+! - mocsy_carbchem
+!    - CALLS vars
+!      - CALLS p80
+!      - CALLS constants
+!      - CALLS rho
+!      - CALLS varsolver
+!        - CALLS [phsolvers routines]
+!      - CALLS varsolver (again)
+!    - CALLS x2pCO2atm
+!    - CALLS p2fCO2
+!    - CALLS schmidt_co2
+!    - CALLS surface_K0
+
+CONTAINS
+
+!=======================================================================
+!
+      SUBROUTINE mocsy_interface( temp, sal, alk, dic, sil, phos, &
+           Patm, depth, lat, kw660, xco2, N,                      &
+           ph, pco2, fco2, co2, hco3, co3, OmegaA,                &
+           OmegaC, BetaD, rhoSW, p, tempis,                       &
+           pco2atm, fco2atm, schmidtco2, kwco2, K0,               &
+           co2starair, co2flux, dpco2 )
+!
+!=======================================================================
+!
+! AXY (26/06/15): to preserve both MEDUSA's scalar variables and
+!                 MOCSY's vector variables on code traceability
+!                 grounds, this additional wrapper does a rather
+!                 superfluous conversion between the two; in the
+!                 fullness of time, this should be dispensed with
+!                 and MOCSY used in its full vector form
+!
+        USE mocsy_singledouble
+        IMPLICIT NONE
+
+!> ======================================================================
+!  VARIABLES
+!> ======================================================================
+!
+   INTEGER, INTENT(in) :: N
+!
+!  MEDUSA-side
+!  Input variables
+   REAL(kind=wp), INTENT(in)  :: temp, sal, alk, dic, sil, phos
+   REAL(kind=wp), INTENT(in)  :: Patm, depth, lat, kw660, xco2
+!
+!  Output variables
+   REAL(kind=wp), INTENT(out) :: ph, pco2, fco2, co2, hco3, co3, OmegaA
+   REAL(kind=wp), INTENT(out) :: OmegaC, BetaD, rhoSW, p, tempis
+   REAL(kind=wp), INTENT(out) :: pco2atm, fco2atm, schmidtco2, kwco2, K0
+   REAL(kind=wp), INTENT(out) :: co2starair, co2flux, dpco2
+!
+!  MOCSY-side
+!  Input variables
+   REAL(kind=wp), DIMENSION(N) :: mtemp, msal, malk, mdic, msil, mphos
+   REAL(kind=wp), DIMENSION(N) :: mPatm, mdepth, mlat, mkw660, mxco2
+!
+!  Output variables
+   REAL(kind=wp), DIMENSION(N) :: mph, mpco2, mfco2, mco2, mhco3, mco3, mOmegaA
+   REAL(kind=wp), DIMENSION(N) :: mOmegaC, mBetaD, mrhoSW, mp, mtempis
+   REAL(kind=wp), DIMENSION(N) :: mpco2atm, mfco2atm, mschmidtco2, mkwco2, mK0
+   REAL(kind=wp), DIMENSION(N) :: mco2starair, mco2flux, mdpco2
+!
+!> ----------------------------------------------------------------------
+!  Set MOCSY inputs to equal MEDUSA inputs (amend units here)
+!> ----------------------------------------------------------------------
+!
+      mtemp(1)  = temp         ! degrees C
+      msal(1)   = sal          ! PSU
+      malk(1)   = alk / 1000.  ! meq  / m3 -> eq  / m3
+      mdic(1)   = dic / 1000.  ! mmol / m3 -> mol / m3
+      msil(1)   = sil / 1000.  ! mmol / m3 -> mol / m3
+      mphos(1)  = phos / 1000. ! mmol / m3 -> mol / m3
+      mPatm(1)  = Patm         ! atm
+      mdepth(1) = depth        ! m
+      mlat(1)   = lat          ! degrees N
+      mkw660(1) = kw660        ! m / s
+      mxco2(1)  = xco2         ! ppm
+!
+!> ----------------------------------------------------------------------
+!  Call MOCSY
+!> ----------------------------------------------------------------------
+!
+      CALL mocsy_carbchem( mtemp, msal, malk, mdic, msil, mphos, & ! inputs
+      mPatm, mdepth, mlat, mkw660, mxco2, 1,                     & ! inputs
+      mph, mpco2, mfco2, mco2, mhco3, mco3, mOmegaA,             & ! outputs
+      mOmegaC, mBetaD, mrhoSW, mp, mtempis,                      & ! outputs
+      mpco2atm, mfco2atm, mschmidtco2, mkwco2, mK0,              & ! outputs
+      mco2starair, mco2flux, mdpco2 ) ! outputs
+!
+!> ----------------------------------------------------------------------
+!  Set MOCSY outputs to equal MEDUSA outputs (amend units here)
+!> ----------------------------------------------------------------------
+!
+      ph         = mph(1)                 ! standard units
+      pco2       = mpco2(1)               ! uatm
+      fco2       = mfco2(1)               ! uatm
+      co2        = mco2(1) * 1000.        ! mol / m3 -> mmol / m3
+      hco3       = mhco3(1) * 1000.       ! mol / m3 -> mmol / m3
+      co3        = mco3(1) * 1000.        ! mol / m3 -> mmol / m3
+      OmegaA     = mOmegaA(1)             ! dimensionless
+      OmegaC     = mOmegaC(1)             ! dimensionless
+      BetaD      = mBetaD(1)              ! dimensionless
+      rhoSW      = mrhoSW(1)              ! kg / m3
+      p          = mp(1)                  ! db
+      tempis     = mtempis(1)             ! degrees C
+      pco2atm    = mpco2atm(1)            ! uatm
+      fco2atm    = mfco2atm(1)            ! uatm
+      schmidtco2 = mschmidtco2(1)         ! dimensionless
+      kwco2      = mkwco2(1)              ! m / s
+      K0         = mK0(1)                 ! (mol/kg) / atm
+      co2starair = mco2starair(1) * 1000. ! mol / m3 -> mmol / m3 
+      co2flux    = mco2flux(1) * 1000.    ! mol / m2 / s -> mmol / m2 / s 
+      dpco2      = mdpco2(1)              ! uatm
+
+  RETURN
+
+  END SUBROUTINE
+
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!
+      SUBROUTINE mocsy_carbchem( temp, sal, alk, dic, sil, phos,  &
+           Patm, depth, lat, kw660, xco2, N,                      &
+           ph, pco2, fco2, co2, hco3, co3, OmegaA,                &
+           OmegaC, BetaD, rhoSW, p, tempis,                       &
+           pco2atm, fco2atm, schmidtco2, kwco2, K0,               &
+           co2starair, co2flux, dpco2 )
+!
+!=======================================================================
+! 
+! AXY (23/06/15): MOCSY introduced to MEDUSA to update carbonate
+!                 chemistry for UKESM1 project
+!
+! Orr, J. C. and Epitalon, J.-M.: Improved routines to model the 
+! ocean carbonate system: mocsy 2.0, Geosci. Model Dev., 8, 485-499, 
+! doi:10.5194/gmd-8-485-2015, 2015.
+!
+! "mocsy is a Fortran 95 package designed to compute all ocean
+! carbonate system variables from DIC and total Alk, particularly
+! from models.  It updates previous OCMIP code, avoids 3 common 
+! model approximations, and offers the best-practice constants as 
+! well as more recent options. Its results agree with those from 
+! CO2SYS-MATLAB within 0.005%."
+!
+! Where possible the code remains identical to that published by
+! Orr & Epitalon (2015; henceforth OE15); some consolidation of 
+! MOCSY files has taken place, and the resulting package is 
+! comprised of four modules:
+!                 
+! 1. mocsy_wrapped.f90
+!    - This module contains the interface between MEDUSA and the
+!      main MOCSY routines; it draws from (but is very different
+!      from) the test_mocsy.f90 routine provided by OE15
+!
+! 2. mocsy_singledouble.f90
+!    - This module contains only precision definitions; it is
+!      based on the singledouble.f90 routine provided by OE15
+!
+! 3. mocsy_phsolvers.f90
+!    - This module contains a suite of solvers derived from
+!      Munhoven (2013) and modified by OE15; it is based on the
+!      phsolver.f90 routine provided by OE15
+!
+! 4. mocsy_gasflux.f90
+!    - This module contains a series of subroutines used to 
+!      calculate the air-sea flux of CO2; it consolidates four
+!      MOCSY routines with an OCMIP-2 Schmidt number routine
+!      updated with the new parameterisations of Wanninkhof (2014)
+!
+! 5. mocsy_mainmod.f90
+!    - This module consolidates all of the remaining MOCSY 
+!      functions and subroutines from OE15 into a single file
+!      for convenience
+!
+! NOTE: it is still possible to run PML's carbonate chemistry
+! routine in MEDUSA; at present this remains the default, if
+! less-preferred, routine (i.e. is used if key_mocsy is not
+! present)
+!
+        USE mocsy_singledouble
+        IMPLICIT NONE
+
+!> ======================================================================
+!  VARIABLES
+!> ======================================================================
+!
+!  Input variables
+   REAL(kind=wp), INTENT(in),  DIMENSION(N) :: temp, sal, alk, dic, sil, phos
+   REAL(kind=wp), INTENT(in),  DIMENSION(N) :: Patm, depth, lat, kw660, xco2
+   INTEGER, INTENT(in) :: N
+!
+!  Output variables
+   REAL(kind=wp), INTENT(out), DIMENSION(N) :: ph, pco2, fco2, co2, hco3, co3, OmegaA
+   REAL(kind=wp), INTENT(out), DIMENSION(N) :: OmegaC, BetaD, rhoSW, p, tempis
+   REAL(kind=wp), INTENT(out), DIMENSION(N) :: pco2atm, fco2atm, schmidtco2, kwco2, K0
+   REAL(kind=wp), INTENT(out), DIMENSION(N) :: co2starair, co2flux, dpco2
+!
+!  Local variables
+   REAL(kind=wp), DIMENSION(N) :: depth0, co2star
+   INTEGER :: i, totdat
+!
+!  "vars" Input options
+   CHARACTER(10) :: optCON, optT, optP, optB, optKf, optK1K2
+!   
+!  initialise depth0 to 0
+   depth0 = 0.0
+   
+!> ======================================================================
+!  CONFIGURE OPTIONS
+!> ======================================================================
+!> OPTIONS: see complete documentation in 'vars' subroutine
+!> Typical options for MODELS
+   optCON  = 'mol/m3' ! input concentrations are in MOL/M3
+   optT    = 'Tpot'   ! input temperature, variable 'temp', is POTENTIAL temp [°C]
+   optP    = 'm'      ! input variable 'depth' is in METERS
+   optB    = 'l10'    ! Lee et al. (2010) formulation for total boron
+   optK1K2 = 'l'      ! Lueker et al. (2000) formulations for K1 & K2 (best practices)
+   optKf   = 'dg'     ! Dickson & Riley (1979) formulation for Kf (recommended by Dickson & Goyet, 1994)
+
+!> ======================================================================
+!  CARBONATE CHEMISTRY CALCULATIONS
+!> ======================================================================
+!> Call mocsy's main subroutine to compute carbonate system variables: 
+!> pH, pCO2, fCO2, CO2*, HCO3- and CO32-, OmegaA, OmegaC, R
+!> FROM temperature, salinity, total alkalinity, dissolved inorganic 
+!> carbon, silica, phosphate, depth (or pressure) (1-D arrays)
+   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, optT, optP)
+!            optCON, optT, optP, optB, optK1K2, optKf)                                    ! INPUT OPTIONS
+
+!> ======================================================================
+!  GAS EXCHANGE CALCULATIONS
+!> ======================================================================
+!>
+!> Only calculate gas exchange fields if depth = 0
+   if (depth(1) .eq. 0.0) then
+!
+!     Compute pCO2atm [uatm] from xCO2 [ppm], atmospheric pressure [atm], & vapor pressure of seawater
+!     pCO2atm = (Patm - pH20(i)) * xCO2,   where pH20 is the vapor pressure of seawater [atm]
+      CALL x2pCO2atm(xco2, temp, sal, Patm, N, & ! INPUT
+      pco2atm)                                   ! OUTPUT
+
+!     Compute fCO2atm [uatm] from pCO2atm [uatm] & fugacity coefficient [unitless]
+!     fCO2atm = pCO2atm * fugcoeff,   where fugcoeff= exp(Patm*(B + 2.0*xc2*Del)/(R*tk) )
+      CALL p2fCO2(pco2atm, temp, Patm, depth0, N, & ! INPUT
+      fco2atm)                                      ! OUTPUT
+
+!     Compute Schmidt number for CO2 from potential temperature
+      CALL schmidt_co2(temp, N, & ! INPUT
+      schmidtco2)                 ! OUTPUT
+
+!     Compute transfer velocity for CO2 in m/s (see equation [4] in OCMIP2 design document & OCMIP2 Abiotic HOWTO)
+      kwco2 = kw660 * (660./schmidtco2)**0.5
+
+!     Surface K0 [(mol/kg) / atm] at T, S of surface water
+      CALL surface_K0(temp, sal, N, & ! INPUT
+      K0)                             ! OUTPUT
+
+!     "Atmospheric" [CO2*], air-sea CO2 flux, sfc DIC rate of change, & Delta pCO2
+!     all "lifted" from the gasx.f90 function of MOCSY
+      co2starair = K0 * fco2atm * 1.0e-6_wp * rhoSW ! Equil. [CO2*] for atm CO2 at Patm & sfc-water T,S [mol/m3]
+      co2star    = co2                              ! Oceanic [CO2*] in [mol/m3] from vars.f90
+      co2flux    = kwco2 * (co2starair - co2star)   ! Air-sea CO2 flux [mol/(m2 * s)]
+!     co2ex      = co2flux / dz1                    ! Change in sfc DIC due to gas exchange [mol/[m3 * s)]
+      dpco2      = pco2 - pco2atm                   ! Delta pCO2 (oceanic - atmospheric pCO2) [uatm]
+!     
+   endif
+
+  RETURN
+
+  END SUBROUTINE
+
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#  else
+   !!======================================================================
+   !!  Dummy module :                         No MOCSY carbonate chemistry
+   !!======================================================================
+
+CONTAINS
+
+   SUBROUTINE mocsy_interface( kt )                   ! Empty routine
+
+      INTEGER, INTENT( in ) ::   kt
+
+      WRITE(*,*) 'mocsy_interface: You should not have seen this print! error?', kt
+
+   END SUBROUTINE mocsy_interface
+#endif 
+
+   !!======================================================================
+
+END MODULE mocsy_wrapper
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 7693)
@@ -0,0 +1,87 @@
+MODULE par_medusa
+   !!======================================================================
+   !!                        ***  par_medusa  ***
+   !! TOP :   set the MEDUSA parameters
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!		   -   !  2013-03  (A. Yool) updated for v3.5 NEMO
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+   USE par_pisces , ONLY : jp_pisces       !: number of tracers in PISCES
+   USE par_pisces , ONLY : jp_pisces_2d    !: number of 2D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_3d    !: number of 3D diag in PISCES
+   USE par_pisces , ONLY : jp_pisces_trd   !: number of biological diag in PISCES
+
+   IMPLICIT NONE
+
+   INTEGER, PARAMETER ::   jp_lm      =  jp_pisces      !: 
+   INTEGER, PARAMETER ::   jp_lm_2d   =  jp_pisces_2d   !:
+   INTEGER, PARAMETER ::   jp_lm_3d   =  jp_pisces_3d   !:
+   INTEGER, PARAMETER ::   jp_lm_trd  =  jp_pisces_trd  !:
+
+#if defined key_medusa
+   !!---------------------------------------------------------------------
+   !!   'key_medusa'                     user defined tracers (MEDUSA)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_medusa     = .TRUE.   !: PTS flag 
+# if defined key_roam
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa     =  15      !: number of PTS tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_2d  =  225     !: additional 2d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_3d  =  5       !: additional 3d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_trd =  0       !: number of sms trends for MEDUSA
+# else
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa     =  11      !: number of PTS tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_2d  =  90      !: additional 2d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_3d  =  4       !: additional 3d output arrays (used if ln_diatrc=T)
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_trd =  0       !: number of sms trends for MEDUSA
+# endif
+
+   ! assign an index in trc arrays for each PTS prognostic variables
+   INTEGER, PUBLIC, PARAMETER ::   jpchn  =  jp_lm + 1      !: non-diatom chlorophyll concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpchd  =  jp_lm + 2      !: diatom     chlorophyll concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpphn  =  jp_lm + 3      !: non-diatom concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpphd  =  jp_lm + 4      !: diatom     concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpzmi  =  jp_lm + 5      !: microzooplankton concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpzme  =  jp_lm + 6      !: mesozooplankton  concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdin  =  jp_lm + 7      !: dissolved inorganic nitrogen concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpsil  =  jp_lm + 8      !: silicic acid concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpfer  =  jp_lm + 9      !: total iron concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdet  =  jp_lm + 10     !: slow-sinking detritus concentration
+   INTEGER, PUBLIC, PARAMETER ::   jppds  =  jp_lm + 11     !: diatom silicon concentration
+# if defined key_roam
+   INTEGER, PUBLIC, PARAMETER ::   jpdtc  =  jp_lm + 12     !: slow-sinking detritus carbon concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpdic  =  jp_lm + 13     !: dissolved inorganic carbon concentration
+   INTEGER, PUBLIC, PARAMETER ::   jpalk  =  jp_lm + 14     !: alkalinity
+   INTEGER, PUBLIC, PARAMETER ::   jpoxy  =  jp_lm + 15     !: dissolved oxygen concentration
+# endif
+
+#else
+   !!---------------------------------------------------------------------
+   !!   Default                           No user defined tracers (MEDUSA)
+   !!---------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_medusa     = .FALSE.  !: MEDUSA flag 
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa     =  0       !: No MEDUSA tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_2d  =  0       !: No MEDUSA additional 2d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_3d  =  0       !: No MEDUSA additional 3d output arrays 
+   INTEGER, PUBLIC, PARAMETER ::   jp_medusa_trd =  0       !: number of sms trends for MEDUSA
+#endif
+
+   ! Starting/ending PISCES do-loop indices (N.B. no PISCES : jpl_pcs < jpf_pcs the do-loop are never done)
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0     = jp_lm     + 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1     = jp_lm     + jp_medusa      !: Last  index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_2d  = jp_lm_2d  + 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_2d  = jp_lm_2d  + jp_medusa_2d   !: Last  index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_3d  = jp_lm_3d  + 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_3d  = jp_lm_3d  + jp_medusa_3d   !: Last  index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_trd = jp_lm_trd + 1              !: First index of MEDUSA passive tracers
+   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_trd = jp_lm_trd + jp_medusa_trd  !: Last  index of MEDUSA passive tracers
+
+   !!======================================================================
+END MODULE par_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 7693)
@@ -0,0 +1,520 @@
+MODULE sms_medusa 
+   !!----------------------------------------------------------------------
+   !!                     ***  sms_medusa.F90  ***  
+   !! TOP :   MEDUSA  Source Minus Sink variables
+   !!----------------------------------------------------------------------
+   !! History :    -   !  1999-09 (M. Levy)  original code
+   !!              -   !  2000-12 (O. Aumont, E. Kestenare)  add sediment 
+   !!             1.0  !  2005-10 (C. Ethe) F90
+   !!             1.0  !  2005-03  (A-S Kremeur) add fphylab, fzoolab, fdetlab, fdbod
+   !!              -   !  2005-06  (A-S Kremeur) add sedpocb, sedpocn, sedpoca
+   !!             2.0  !  2007-04  (C. Deltel, G. Madec)  Free form and modules
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!----------------------------------------------------------------------
+
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                         MEDUSA model
+   !!----------------------------------------------------------------------
+   USE par_oce
+   USE par_trc
+
+   IMPLICIT NONE
+   PUBLIC
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   INTEGER ::   numnatp_ref = -1           !! Logical units for namelist medusa
+   INTEGER ::   numnatp_cfg = -1           !! Logical units for namelist medusa
+   INTEGER ::   numonp      = -1           !! Logical unit for namelist medusa output
+
+!!----------------------------------------------------------------------
+!! Biological parameters
+!!----------------------------------------------------------------------
+!!
+!! Primary production and chl related quantities
+   REAL(wp) ::  xxi       !:  conversion factor from gC to mmolN 
+   REAL(wp) ::  xaln      !:  Chl-a specific initial slope of P-I curve for non-diatoms 
+   REAL(wp) ::  xald      !:  Chl-a specific initial slope of P-I curve for diatoms
+   INTEGER  ::  jphy      !:  phytoplankton T-dependent growth switch
+   REAL(wp) ::  xvpn      !:  maximum growth rate for non-diatoms
+   REAL(wp) ::  xvpd      !:  maximum growth rate for diatoms
+   REAL(wp) ::  xthetam   !:  maximum Chl to C ratio for non-diatoms      
+   REAL(wp) ::  xthetamd  !:  maximum Chl to C ratio for diatoms    
+   REAL(wp) ::  jq10      !:  specific Q10 value (jphy==2)    
+!!
+!! Diatom silicon parameters
+   REAL(wp) ::  xsin0     !:  minimum diatom Si:N ratio
+   REAL(wp) ::  xnsi0     !:  minimum diatom N:Si ratio
+   REAL(wp) ::  xuif      !:  hypothetical growth ratio at infinite Si:N ratio
+!!
+!! Nutrient limitation
+   INTEGER  ::  jliebig   !:  Liebig nutrient uptake switch
+   REAL(wp) ::  xnln      !:  half-sat constant for DIN uptake by non-diatoms 
+   REAL(wp) ::  xnld      !:  half-sat constant for DIN uptake by diatoms 
+   REAL(wp) ::  xsld      !:  half-sat constant for Si uptake by diatoms 
+   REAL(wp) ::  xfln      !:  half-sat constant for Fe uptake by non-diatoms 
+   REAL(wp) ::  xfld      !:  half-sat constant for Fe uptake by diatoms  
+!!
+!! Grazing
+   REAL(wp) ::  xgmi      !:  microzoo maximum growth rate 
+   REAL(wp) ::  xgme      !:  mesozoo maximum growth rate 
+   REAL(wp) ::  xkmi      !:  microzoo grazing half-sat parameter
+   REAL(wp) ::  xkme      !:  mesozoo grazing half-sat parameter
+   REAL(wp) ::  xphi      !:  micro/mesozoo grazing inefficiency
+   REAL(wp) ::  xbetan    !:  micro/mesozoo N assimilation efficiency
+   REAL(wp) ::  xbetac    !:  micro/mesozoo C assimilation efficiency
+   REAL(wp) ::  xkc       !:  micro/mesozoo net C growth efficiency
+   REAL(wp) ::  xpmipn    !:  grazing preference of microzoo for non-diatoms
+   REAL(wp) ::  xpmid     !:  grazing preference of microzoo for diatoms
+   REAL(wp) ::  xpmepn    !:  grazing preference of mesozoo for non-diatoms 
+   REAL(wp) ::  xpmepd    !:  grazing preference of mesozoo for diatoms
+   REAL(wp) ::  xpmezmi   !:  grazing preference of mesozoo for microzoo
+   REAL(wp) ::  xpmed     !:  grazing preference of mesozoo for detritus
+!!
+!! Metabolic losses
+   REAL(wp) ::  xmetapn   !:  non-diatom metabolic loss rate
+   REAL(wp) ::  xmetapd   !:  diatom     metabolic loss rate
+   REAL(wp) ::  xmetazmi  !:  microzoo   metabolic loss rate
+   REAL(wp) ::  xmetazme  !:  mesozoo    metabolic loss rate
+!!
+!! Mortality losses
+   INTEGER  ::  jmpn      !:  non-diatom mortality functional form
+   REAL(wp) ::  xmpn      !:  non-diatom mortality rate
+   REAL(wp) ::  xkphn     !:  non-diatom mortality half-sat constant
+   INTEGER  ::  jmpd      !:  diatom     mortality functional form
+   REAL(wp) ::  xmpd      !:  diatom     mortality rate
+   REAL(wp) ::  xkphd     !:  diatom     mortality half-sat constant
+   INTEGER  ::  jmzmi     !:  microzoo   mortality functional form
+   REAL(wp) ::  xmzmi     !:  microzoo   mortality rate
+   REAL(wp) ::  xkzmi     !:  microzoo   mortality half-sat constant
+   INTEGER  ::  jmzme     !:  mesozoo    mortality functional form
+   REAL(wp) ::  xmzme     !:  mesozoo    mortality rate
+   REAL(wp) ::  xkzme     !:  mesozoo    mortality half-sat constant
+!!
+!! Remineralisation
+   INTEGER  ::  jmd       !:  detritus T-dependent remineralisation switch
+   INTEGER  ::  jsfd      !:  accelerate seafloor detritus remin. switch
+   REAL(wp) ::  xmd       !:  detrital nitrogen remineralisation rate 
+   REAL(wp) ::  xmdc      !:  detrital carbon remineralisation rate 
+!!
+!! Stochiometric ratios
+   REAL(wp) ::  xthetapn  !:  non-diatom C:N ratio
+   REAL(wp) ::  xthetapd  !:  diatom C:N ratio
+   REAL(wp) ::  xthetazmi !:  microzoo C:N ratio
+   REAL(wp) ::  xthetazme !:  mesozoo C:N ratio
+   REAL(wp) ::  xthetad   !:  detritus C:N ratio
+   REAL(wp) ::  xrfn      !:  phytoplankton Fe:N ratio
+   REAL(wp) ::  xrsn      !:  diatom Si:N ratio (NOT USED HERE; RETAINED FOR LOBSTER)
+!!
+!! Iron parameters
+   INTEGER  ::  jiron     !:  iron scavenging submodel switch
+   REAL(wp) ::  xfe_mass  !:  iron atomic mass
+   REAL(wp) ::  xfe_sol   !:  aeolian iron solubility
+   REAL(wp) ::  xfe_sed   !:  sediment iron input
+   REAL(wp) ::  xLgT      !:  total ligand concentration (umol/m3)
+   REAL(wp) ::  xk_FeL    !:  dissociation constant for (Fe + L)
+   REAL(wp) ::  xk_sc_Fe  !:  scavenging rate of "free" iron
+!!
+!! Gravitational sinking      
+   REAL(wp) ::  vsed      !:  detritus gravitational sinking rate 
+   REAL(wp) ::  xhr       !:  coefficient for Martin et al. (1987) remineralisation
+!!
+!! Fast-sinking detritus parameters
+   INTEGER  ::  jexport   !:  fast detritus remineralisation switch
+   INTEGER  ::  jfdfate   !:  fate of fast detritus at seafloor switch
+   INTEGER  ::  jrratio   !:  rain ratio switch
+   INTEGER  ::  jocalccd  !:  CCD switch
+   REAL(wp) ::  xridg_r0  !:  Ridgwell rain ratio coefficient
+   REAL(wp) ::  xfdfrac1  !:  fast-sinking fraction of diatom nat. mort. losses
+   REAL(wp) ::  xfdfrac2  !:  fast-sinking fraction of mesozooplankton mort. losses
+   REAL(wp) ::  xfdfrac3  !:  fast-sinking fraction of diatom silicon grazing losses
+   REAL(wp) ::  xcaco3a   !:  polar (high latitude) CaCO3 fraction
+   REAL(wp) ::  xcaco3b   !:  equatorial (low latitude) CaCO3 fraction
+   REAL(wp) ::  xmassc    !:  organic C mass:mole ratio, C106 H175 O40 N16 P1
+   REAL(wp) ::  xmassca   !:  calcium carbonate mass:mole ratio, CaCO3
+   REAL(wp) ::  xmasssi   !:  biogenic silicon mass:mole ratio, (H2SiO3)n
+   REAL(wp) ::  xprotca   !:  calcium carbonate protection ratio
+   REAL(wp) ::  xprotsi   !:  biogenic silicon protection ratio
+   REAL(wp) ::  xfastc    !:  organic C remineralisation length scale
+   REAL(wp) ::  xfastca   !:  calcium carbonate dissolution length scale
+   REAL(wp) ::  xfastsi   !:  biogenic silicon dissolution length scale
+!!
+!! Benthos parameters
+   INTEGER  ::  jorgben   !:  does   organic detritus go to the benthos?
+   INTEGER  ::  jinorgben !:  does inorganic detritus go to the benthos?
+!!
+   REAL(wp) ::  xsedn     !:  organic   nitrogen sediment remineralisation rate 
+   REAL(wp) ::  xsedfe    !:  organic   iron     sediment remineralisation rate 
+   REAL(wp) ::  xsedsi    !:  inorganic silicon  sediment dissolution      rate 
+   REAL(wp) ::  xsedc     !:  organic   carbon   sediment remineralisation rate 
+   REAL(wp) ::  xsedca    !:  inorganic carbon   sediment dissolution      rate 
+   REAL(wp) ::  xburial   !:  burial rate of seafloor detritus
+!!
+!! River parameters
+   INTEGER  ::  jriver_n  !:  riverine nitrogen?   0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_si !:  riverine silicon?    0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_c  !:  riverine carbon?     0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_alk!:  riverine alkalinity? 0 = no, 1 = conc, 2 = flux
+   INTEGER  ::  jriver_dep!:  depth river input added to?  1 = surface, >1 possible
+!!
+!! Miscellaneous
+   REAL(wp) ::  xsdiss    !:  diatom frustule dissolution rate
+!!
+!! Additional parameters
+   INTEGER  ::  jpkb      !:  vertical layer for diagnostic of the vertical flux 
+!!
+!! UKESM diagnostics
+   INTEGER  ::  jdms         !: include DMS diagnostics ? Jpalm (27-08-2014) 
+   INTEGER  ::  jdms_input   !: use instant (0) or diel-average (1) inputs (AXY, 08/07/2015)
+   INTEGER  ::  jdms_model   !: choice of DMS model passed to atmosphere
+!!                              1 = ANDR, 2 = SIMO, 3 = ARAN, 4 = HALL
+!!
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   remdmp   !: depth dependent damping coefficient of passive tracers 
+!!
+!! AXY (27/07/10): add in indices for depth horizons (for sinking flux
+!!                 and seafloor iron inputs)
+   INTEGER  ::    i0100, i0150, i0200, i0500, i1000, i1100
+#if defined key_roam
+!!
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+   REAL(wp) ::  xthetaphy    !:  oxygen evolution/consumption by phytoplankton 
+   REAL(wp) ::  xthetazoo    !:  oxygen consumption by zooplankton 
+   REAL(wp) ::  xthetanit    !:  oxygen consumption by nitrogen remineralisation
+   REAL(wp) ::  xthetarem    !:  oxygen consumption by carbon remineralisation
+   REAL(wp) ::  xo2min       !:  oxygen minimum concentration
+!! 
+!! 3D fields of carbonate system parameters
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_pH       !: 3D pH
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_h2co3    !: 3D carbonic acid
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_hco3     !: 3D bicarbonate
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_co3      !: 3D carbonate
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_omcal    !: 3D omega calcite
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: f3_omarg    !: 3D omega aragonite
+!! 
+!! 2D fields of calcium carbonate compensation depth
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: f2_ccd_cal  !: 2D calcite CCD depth
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: f2_ccd_arg  !: 2D aragonite CCD depth
+!!
+!! 2D fields of organic and inorganic material sedimented on the seafloor
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_n    !: 2D organic nitrogen   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_n    !: 2D organic nitrogen   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_n    !: 2D organic nitrogen   (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_fe   !: 2D organic iron       (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_fe   !: 2D organic iron       (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_fe   !: 2D organic iron       (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_si   !: 2D inorganic silicon  (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_si   !: 2D inorganic silicon  (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_si   !: 2D inorganic silicon  (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_c    !: 2D organic carbon     (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_c    !: 2D organic carbon     (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_c    !: 2D organic carbon     (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_sed_ca   !: 2D inorganic carbon   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_sed_ca   !: 2D inorganic carbon   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_sed_ca   !: 2D inorganic carbon   (after)
+!!
+!! 2D fields of temporally averaged properties for DMS calculations (AXY, 07/07/15)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_dms_chn  !: 2D avg CHN   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_dms_chn  !: 2D avg CHN   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_dms_chn  !: 2D avg CHN   (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_dms_chd  !: 2D avg CHD   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_dms_chd  !: 2D avg CHD   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_dms_chd  !: 2D avg CHD   (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_dms_mld  !: 2D avg MLD   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_dms_mld  !: 2D avg MLD   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_dms_mld  !: 2D avg MLD   (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_dms_qsr  !: 2D avg QSR   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_dms_qsr  !: 2D avg QSR   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_dms_qsr  !: 2D avg QSR   (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_dms_din  !: 2D avg DIN   (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_dms_din  !: 2D avg DIN   (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_dms_din  !: 2D avg DIN   (after)
+!!
+!! 2D fields needing to be knows at first tstp for coupling with atm - UKEMS(Jpalm,14-06-2016)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_co2_flx  !: 2D avg fx co2 (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_co2_flx  !: 2D avg fx co2 (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_co2_flx  !: 2D avg fx co2 (after)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zb_dms_srf  !: 2D avg fx co2 (before)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: zn_dms_srf  !: 2D avg fx co2 (now)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: za_dms_srf  !: 2D avg fx co2 (after)
+
+#endif
+
+!!----------------------------------------------------------------------
+!! CCD parameter
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ocal_ccd  !: CCD depth
+
+!!----------------------------------------------------------------------
+!! Dust parameters
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dust      !: dust parameter 1
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   zirondep  !! Fe deposition
+
+!!----------------------------------------------------------------------
+!! River parameters
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_n      !: riverine N
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_si     !: riverine Si
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_c      !: riverine C
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   riv_alk    !: riverine alkalinity
+   !! AXY (19/07/12): add this to permit river fluxes to be added below top box
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   friver_dep !: where river fluxes added
+
+#if defined key_roam
+!!----------------------------------------------------------------------
+!! Atmospheric pCO2 data (1859 to 2100 inclusive)
+!!----------------------------------------------------------------------
+!!
+   REAL(wp), DIMENSION(242)         ::   hist_pco2 !: pCO2
+
+# if defined key_rcp26
+      !! UKMO, run AJKKH + KAAEC, RCP 2.6, pCO2 time evolution
+      DATA hist_pco2 / 286.0230, 286.1730, 286.3230, 286.4480, 286.5730, &
+      & 286.7230, 286.8480, 286.9480, 287.0480, 287.1730, &
+      & 287.3230, 287.4730, 287.6480, 287.8480, 288.0730, &
+      & 288.3480, 288.6480, 288.9730, 289.3470, 289.7470, &
+      & 290.1730, 290.6470, 291.1470, 291.6220, 292.0720, &
+      & 292.5220, 292.9220, 293.2470, 293.5220, 293.7470, &
+      & 293.9470, 294.1220, 294.2720, 294.4220, 294.5470, &
+      & 294.6470, 294.7470, 294.8470, 294.9710, 295.1710, &
+      & 295.4460, 295.7470, 296.0720, 296.4210, 296.7710, &
+      & 297.1460, 297.5710, 298.0210, 298.4460, 298.8460, &
+      & 299.2460, 299.6450, 300.0210, 300.3710, 300.7200, &
+      & 301.0450, 301.3460, 301.6710, 302.0200, 302.3450, &
+      & 302.6450, 302.9700, 303.3450, 303.7200, 304.0700, &
+      & 304.4700, 304.9200, 305.3440, 305.7700, 306.2450, &
+      & 306.7190, 307.1700, 307.6440, 308.1190, 308.5440, &
+      & 308.9440, 309.3440, 309.6940, 309.9440, 310.1190, &
+      & 310.2440, 310.3190, 310.3190, 310.2440, 310.1440, &
+      & 310.0690, 310.0440, 310.0690, 310.1440, 310.2690, &
+      & 310.4440, 310.6940, 311.0430, 311.4440, 311.8690, &
+      & 312.3680, 312.9430, 313.5430, 314.1680, 314.7900, &
+      & 315.4430, 316.2150, 317.0170, 317.7370, 318.3400, &
+      & 318.8680, 319.5900, 320.5890, 321.5470, 322.5770, &
+      & 323.8440, 324.9260, 325.7960, 327.0810, 328.6180, &
+      & 329.6830, 330.5250, 331.6880, 333.2120, 334.7870, &
+      & 336.4640, 338.2990, 339.6660, 340.7310, 342.1360, &
+      & 343.7200, 345.2200, 346.7350, 348.5820, 350.6740, &
+      & 352.4230, 353.7910, 354.9530, 355.8210, 356.7130, &
+      & 358.0630, 359.7720, 361.3970, 363.0900, 365.2560, &
+      & 367.2810, 368.7980, 370.4000, 372.4550, 374.6920, &
+      & 376.7440, 378.7440, 380.7580, 382.7080, 384.7300, &
+      & 386.9310, 389.2150, 391.4910, 393.7710, 396.0460, &
+      & 398.3240, 400.6080, 402.8950, 405.1780, 407.4550, &
+      & 409.7260, 411.9930, 414.2500, 416.4410, 418.5280, &
+      & 420.5250, 422.4390, 424.2720, 426.0200, 427.6750, &
+      & 429.2360, 430.7050, 432.0850, 433.3580, 434.5140, &
+      & 435.5740, 436.5490, 437.4420, 438.2550, 438.9810, &
+      & 439.6110, 440.1430, 440.5770, 440.9450, 441.2660, &
+      & 441.5410, 441.7840, 442.0050, 442.2040, 442.3780, &
+      & 442.5210, 442.6200, 442.6720, 442.6810, 442.6540, &
+      & 442.5830, 442.4670, 442.3270, 442.1680, 441.9960, &
+      & 441.8060, 441.5930, 441.3440, 441.0540, 440.7230, &
+      & 440.3510, 439.9300, 439.4650, 438.9730, 438.4630, &
+      & 437.9400, 437.4020, 436.8400, 436.2640, 435.6850, &
+      & 435.1030, 434.5160, 433.9170, 433.3060, 432.7010, &
+      & 432.1110, 431.5380, 430.9810, 430.4320, 429.8860, &
+      & 429.3370, 428.7810, 428.2220, 427.6490, 427.0660, &
+      & 426.4890, 425.9270, 425.3840, 424.8610, 424.3540, &
+      & 423.8540, 423.3540, 422.8530, 422.3510, 421.8410, &
+      & 421.3250, 420.8190 /
+# else
+      !! UKMO, run AJKKH + KAAEF, RCP 8.5, pCO2 time evolution
+      DATA hist_pco2 / 286.0230, 286.1730, 286.3230, 286.4480, 286.5730, &
+      & 286.7230, 286.8480, 286.9480, 287.0480, 287.1730, &
+      & 287.3230, 287.4730, 287.6480, 287.8480, 288.0730, &
+      & 288.3480, 288.6480, 288.9730, 289.3470, 289.7470, &
+      & 290.1730, 290.6470, 291.1470, 291.6220, 292.0720, &
+      & 292.5220, 292.9220, 293.2470, 293.5220, 293.7470, &
+      & 293.9470, 294.1220, 294.2720, 294.4220, 294.5470, &
+      & 294.6470, 294.7470, 294.8470, 294.9710, 295.1710, &
+      & 295.4460, 295.7470, 296.0720, 296.4210, 296.7710, &
+      & 297.1460, 297.5710, 298.0210, 298.4460, 298.8460, &
+      & 299.2460, 299.6450, 300.0210, 300.3710, 300.7200, &
+      & 301.0450, 301.3460, 301.6710, 302.0200, 302.3450, &
+      & 302.6450, 302.9700, 303.3450, 303.7200, 304.0700, &
+      & 304.4700, 304.9200, 305.3440, 305.7700, 306.2450, &
+      & 306.7190, 307.1700, 307.6440, 308.1190, 308.5440, &
+      & 308.9440, 309.3440, 309.6940, 309.9440, 310.1190, &
+      & 310.2440, 310.3190, 310.3190, 310.2440, 310.1440, &
+      & 310.0690, 310.0440, 310.0690, 310.1440, 310.2690, &
+      & 310.4440, 310.6940, 311.0430, 311.4440, 311.8690, &
+      & 312.3680, 312.9430, 313.5430, 314.1680, 314.7900, &
+      & 315.4430, 316.2150, 317.0170, 317.7370, 318.3400, &
+      & 318.8680, 319.5900, 320.5890, 321.5470, 322.5770, &
+      & 323.8440, 324.9260, 325.7960, 327.0810, 328.6180, &
+      & 329.6830, 330.5250, 331.6880, 333.2120, 334.7870, &
+      & 336.4640, 338.2990, 339.6660, 340.7310, 342.1360, &
+      & 343.7200, 345.2200, 346.7350, 348.5820, 350.6740, &
+      & 352.4230, 353.7910, 354.9530, 355.8210, 356.7130, &
+      & 358.0630, 359.7720, 361.3970, 363.0900, 365.2560, &
+      & 367.2810, 368.7980, 370.4000, 372.4550, 374.6920, &
+      & 376.7440, 378.7440, 380.7580, 382.7080, 384.7300, &
+      & 386.9420, 389.2540, 391.5670, 393.9370, 396.3920, &
+      & 398.9320, 401.5550, 404.2550, 407.0220, 409.8530, &
+      & 412.7470, 415.7050, 418.7210, 421.7880, 424.9180, &
+      & 428.1200, 431.3970, 434.7470, 438.1650, 441.6410, &
+      & 445.1700, 448.7530, 452.3920, 456.0950, 459.8810, &
+      & 463.7680, 467.7660, 471.8750, 476.0960, 480.4210, &
+      & 484.8390, 489.3470, 493.9430, 498.6400, 503.4380, &
+      & 508.3410, 513.3630, 518.5160, 523.8050, 529.2290, &
+      & 534.7780, 540.4450, 546.2230, 552.1120, 558.1110, &
+      & 564.2110, 570.4130, 576.7390, 583.1990, 589.7980, &
+      & 596.5390, 603.4110, 610.4060, 617.4940, 624.6500, &
+      & 631.8800, 639.1750, 646.5360, 653.9800, 661.5230, &
+      & 669.1840, 676.9570, 684.8290, 692.7790, 700.7690, &
+      & 708.8050, 716.8870, 725.0020, 733.1770, 741.3900, &
+      & 749.6700, 758.0480, 766.5050, 775.0350, 783.6110, &
+      & 792.2200, 800.8740, 809.5680, 818.2760, 827.0090, &
+      & 835.8020, 844.6550, 853.5730, 862.5690, 871.6190, &
+      & 880.7020, 889.8240, 898.9590, 908.1270, 917.3080, &
+      & 926.4960, 935.7040 /
+# endif
+#endif
+
+!!----------------------------------------------------------------------
+!! Optical parameters
+!!----------------------------------------------------------------------
+!!
+   REAL(wp) ::   xkr0       !: water coefficient absorption in red      (NAMELIST)
+   REAL(wp) ::   xkg0       !: water coefficient absorption in green    (NAMELIST)
+   REAL(wp) ::   xkrp       !: pigment coefficient absorption in red    (NAMELIST)
+   REAL(wp) ::   xkgp       !: pigment coefficient absorption in green  (NAMELIST)
+   REAL(wp) ::   xlr        !: exposant for pigment absorption in red   (NAMELIST)
+   REAL(wp) ::   xlg        !: exposant for pigment absorption in green (NAMELIST)
+   REAL(wp) ::   rpig       !: chla/chla+phea ratio                     (NAMELIST)
+                                                        
+   INTEGER , ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   neln    !: number of levels in the euphotic layer
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   xze     !: euphotic layer depth
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   xpar    !: par (photosynthetic available radiation)
+
+!!----------------------------------------------------------------------
+!! Sediment parameters                               
+!! 
+!! AXY (16/01/12): these parameters were originally part of the pre-
+!!                 cursor model on which MEDUSA's code was grounded;
+!!                 they do not relate to the sediment/benthos submodel
+!!                 added as part of the ROAM project; they have only
+!!                 been retained because they are distributed through
+!!                 MEDUSA and require a proper clean-up to purge
+!!----------------------------------------------------------------------
+!!
+   REAL(wp) ::   sedlam       !: time coefficient of POC remineralization in sediments
+   REAL(wp) ::   sedlostpoc   !: ???
+   REAL(wp) ::   areacot      !: ???
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: dminl       !: fraction of sinking POC released in sediments
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: dmin3       !: fraction of sinking POC released at each level
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: sedpocb     !: mass of POC in sediments
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: sedpocn     !: mass of POC in sediments
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: sedpoca     !: mass of POC in sediments
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: fbodf       !: rapid sinking particles
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: fbods       !: rapid sinking particles
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: fbodn       !: rapid sinking particles
+                                                        
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: ffln        !: 
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: fflf        !: 
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: ffls        !: 
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   :: cmask       !: ???
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION sms_medusa_alloc()
+      !!----------------------------------------------------------------------
+      !!        *** ROUTINE sms_medusa_alloc ***
+      !!----------------------------------------------------------------------
+      USE lib_mpp , ONLY: ctl_warn
+      INTEGER ::   ierr(7)        ! Local variables
+      !!----------------------------------------------------------------------
+      ierr(:) = 0
+      !
+#if defined key_medusa
+      !* depth-dependent damping coefficient
+      ALLOCATE( remdmp(jpk,jp_medusa),                           STAT=ierr(1) )
+# if defined key_roam
+      !* 2D and 3D fields of carbonate system parameters
+      ALLOCATE( f2_ccd_cal(jpi,jpj)  , f2_ccd_arg(jpi,jpj)  ,       &
+         &      f3_pH(jpi,jpj,jpk)   , f3_h2co3(jpi,jpj,jpk),       &
+         &      f3_hco3(jpi,jpj,jpk) , f3_co3(jpi,jpj,jpk)  ,       &
+         &      f3_omcal(jpi,jpj,jpk), f3_omarg(jpi,jpj,jpk),    STAT=ierr(2) )
+      !* 2D fields of organic and inorganic material sedimented on the seafloor
+      ALLOCATE( zb_sed_n(jpi,jpj)    , zn_sed_n(jpi,jpj)    ,       &
+         &      za_sed_n(jpi,jpj)    ,                              &
+         &      zb_sed_fe(jpi,jpj)   , zn_sed_fe(jpi,jpj)   ,       &
+         &      za_sed_fe(jpi,jpj)   ,                              &
+         &      zb_sed_si(jpi,jpj)   , zn_sed_si(jpi,jpj)   ,       &
+         &      za_sed_si(jpi,jpj)   ,                              &
+         &      zb_sed_c(jpi,jpj)    , zn_sed_c(jpi,jpj)    ,       &
+         &      za_sed_c(jpi,jpj)    ,                              &
+         &      zb_sed_ca(jpi,jpj)   , zn_sed_ca(jpi,jpj)   ,       &
+         &      za_sed_ca(jpi,jpj)   ,                           STAT=ierr(3) )
+      !* 2D fields of temporally averaged properties for DMS calculations (AXY, 07/07/15)
+      ALLOCATE( zb_dms_chn(jpi,jpj)  , zn_dms_chn(jpi,jpj)  ,       &
+         &      za_dms_chn(jpi,jpj)  ,                              &
+         &      zb_dms_chd(jpi,jpj)  , zn_dms_chd(jpi,jpj)  ,       &		  
+         &      za_dms_chd(jpi,jpj)  ,                              &
+         &      zb_dms_mld(jpi,jpj)  , zn_dms_mld(jpi,jpj)  ,       &		  
+         &      za_dms_mld(jpi,jpj)  ,                              &
+         &      zb_dms_qsr(jpi,jpj)  , zn_dms_qsr(jpi,jpj)  ,       &		  
+         &      za_dms_qsr(jpi,jpj)  ,                              &
+         &      zb_dms_din(jpi,jpj)  , zn_dms_din(jpi,jpj)  ,       &		  
+         &      za_dms_din(jpi,jpj)  ,                           STAT=ierr(4) )
+      !* 2D fields needing to be knows at first tstp for coupling with atm -
+      !UKEMSi (Jpalm,14-06-2016) 
+      ALLOCATE( zb_co2_flx(jpi,jpj)  , zn_co2_flx(jpi,jpj)  ,       &
+         &      za_co2_flx(jpi,jpj)  ,                              &
+         &      zb_dms_srf(jpi,jpj)  , zn_dms_srf(jpi,jpj)  ,       &           
+         &      za_dms_srf(jpi,jpj)  ,                           STAT=ierr(5) )
+# endif
+      !* 2D fields of miscellaneous parameters
+      ALLOCATE( ocal_ccd(jpi,jpj)    , dust(jpi,jpj)        ,       &
+         &      zirondep(jpi,jpj)                           ,       &
+         &      riv_n(jpi,jpj)                              ,       &
+         &      riv_si(jpi,jpj)      , riv_c(jpi,jpj)       ,       &
+         &      riv_alk(jpi,jpj)     , friver_dep(jpk,jpk)  ,    STAT=ierr(6) )
+      !* 2D and 3D fields of light parameters
+      ALLOCATE( neln(jpi,jpj)        , xze(jpi,jpj)         ,       &
+         &      xpar(jpi,jpj,jpk)    ,                           STAT=ierr(7) )
+      !* 2D and 3D fields of sediment-associated parameters
+      ALLOCATE( dminl(jpi,jpj)       , dmin3(jpi,jpj,jpk)   ,       &
+         &      sedpocb(jpi,jpj)     , sedpocn(jpi,jpj)     ,       &
+         &      sedpoca(jpi,jpj)     , fbodn(jpi,jpj)       ,       &
+         &      fbodf(jpi,jpj)       , fbods(jpi,jpj)       ,       &
+         &      ffln(jpi,jpj,jpk)    , fflf(jpi,jpj,jpk)    ,       &
+         &      ffls(jpi,jpj,jpk)    , cmask(jpi,jpj)       ,    STAT=ierr(8) ) 
+#endif
+      !
+      sms_medusa_alloc = MAXVAL( ierr )
+      !
+      IF( sms_medusa_alloc /= 0 )   CALL ctl_warn('sms_medusa_alloc: failed to allocate arrays')
+      !
+   END FUNCTION sms_medusa_alloc
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                     NO MEDUSA model 
+   !!----------------------------------------------------------------------
+#endif
+
+   !!======================================================================
+END MODULE sms_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcavg_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcavg_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcavg_medusa.F90	(revision 7693)
@@ -0,0 +1,128 @@
+MODULE trcavg_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcavg_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :    -   !  2015-07  (A. Yool) Original code
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA rolling averages
+   !!----------------------------------------------------------------------
+   !!   trc_avg_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE in_out_manager  ! I/O manager
+
+      IMPLICIT NONE
+      PRIVATE
+
+      PUBLIC   trc_avg_medusa    ! called in trc_sms_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+!=======================================================================
+!
+      SUBROUTINE trc_avg_medusa( kt )
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates rolling averages of variables
+      !! Author : Andrew Yool
+      !! Date   : 23/07/15
+      !!
+      !! Calculates and updates rolling averages of properties such
+      !! as surface irradiance and mixed layer depth that are used
+      !! in functions that require average rather than instantaneous
+      !! values.
+      !!
+      !! This functionality was originally added to support the
+      !! calculation of surface DMS concentrations - and was done so
+      !! within the trcbio_meduse.F90 routine - but was moved to
+      !! this separate module so that its calculations could be used
+      !! to inform MEDUSA's submarine irradiance field
+      !!
+!=======================================================================
+!
+      IMPLICIT NONE
+!
+      INTEGER, INTENT( in ) ::   kt   ! index of the time stepping
+! 
+!=======================================================================
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA inside trc_avg_medusa'
+         CALL flush(numout)
+# endif
+      !! AXY (24/07/15): alter this to report on first MEDUSA call
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_avg_medusa: MEDUSA rolling average'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+         IF(lwp) WRITE(numout,*) ' kt =',kt
+      ENDIF
+      !!
+      !!----------------------------------------------------------------------
+      !! Process average fields
+      !! The empirical formulae used for estimating surface DMS concentrations
+      !! require temporally averaged input fields; this block calculates these
+      !! averages based on diel averages; note that rdt 
+      !!----------------------------------------------------------------------
+      !!
+      zn_dms_chn(:,:) = ( zb_dms_chn(:,:) * ((86400. - rdt) / 86400.) ) &
+      &                  + ( trn(:,:,1,jpchn) * (rdt / 86400.) )
+      zb_dms_chn(:,:) = zn_dms_chn(:,:)
+      zn_dms_chd(:,:) = ( zb_dms_chd(:,:) * ((86400. - rdt) / 86400.) ) &
+      &                  + ( trn(:,:,1,jpchd) * (rdt / 86400.) )
+      zb_dms_chd(:,:) = zn_dms_chd(:,:)
+      zn_dms_mld(:,:) = ( zb_dms_mld(:,:) * ((86400. - rdt) / 86400.) ) &
+      &                  + (        hmld(:,:) * (rdt / 86400.) )
+      zb_dms_mld(:,:) = zn_dms_mld(:,:)
+      zn_dms_qsr(:,:) = ( zb_dms_qsr(:,:) * ((86400. - rdt) / 86400.) ) &
+      &                  + (         qsr(:,:) * (rdt / 86400.) )
+      zb_dms_qsr(:,:) = zn_dms_qsr(:,:)
+      zn_dms_din(:,:) = ( zb_dms_din(:,:) * ((86400. - rdt) / 86400.) ) &
+      &                  + ( trn(:,:,1,jpdin) * (rdt / 86400.) )
+      zb_dms_din(:,:) = zn_dms_din(:,:)
+
+  END SUBROUTINE trc_avg_medusa
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+
+CONTAINS
+
+!=======================================================================
+!
+   SUBROUTINE trc_avg_medusa( kt )                                        !! EMPTY Routine
+!      
+!
+      INTEGER, INTENT( in ) ::   kt
+!
+
+      WRITE(*,*) 'trc_avg_medusa: You should not have seen this print! error?'
+
+   END SUBROUTINE trc_avg_medusa
+#endif
+
+   !!======================================================================
+END MODULE  trcavg_medusa
+
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 7693)
@@ -0,0 +1,6151 @@
+MODULE trcbio_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcbio  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  1999-07  (M. Levy)              original code
+   !!  -   !  2000-12  (E. Kestenare)         assign parameters to name individual tracers
+   !!  -   !  2001-03  (M. Levy)              LNO3 + dia2d 
+   !! 2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !!  -   !  2008-08  (K. Popova)            adaptation for MEDUSA
+   !!  -   !  2008-11  (A. Yool)              continuing adaptation for MEDUSA
+   !!  -   !  2010-03  (A. Yool)              updated for branch inclusion
+   !!  -   !  2011-08  (A. Yool)              updated for ROAM (see below)
+   !!  -   !  2013-03  (A. Yool)              updated for iMARNET
+   !!  -   !  2013-05  (A. Yool)              updated for v3.5
+   !!  -   !  2014-08  (A. Yool, J. Palm)     Add DMS module for UKESM1 model
+   !!  -   !  2015-06  (A. Yool)              Update to include MOCSY
+   !!  -   !  2015-07  (A. Yool)              Update for rolling averages
+   !!  -   !  2015-10  (J. Palm)              Update for diag outputs through iom_use  
+   !!  -   !  2016-11  (A. Yool)              Updated diags for CMIP6
+   !!----------------------------------------------------------------------
+   !!
+#if defined key_roam
+   !!----------------------------------------------------------------------
+   !! Updates for the ROAM project include:
+   !!   - addition of DIC, alkalinity, detrital carbon and oxygen tracers
+   !!   - addition of air-sea fluxes of CO2 and oxygen
+   !!   - periodic (monthly) calculation of full 3D carbonate chemistry 
+   !!   - detrital C:N ratio now free to evolve dynamically
+   !!   - benthic storage pools
+   !! 
+   !! Opportunity also taken to add functionality:
+   !!   - switch for Liebig Law (= most-limiting) nutrient uptake
+   !!   - switch for accelerated seafloor detritus remineralisation
+   !!   - switch for fast -> slow detritus transfer at seafloor
+   !!   - switch for ballast vs. Martin vs. Henson fast detritus remin.
+   !!   - per GMD referee remarks, xfdfrac3 introduced for grazed PDS
+   !!----------------------------------------------------------------------
+#endif
+   !!
+#if defined key_mocsy
+   !!----------------------------------------------------------------------
+   !! Updates with the addition of MOCSY include:
+   !!   - option to use PML or MOCSY carbonate chemistry (the latter is 
+   !!     preferred)
+   !!   - central calculation of gas transfer velocity, f_kw660; previously
+   !!     this was done separately for CO2 and O2 with predictable results
+   !!   - distribution of f_kw660 to both PML and MOCSY CO2 air-sea flux 
+   !!     calculations and to those for O2 air-sea flux
+   !!   - extra diagnostics included for MOCSY
+   !!----------------------------------------------------------------------
+#endif
+   !!
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_bio_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE trcsed_medusa
+      USE sbc_oce         ! surface forcing
+      USE sbcrnf          ! surface boundary condition: runoff variables
+      USE in_out_manager  ! I/O manager
+# if defined key_iomput
+      USE iom
+      USE trcnam_medusa         ! JPALM 13-11-2015 -- if iom_use for diag
+      !!USE trc_nam_iom_medusa  ! JPALM 13-11-2015 -- if iom_use for diag
+# endif
+# if defined key_roam
+      USE gastransfer
+#  if defined key_mocsy
+      USE mocsy_wrapper
+#  else
+      USE trcco2_medusa
+#  endif
+      USE trcoxy_medusa
+      !! Jpalm (08/08/2014)
+      USE trcdms_medusa
+# endif
+      !! AXY (18/01/12): brought in for benthic timestepping
+      USE trcnam_trp      ! AXY (24/05/2013)
+      USE trdmxl_trc
+      USE trdtrc_oce  ! AXY (24/05/2013)
+
+      !! AXY (30/01/14): necessary to find NaNs on HECTOR
+      USE, INTRINSIC :: ieee_arithmetic 
+
+      !! JPALM (27-06-2016): add lk_oasis for CO2 and DMS coupling with atm
+      USE sbc_oce, ONLY: lk_oasis
+      USE oce,     ONLY: CO2Flux_out_cpl, DMS_out_cpl, PCO2a_in_cpl
+
+      IMPLICIT NONE
+      PRIVATE
+      
+      PUBLIC   trc_bio_medusa    ! called in ???
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_bio_medusa( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_bio  ***
+      !!
+      !! ** Purpose :   compute the now trend due to biogeochemical processes
+      !!              and add it to the general trend of passive tracers equations
+      !!
+      !! ** Method  :   each now biological flux is calculated in function of now
+      !!              concentrations of tracers.
+      !!              depending on the tracer, these fluxes are sources or sinks.
+      !!              the total of the sources and sinks for each tracer
+      !!              is added to the general trend.
+      !!        
+      !!                      tra = tra + zf...tra - zftra...
+      !!                                     |         |
+      !!                                     |         |
+      !!                                  source      sink
+      !!        
+      !!              IF 'key_trc_diabio' defined , the biogeochemical trends
+      !!              for passive tracers are saved for futher diagnostics.
+      !!---------------------------------------------------------------------
+      !!
+      !!
+      !!----------------------------------------------------------------------            
+      !! Variable conventions
+      !!----------------------------------------------------------------------
+      !!
+      !! names: z*** - state variable 
+      !!        f*** - function (or temporary variable used in part of a function)
+      !!        x*** - parameter
+      !!        b*** - right-hand part (sources and sinks)
+      !!        i*** - integer variable (usually used in yes/no flags)
+      !!
+      !! time (integer timestep)
+      INTEGER, INTENT( in ) ::    kt
+      !!
+      !! spatial array indices
+      INTEGER  ::    ji,jj,jk,jn
+      !!
+      !! AXY (27/07/10): add in indices for depth horizons (for sinking flux
+      !!                 and seafloor iron inputs)
+      !! INTEGER  ::    i0100, i0200, i0500, i1000, i1100
+      !!
+      !! model state variables
+      REAL(wp) ::    zchn,zchd,zphn,zphd,zpds,zzmi
+      REAL(wp) ::    zzme,zdet,zdtc,zdin,zsil,zfer
+      REAL(wp) ::    zage
+# if defined key_roam
+      REAL(wp) ::    zdic, zalk, zoxy
+      REAL(wp) ::    ztmp, zsal
+# endif
+# if defined key_mocsy
+      REAL(wp) ::    zpho
+# endif
+      !!
+      !! integrated source and sink terms
+      REAL(wp) ::    b0
+      !! AXY (23/08/13): changed from individual variables for each flux to
+      !!                 an array that holds all fluxes
+      REAL(wp), DIMENSION(jp_medusa) ::    btra
+      !!
+      !! primary production and chl related quantities      
+      REAL(wp)                     ::    fthetan,faln,fchn1,fchn,fjln,fprn,frn
+      REAL(wp)                     ::    fthetad,fald,fchd1,fchd,fjld,fprd,frd
+      !! AXY (23/11/16): add in light-only limitation term (normalised 0-1 range)
+      REAL(wp)                     ::    fjlim_pn, fjlim_pd
+      !! AXY (03/02/11): add in Liebig terms
+      REAL(wp) ::    fpnlim, fpdlim
+      !! AXY (16/07/09): add in Eppley curve functionality
+      REAL(wp) ::    loc_T,fun_T,xvpnT,xvpdT
+      INTEGER  ::    ieppley
+      !! AXY (16/05/11): per Katya's prompting, add in new T-dependence
+      !!                 for phytoplankton growth only (i.e. no change
+      !!                 for remineralisation)
+      REAL(wp) ::    fun_Q10
+      !! AXY (01/03/10): add in mixed layer PP diagnostics
+      REAL(wp), DIMENSION(jpi,jpj) ::  fprn_ml,fprd_ml
+      !!
+      !! nutrient limiting factors
+      REAL(wp) ::    fnln,ffln            !! N and Fe
+      REAL(wp) ::    fnld,ffld,fsld,fsld2 !! N, Fe and Si
+      !!
+      !! silicon cycle
+      REAL(wp) ::    fsin,fnsi,fsin1,fnsi1,fnsi2,fprds,fsdiss
+      !!
+      !! iron cycle; includes parameters for Parekh et al. (2005) iron scheme
+      REAL(wp) ::    ffetop,ffebot,ffescav
+      REAL(wp) ::    xLgF, xFeT, xFeF, xFeL         !! state variables for iron-ligand system
+      REAL(wp), DIMENSION(jpi,jpj) ::  xFree        !! state variables for iron-ligand system
+      REAL(wp) ::    xb_coef_tmp, xb2M4ac           !! iron-ligand parameters
+      REAL(wp) ::    xmaxFeF,fdeltaFe               !! max Fe' parameters
+      !!
+      !! local parameters for Moore et al. (2004) alternative scavenging scheme
+      REAL(wp) ::    fbase_scav,fscal_sink,fscal_part,fscal_scav
+      !!
+      !! local parameters for Moore et al. (2008) alternative scavenging scheme
+      REAL(wp) ::    fscal_csink,fscal_sisink,fscal_casink
+      !!
+      !! local parameters for Galbraith et al. (2010) alternative scavenging scheme
+      REAL(wp) ::    xCscav1, xCscav2, xk_org, xORGscav  !! organic portion of scavenging
+      REAL(wp) ::    xk_inorg, xINORGscav                !! inorganic portion of scavenging
+      !!
+      !! microzooplankton grazing
+      REAL(wp) ::    fmi1,fmi,fgmipn,fgmid,fgmidc
+      REAL(wp) ::    finmi,ficmi,fstarmi,fmith,fmigrow,fmiexcr,fmiresp
+      !!
+      !! mesozooplankton grazing
+      REAL(wp) ::    fme1,fme,fgmepn,fgmepd,fgmepds,fgmezmi,fgmed,fgmedc
+      REAL(wp) ::    finme,ficme,fstarme,fmeth,fmegrow,fmeexcr,fmeresp
+      !!
+      !! mortality/Remineralisation (defunct parameter "fz" removed)
+      REAL(wp) ::    fdpn,fdpd,fdpds,fdzmi,fdzme,fdd
+# if defined key_roam
+      REAL(wp) ::    fddc
+# endif
+      REAL(wp) ::    fdpn2,fdpd2,fdpds2,fdzmi2,fdzme2
+      REAL(wp) ::    fslown, fslowc
+      REAL(wp), DIMENSION(jpi,jpj) ::    fslownflux, fslowcflux
+      REAL(wp) ::    fregen,fregensi
+      REAL(wp), DIMENSION(jpi,jpj) ::    fregenfast,fregenfastsi
+# if defined key_roam
+      REAL(wp) ::    fregenc
+      REAL(wp), DIMENSION(jpi,jpj) ::    fregenfastc
+# endif
+      !!
+      !! particle flux
+      REAL(WP) ::    fthk,fdep,fdep1,fdep2,flat,fcaco3
+      REAL(WP) ::    ftempn,ftempsi,ftempfe,ftempc,ftempca
+      REAL(wp) ::    freminn,freminsi,freminfe,freminc,freminca
+      REAL(wp), DIMENSION(jpi,jpj) ::    ffastn,ffastsi,ffastfe,ffastc,ffastca
+      REAL(wp) ::    fleftn,fleftsi,fleftfe,fleftc,fleftca
+      REAL(wp) ::    fheren,fheresi,fherefe,fherec,fhereca
+      REAL(wp) ::    fprotf
+      REAL(wp), DIMENSION(jpi,jpj) ::    fsedn,fsedsi,fsedfe,fsedc,fsedca
+      REAL(wp), DIMENSION(jpi,jpj) ::    fccd
+      REAL(wp) ::    fccd_dep
+      !! AXY (28/11/16): fix mbathy bug
+      INTEGER  ::    jmbathy
+      !!
+      !! AXY (06/07/11): alternative fast detritus schemes
+      REAL(wp) ::    fb_val, fl_sst
+      !!
+      !! AXY (08/07/11): fate of fast detritus reaching the seafloor
+      REAL(wp) ::    ffast2slown,ffast2slowfe,ffast2slowc
+      !!
+      !! conservation law
+      REAL(wp) ::    fnit0,fsil0,ffer0 
+# if defined key_roam
+      REAL(wp) ::    fcar0,falk0,foxy0 
+# endif      
+      !! 
+      !! temporary variables
+      REAL(wp) ::    fq0,fq1,fq2,fq3,fq4,fq5,fq6,fq7,fq8,fq9
+      !!
+      !! water column nutrient and flux integrals
+      REAL(wp), DIMENSION(jpi,jpj) ::    ftot_n,ftot_si,ftot_fe
+      REAL(wp), DIMENSION(jpi,jpj) ::    fflx_n,fflx_si,fflx_fe
+      REAL(wp), DIMENSION(jpi,jpj) ::    fifd_n,fifd_si,fifd_fe
+      REAL(wp), DIMENSION(jpi,jpj) ::    fofd_n,fofd_si,fofd_fe
+# if defined key_roam
+      REAL(wp), DIMENSION(jpi,jpj) ::    ftot_c,ftot_a,ftot_o2
+      REAL(wp), DIMENSION(jpi,jpj) ::    fflx_c,fflx_a,fflx_o2
+      REAL(wp), DIMENSION(jpi,jpj) ::    fifd_c,fifd_a,fifd_o2
+      REAL(wp), DIMENSION(jpi,jpj) ::    fofd_c,fofd_a,fofd_o2
+# endif
+      !!
+      !! zooplankton grazing integrals
+      REAL(wp), DIMENSION(jpi,jpj) ::    fzmi_i,fzmi_o,fzme_i,fzme_o
+      !!
+      !! limitation term temporary variables
+      REAL(wp), DIMENSION(jpi,jpj) ::    ftot_pn,ftot_pd
+      REAL(wp), DIMENSION(jpi,jpj) ::    ftot_zmi,ftot_zme,ftot_det,ftot_dtc
+      !! use ballast scheme (1) or simple exponential scheme (0; a conservation test)
+      INTEGER  ::    iball
+      !! use biological fluxes (1) or not (0)
+      INTEGER  ::    ibio_switch
+      !!
+      !! diagnose fluxes (should only be used in 1D runs)
+      INTEGER  ::    idf, idfval
+      !!
+      !! nitrogen and silicon production and consumption
+      REAL(wp) ::    fn_prod, fn_cons, fs_prod, fs_cons
+      REAL(wp), DIMENSION(jpi,jpj) ::    fnit_prod, fnit_cons, fsil_prod, fsil_cons
+# if defined key_roam
+      !!
+      !! flags to help with calculating the position of the CCD
+      INTEGER, DIMENSION(jpi,jpj) ::     i2_omcal,i2_omarg
+      !!
+      !! ROAM air-sea flux and diagnostic parameters
+      REAL(wp) ::    f_wind
+      !! AXY (24/11/16): add xCO2 variable for atmosphere (what we actually have)
+      REAL(wp) ::    f_xco2a
+      REAL(wp) ::    f_ph, f_pco2w, f_h2co3, f_hco3, f_co3, f_co2flux
+      REAL(wp) ::    f_TDIC, f_TALK, f_dcf, f_henry
+      REAL(wp) ::    f_uwind, f_vwind, f_pp0
+      REAL(wp) ::    f_kw660, f_o2flux, f_o2sat, f_o2sat3
+      REAL(wp), DIMENSION(jpi,jpj) ::    f_omcal, f_omarg
+      !!
+      !! AXY (23/06/15): additional diagnostics for MOCSY and oxygen
+      REAL(wp) ::    f_fco2w, f_BetaD, f_rhosw, f_opres, f_insitut, f_pco2atm, f_fco2atm
+      REAL(wp) ::    f_schmidtco2, f_kwco2, f_K0, f_co2starair, f_dpco2, f_kwo2
+      !! jpalm 14-07-2016: convert CO2flux diag from mmol/m2/d to kg/m2/s
+      REAL, PARAMETER :: weight_CO2_mol = 44.0095  !! g / mol
+      REAL, PARAMETER :: secs_in_day    = 86400.0  !! s / d
+      REAL, PARAMETER :: CO2flux_conv   = (1.e-6 * weight_CO2_mol) / secs_in_day
+
+      !!
+      INTEGER  ::    iters
+      REAL(wp) ::    f_year
+      INTEGER  ::    i_year
+      INTEGER  ::    iyr1, iyr2
+      !!
+      !! carbon, alkalinity production and consumption
+      REAL(wp) ::    fc_prod, fc_cons, fa_prod, fa_cons
+      REAL(wp), DIMENSION(jpi,jpj) ::    fcomm_resp
+      REAL(wp), DIMENSION(jpi,jpj) ::    fcar_prod, fcar_cons
+      !!
+      !! oxygen production and consumption (and non-consumption)
+      REAL(wp) ::    fo2_prod, fo2_cons, fo2_ncons, fo2_ccons
+      REAL(wp), DIMENSION(jpi,jpj) ::    foxy_prod, foxy_cons, foxy_anox
+      !! Jpalm (11-08-2014)
+      !! add DMS in MEDUSA for UKESM1 model
+      REAL(wp) ::    dms_surf
+      !! AXY (13/03/15): add in other DMS calculations
+      REAL(wp) ::    dms_andr, dms_simo, dms_aran, dms_hall
+
+# endif
+      !! 
+      !! benthic fluxes
+      INTEGER  ::    ibenthic
+      REAL(wp), DIMENSION(jpi,jpj) :: f_sbenin_n, f_sbenin_fe,              f_sbenin_c
+      REAL(wp), DIMENSION(jpi,jpj) :: f_fbenin_n, f_fbenin_fe, f_fbenin_si, f_fbenin_c, f_fbenin_ca
+      REAL(wp), DIMENSION(jpi,jpj) :: f_benout_n, f_benout_fe, f_benout_si, f_benout_c, f_benout_ca
+      REAL(wp) ::    zfact
+      !! 
+      !! benthic fluxes of CaCO3 that shouldn't happen because of lysocline
+      REAL(wp), DIMENSION(jpi,jpj) :: f_benout_lyso_ca
+      !!
+      !! riverine fluxes
+      REAL(wp), DIMENSION(jpi,jpj) :: f_runoff, f_riv_n, f_riv_si, f_riv_c, f_riv_alk
+      !! AXY (19/07/12): variables for local riverine fluxes to handle inputs below surface
+      REAL(wp) ::    f_riv_loc_n, f_riv_loc_si, f_riv_loc_c, f_riv_loc_alk
+      !!
+      !! horizontal grid location
+      REAL(wp) ::    flatx, flonx
+      !!
+      !! Jpalm -- 11-10-2015 -- adapt diag to iom_use
+      !! 2D var for diagnostics.
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fprn2d, fdpn2d, fprd2d, fdpd2d, fprds2d, fsdiss2d, fgmipn2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fgmid2d, fdzmi2d, fgmepn2d, fgmepd2d, fgmezmi2d, fgmed2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fdzme2d, fslown2d, fdd2d, ffetop2d, ffebot2d, ffescav2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fjln2d, fnln2d, ffln2d, fjld2d, fnld2d, ffld2d, fsld2d2
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fsld2d, fregen2d, fregensi2d, ftempn2d, ftempsi2d, ftempfe2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: ftempc2d, ftempca2d, freminn2d, freminsi2d, freminfe2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: freminc2d, freminca2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zw2d
+# if defined key_roam
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: ffastca2d, rivn2d, rivsi2d, rivc2d, rivalk2d, fslowc2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fdpn22d, fdpd22d, fdzmi22d, fdzme22d, zimesn2d, zimesd2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zimesc2d, zimesdc2d, ziexcr2d, ziresp2d, zigrow2d, zemesn2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zemesd2d, zemesc2d, zemesdc2d, zeexcr2d, zeresp2d, zegrow2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: mdetc2d, gmidc2d, gmedc2d, f_pco2a2d, f_pco2w2d, f_co2flux2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: f_TDIC2d, f_TALK2d, f_kw6602d, f_pp02d, f_o2flux2d, f_o2sat2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: dms_andr2d, dms_simo2d, dms_aran2d, dms_hall2d, dms_surf2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: iben_n2d, iben_fe2d, iben_c2d, iben_si2d, iben_ca2d, oben_n2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: oben_fe2d, oben_c2d, oben_si2d, oben_ca2d, sfr_ocal2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: sfr_oarg2d, lyso_ca2d 
+      !! AXY (23/11/16): extra MOCSY diagnostics
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: f_xco2a_2d, f_fco2w_2d, f_fco2a_2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: f_ocnrhosw_2d, f_ocnschco2_2d, f_ocnkwco2_2d
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: f_ocnk0_2d, f_co2starair_2d, f_ocndpco2_2d
+# endif
+      !!
+      !! 3D var for diagnostics.
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: tpp3d, detflux3d, remin3dn
+      !!
+# if defined key_roam
+      !! AXY (04/11/16)
+      !! 2D var for new CMIP6 diagnostics (behind a key_roam ifdef for simplicity)
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fgco2, intdissic, intdissin, intdissisi, inttalk, o2min, zo2min
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: fbddtalk, fbddtdic, fbddtdife, fbddtdin, fbddtdisi
+      !!
+      !! 3D var for new CMIP6 diagnostics
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: tppd3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: bddtalk3, bddtdic3, bddtdife3, bddtdin3, bddtdisi3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: fd_nit3, fd_sil3, fd_car3, fd_cal3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: co33, co3satarag3, co3satcalc3, dcalc3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: expc3, expn3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: fediss3, fescav3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: migrazp3, migrazd3, megrazp3, megrazd3, megrazz3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: o2sat3, pbsi3, pcal3, remoc3
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: pnlimj3, pnlimn3, pnlimfe3, pdlimj3, pdlimn3, pdlimfe3, pdlimsi3
+# endif
+      !!---------------------------------------------------------------------
+
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) 'trc_bio_medusa: variables defined'
+      CALL flush(numout)
+# endif 
+
+      !! AXY (20/11/14): alter this to report on first MEDUSA call
+      !! IF( kt == nit000 ) THEN
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_bio: MEDUSA bio-model'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+	 IF(lwp) WRITE(numout,*) ' kt =',kt
+      ENDIF
+
+      !! AXY (13/01/12): is benthic model properly interactive? 0 = no, 1 = yes
+      ibenthic = 1
+
+      !! not sure what this is for; it's not used anywhere; commenting out
+      !! fbodn(:,:) = 0.e0   
+
+      !!
+      IF( ln_diatrc ) THEN
+         !! blank 2D diagnostic array
+         trc2d(:,:,:) = 0.e0
+         !!
+         !! blank 3D diagnostic array
+         trc3d(:,:,:,:) = 0.e0
+      ENDIF
+
+      !!----------------------------------------------------------------------
+      !! b0 is present for debugging purposes; using b0 = 0 sets the tendency
+      !! terms of all biological equations to 0.
+      !!----------------------------------------------------------------------
+      !!
+      !! AXY (03/09/14): probably not the smartest move ever, but it'll fit
+      !!                 the bill for now; another item on the things-to-sort-
+      !!		 out-in-the-future list ...
+# if defined key_kill_medusa
+      b0 = 0.
+# else
+      b0 = 1.
+# endif
+      !!----------------------------------------------------------------------
+      !! fast detritus ballast scheme (0 = no; 1 = yes)
+      !! alternative to ballast scheme is same scheme but with no ballast
+      !! protection (not dissimilar to Martin et al., 1987)
+      !!----------------------------------------------------------------------
+      !!
+      iball = 1
+
+      !!----------------------------------------------------------------------
+      !! full flux diagnostics (0 = no; 1 = yes); appear in ocean.output
+      !! these should *only* be used in 1D since they give comprehensive
+      !! output for ecological functions in the model; primarily used in
+      !! debugging
+      !!----------------------------------------------------------------------
+      !!
+      idf    = 0
+      !!
+      !! timer mechanism
+      if (kt/120*120.eq.kt) then
+         idfval = 1
+      else
+         idfval = 0
+      endif
+
+      !!----------------------------------------------------------------------
+      !! blank fast-sinking detritus 2D fields
+      !!----------------------------------------------------------------------
+      !!
+      ffastn(:,:)  = 0.0        !! organic nitrogen
+      ffastsi(:,:) = 0.0        !! biogenic silicon
+      ffastfe(:,:) = 0.0        !! organic iron
+      ffastc(:,:)  = 0.0        !! organic carbon
+      ffastca(:,:) = 0.0        !! biogenic calcium carbonate
+      !!
+      fsedn(:,:)   = 0.0        !! Seafloor flux of N 
+      fsedsi(:,:)  = 0.0        !! Seafloor flux of Si
+      fsedfe(:,:)  = 0.0        !! Seafloor flux of Fe
+      fsedc(:,:)   = 0.0        !! Seafloor flux of C
+      fsedca(:,:)  = 0.0        !! Seafloor flux of CaCO3
+      !!
+      fregenfast(:,:)   = 0.0   !! integrated  N regeneration (fast detritus)
+      fregenfastsi(:,:) = 0.0   !! integrated Si regeneration (fast detritus)
+# if defined key_roam
+      fregenfastc(:,:)  = 0.0   !! integrated  C regeneration (fast detritus)
+# endif
+      !!
+      fccd(:,:)    = 0.0        !! last depth level before CCD
+
+      !!----------------------------------------------------------------------
+      !! blank nutrient/flux inventories
+      !!----------------------------------------------------------------------
+      !!
+      fflx_n(:,:)  = 0.0        !! nitrogen flux total
+      fflx_si(:,:) = 0.0        !! silicon  flux total
+      fflx_fe(:,:) = 0.0        !! iron     flux total
+      fifd_n(:,:)  = 0.0        !! nitrogen fast detritus production
+      fifd_si(:,:) = 0.0        !! silicon  fast detritus production
+      fifd_fe(:,:) = 0.0        !! iron     fast detritus production
+      fofd_n(:,:)  = 0.0        !! nitrogen fast detritus remineralisation
+      fofd_si(:,:) = 0.0        !! silicon  fast detritus remineralisation
+      fofd_fe(:,:) = 0.0        !! iron     fast detritus remineralisation
+# if defined key_roam
+      fflx_c(:,:)  = 0.0        !! carbon     flux total
+      fflx_a(:,:)  = 0.0        !! alkalinity flux total
+      fflx_o2(:,:) = 0.0        !! oxygen     flux total
+      ftot_c(:,:)  = 0.0        !! carbon     inventory
+      ftot_a(:,:)  = 0.0        !! alkalinity inventory
+      ftot_o2(:,:) = 0.0        !! oxygen     inventory
+      fifd_c(:,:)  = 0.0        !! carbon     fast detritus production
+      fifd_a(:,:)  = 0.0        !! alkalinity fast detritus production
+      fifd_o2(:,:) = 0.0        !! oxygen     fast detritus production
+      fofd_c(:,:)  = 0.0        !! carbon     fast detritus remineralisation
+      fofd_a(:,:)  = 0.0        !! alkalinity fast detritus remineralisation
+      fofd_o2(:,:) = 0.0        !! oxygen     fast detritus remineralisation
+      !!
+      fnit_prod(:,:) = 0.0      !! (organic)   nitrogen production
+      fnit_cons(:,:) = 0.0      !! (organic)   nitrogen consumption
+      fsil_prod(:,:) = 0.0      !! (inorganic) silicon production
+      fsil_cons(:,:) = 0.0      !! (inorganic) silicon consumption
+      fcar_prod(:,:) = 0.0      !! (organic)   carbon production
+      fcar_cons(:,:) = 0.0      !! (organic)   carbon consumption
+      !!
+      foxy_prod(:,:) = 0.0      !! oxygen production
+      foxy_cons(:,:) = 0.0      !! oxygen consumption
+      foxy_anox(:,:) = 0.0      !! unrealised oxygen consumption
+# endif
+      ftot_n(:,:)   = 0.0       !! N inventory 
+      ftot_si(:,:)  = 0.0       !! Si inventory
+      ftot_fe(:,:)  = 0.0       !! Fe inventory
+      ftot_pn(:,:)  = 0.0       !! integrated non-diatom phytoplankton
+      ftot_pd(:,:)  = 0.0       !! integrated diatom     phytoplankton
+      ftot_zmi(:,:) = 0.0       !! integrated microzooplankton
+      ftot_zme(:,:) = 0.0       !! integrated mesozooplankton
+      ftot_det(:,:) = 0.0       !! integrated slow detritus, nitrogen
+      ftot_dtc(:,:) = 0.0       !! integrated slow detritus, carbon
+      !!
+      fzmi_i(:,:)  = 0.0        !! material grazed by microzooplankton
+      fzmi_o(:,:)  = 0.0        !! ... sum of fate of this material
+      fzme_i(:,:)  = 0.0        !! material grazed by  mesozooplankton
+      fzme_o(:,:)  = 0.0        !! ... sum of fate of this material
+      !!
+      f_sbenin_n(:,:)  = 0.0    !! slow detritus N  -> benthic pool
+      f_sbenin_fe(:,:) = 0.0    !! slow detritus Fe -> benthic pool
+      f_sbenin_c(:,:)  = 0.0    !! slow detritus C  -> benthic pool
+      f_fbenin_n(:,:)  = 0.0    !! fast detritus N  -> benthic pool
+      f_fbenin_fe(:,:) = 0.0    !! fast detritus Fe -> benthic pool
+      f_fbenin_si(:,:) = 0.0    !! fast detritus Si -> benthic pool
+      f_fbenin_c(:,:)  = 0.0    !! fast detritus C  -> benthic pool
+      f_fbenin_ca(:,:) = 0.0    !! fast detritus Ca -> benthic pool
+      !!
+      f_benout_n(:,:)  = 0.0    !! benthic N  pool  -> dissolved
+      f_benout_fe(:,:) = 0.0    !! benthic Fe pool  -> dissolved
+      f_benout_si(:,:) = 0.0    !! benthic Si pool  -> dissolved
+      f_benout_c(:,:)  = 0.0    !! benthic C  pool  -> dissolved
+      f_benout_ca(:,:) = 0.0    !! benthic Ca pool  -> dissolved
+      !!
+      f_benout_lyso_ca(:,:) = 0.0 !! benthic Ca pool  -> dissolved (when it shouldn't!)
+      !!
+      f_runoff(:,:)  = 0.0      !! riverine runoff
+      f_riv_n(:,:)   = 0.0      !! riverine N   input 
+      f_riv_si(:,:)  = 0.0      !! riverine Si  input 
+      f_riv_c(:,:)   = 0.0      !! riverine C   input 
+      f_riv_alk(:,:) = 0.0      !! riverine alk input 
+      !!
+      !! allocate and initiate 2D diag
+      !! -----------------------------
+      !! Juju :: add kt condition !!
+      IF ( lk_iomput .AND. .NOT.  ln_diatrc ) THEN 
+         !!
+         if ( kt == nittrc000 )   CALL trc_nam_iom_medusa !! initialise iom_use test
+         !!
+         CALL wrk_alloc( jpi, jpj,      zw2d )
+         zw2d(:,:)      = 0.0   !!
+         IF ( med_diag%PRN%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fprn2d    )
+            fprn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF ( med_diag%MPN%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fdpn2d    )
+            fdpn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF ( med_diag%PRD%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fprd2d    )
+            fprd2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%MPD%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fdpd2d    )
+            fdpd2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OPAL%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fprds2d    )
+            fprds2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OPALDISS%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fsdiss2d    )
+            fsdiss2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMIPn%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fgmipn2d    )
+            fgmipn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMID%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fgmid2d    )
+            fgmid2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%MZMI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fdzmi2d    )
+            fdzmi2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMEPN%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fgmepn2d    )
+            fgmepn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMEPD%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fgmepd2d    )
+            fgmepd2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMEZMI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fgmezmi2d    )
+            fgmezmi2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMED%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fgmed2d    )
+            fgmed2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%MZME%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fdzme2d    )
+            fdzme2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%DETN%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fslown2d    )
+            fslown2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%MDET%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fdd2d    )
+            fdd2d(:,:)      = 0.0 !!
+         ENDIF      
+         IF( med_diag%AEOLIAN%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   ffetop2d    )
+            ffetop2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%BENTHIC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    ffebot2d   )
+            ffebot2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%SCAVENGE%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   ffescav2d    )
+            ffescav2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PN_JLIM%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fjln2d    )
+            fjln2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PN_NLIM%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fnln2d    )
+            fnln2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PN_FELIM%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   ffln2d    )
+            ffln2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PD_JLIM%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fjld2d    )
+            fjld2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PD_NLIM%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fnld2d    )
+            fnld2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PD_FELIM%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   ffld2d    )
+            ffld2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PD_SILIM%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fsld2d2    )
+            fsld2d2(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PDSILIM2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fsld2d    )
+            fsld2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip SDT_XXXX diagnostics here
+!!
+         IF( med_diag%TOTREG_N%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fregen2d    )
+            fregen2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%TOTRG_SI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fregensi2d    )
+            fregensi2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip REG_XXXX diagnostics here
+!!
+         IF( med_diag%FASTN%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   ftempn2d    )
+            ftempn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%FASTSI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   ftempsi2d    )
+            ftempsi2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%FASTFE%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,  ftempfe2d     )
+            ftempfe2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%FASTC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,  ftempc2d     )
+            ftempc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%FASTCA%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   ftempca2d    )
+            ftempca2d(:,:)      = 0.0 !!
+         ENDIF     
+!!
+!! skip FDT_XXXX, RG_XXXXF, FDS_XXXX, RGSXXXXF diagnostics here
+!!
+         IF( med_diag%REMINN%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    freminn2d   )
+            freminn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%REMINSI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    freminsi2d   )
+            freminsi2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%REMINFE%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    freminfe2d   )
+            freminfe2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%REMINC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   freminc2d    )
+            freminc2d(:,:)      = 0.0 !! 
+         ENDIF
+         IF( med_diag%REMINCA%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   freminca2d    )
+            freminca2d(:,:)      = 0.0 !!
+         ENDIF
+# if defined key_roam
+!!
+!! skip SEAFLRXX, MED_XXXX, INTFLX_XX, INT_XX, ML_XXX, OCAL_XXX, FE_XXXX, MED_XZE, WIND diagnostics here
+!!
+         IF( med_diag%RR_0100%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    ffastca2d   )
+            ffastca2d(:,:)      = 0.0 !!
+         ENDIF
+
+         IF( med_diag%ATM_PCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    f_pco2a2d   )
+            f_pco2a2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip OCN_PH diagnostic here
+!!
+         IF( med_diag%OCN_PCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    f_pco2w2d   )
+            f_pco2w2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip OCNH2CO3, OCN_HCO3, OCN_CO3 diagnostics here
+!!
+         IF( med_diag%CO2FLUX%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   f_co2flux2d    )
+            f_co2flux2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip OM_XXX diagnostics here
+!!
+         IF( med_diag%TCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   f_TDIC2d    )
+            f_TDIC2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%TALK%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    f_TALK2d   )
+            f_TALK2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%KW660%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    f_kw6602d   )
+            f_kw6602d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ATM_PP0%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    f_pp02d   )
+            f_pp02d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%O2FLUX%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   f_o2flux2d    )
+            f_o2flux2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%O2SAT%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    f_o2sat2d   )
+            f_o2sat2d(:,:)      = 0.0 !!
+         ENDIF 
+!!
+!! skip XXX_CCD diagnostics here
+!! 
+         IF( med_diag%SFR_OCAL%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    sfr_ocal2d  )
+            sfr_ocal2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%SFR_OARG%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    sfr_oarg2d  )
+            sfr_oarg2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip XX_PROD, XX_CONS, O2_ANOX, RR_XXXX diagnostics here
+!! 
+         IF( med_diag%IBEN_N%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    iben_n2d  )
+            iben_n2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%IBEN_FE%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   iben_fe2d   )
+            iben_fe2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%IBEN_C%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   iben_c2d   )
+            iben_c2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%IBEN_SI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   iben_si2d   )
+            iben_si2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%IBEN_CA%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   iben_ca2d   )
+            iben_ca2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OBEN_N%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    oben_n2d  )
+            oben_n2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OBEN_FE%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    oben_fe2d  )
+            oben_fe2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OBEN_C%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    oben_c2d  )
+            oben_c2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OBEN_SI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    oben_si2d  )
+            oben_si2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OBEN_CA%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    oben_ca2d  )
+            oben_ca2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip BEN_XX diagnostics here
+!!
+         IF( med_diag%RIV_N%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    rivn2d   )
+            rivn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%RIV_SI%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    rivsi2d   )
+            rivsi2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%RIV_C%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   rivc2d    )
+            rivc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%RIV_ALK%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    rivalk2d   )
+            rivalk2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%DETC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    fslowc2d   )
+            fslowc2d(:,:)      = 0.0 !!
+         ENDIF 
+!!
+!! skip SDC_XXXX, INVTXXX diagnostics here
+!!
+         IF( med_diag%LYSO_CA%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    lyso_ca2d  )
+            lyso_ca2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip COM_RESP diagnostic here
+!!
+         IF( med_diag%PN_LLOSS%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    fdpn22d   )
+            fdpn22d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%PD_LLOSS%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    fdpd22d   )
+            fdpd22d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_LLOSS%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    fdzmi22d   )
+            fdzmi22d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZE_LLOSS%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   fdzme22d    )
+            fdzme22d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_MES_N%dgsave ) THEN   
+            CALL wrk_alloc( jpi, jpj,   zimesn2d    )
+            zimesn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_MES_D%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zimesd2d   )
+            zimesd2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_MES_C%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zimesc2d   )
+            zimesc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_MESDC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zimesdc2d   )
+            zimesdc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_EXCR%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,     ziexcr2d  )
+            ziexcr2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_RESP%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    ziresp2d   )
+            ziresp2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZI_GROW%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zigrow2d   )
+            zigrow2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZE_MES_N%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   zemesn2d    )
+            zemesn2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZE_MES_D%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zemesd2d   )
+            zemesd2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZE_MES_C%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zemesc2d   )
+            zemesc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZE_MESDC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zemesdc2d   )
+            zemesdc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZE_EXCR%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zeexcr2d   )
+            zeexcr2d(:,:)      = 0.0 !!
+         ENDIF                  
+         IF( med_diag%ZE_RESP%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zeresp2d   )
+            zeresp2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ZE_GROW%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    zegrow2d   )
+            zegrow2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%MDETC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,   mdetc2d    )
+            mdetc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMIDC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    gmidc2d   )
+            gmidc2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%GMEDC%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj,    gmedc2d   )
+            gmedc2d(:,:)      = 0.0 !!
+         ENDIF
+!!
+!! skip INT_XXX diagnostics here
+!!
+         IF (jdms .eq. 1) THEN
+            IF( med_diag%DMS_SURF%dgsave ) THEN
+               CALL wrk_alloc( jpi, jpj,   dms_surf2d    )
+               dms_surf2d(:,:)      = 0.0 !!
+            ENDIF
+            IF( med_diag%DMS_ANDR%dgsave ) THEN
+               CALL wrk_alloc( jpi, jpj,   dms_andr2d    )
+               dms_andr2d(:,:)      = 0.0 !!
+            ENDIF
+            IF( med_diag%DMS_SIMO%dgsave ) THEN
+               CALL wrk_alloc( jpi, jpj,  dms_simo2d     )
+               dms_simo2d(:,:)      = 0.0 !!
+            ENDIF
+            IF( med_diag%DMS_ARAN%dgsave ) THEN
+               CALL wrk_alloc( jpi, jpj,   dms_aran2d    )
+               dms_aran2d(:,:)      = 0.0 !!
+            ENDIF
+            IF( med_diag%DMS_HALL%dgsave ) THEN
+               CALL wrk_alloc( jpi, jpj,   dms_hall2d    )
+               dms_hall2d(:,:)      = 0.0 !!
+            ENDIF
+         ENDIF   
+         !!
+         !! AXY (24/11/16): extra MOCSY diagnostics, 2D
+         IF( med_diag%ATM_XCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_xco2a_2d      )
+            f_xco2a_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OCN_FCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_fco2w_2d      )
+            f_fco2w_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%ATM_FCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_fco2a_2d      )
+            f_fco2a_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OCN_RHOSW%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_ocnrhosw_2d   )
+            f_ocnrhosw_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OCN_SCHCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_ocnschco2_2d  )
+            f_ocnschco2_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OCN_KWCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_ocnkwco2_2d   )
+            f_ocnkwco2_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OCN_K0%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_ocnk0_2d      )
+            f_ocnk0_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%CO2STARAIR%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_co2starair_2d )
+            f_co2starair_2d(:,:)      = 0.0 !!
+         ENDIF
+         IF( med_diag%OCN_DPCO2%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, f_ocndpco2_2d   )
+            f_ocndpco2_2d(:,:)      = 0.0 !!
+         ENDIF
+# endif  
+         IF( med_diag%TPP3%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, jpk,       tpp3d )
+            tpp3d(:,:,:)      = 0.0 !! 
+         ENDIF
+         IF( med_diag%DETFLUX3%dgsave ) THEN
+            CALL wrk_alloc( jpi, jpj, jpk,        detflux3d )
+            detflux3d(:,:,:)      = 0.0 !! 
+         ENDIF
+         IF( med_diag%REMIN3N%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk,        remin3dn )
+             remin3dn(:,:,:)      = 0.0 !! 
+          ENDIF
+          !! 
+          !! AXY (10/11/16): CMIP6 diagnostics, 2D
+          !! JPALM -- 17-11-16 -- put fgco2 alloc out of diag request
+          !!                   needed for coupling/passed through restart
+          !! IF( med_diag%FGCO2%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj,   fgco2    )
+             fgco2(:,:)      = 0.0 !!
+          !! ENDIF
+          IF( med_diag%INTDISSIC%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj,   intdissic    )
+             intdissic(:,:)  = 0.0 !!
+          ENDIF          
+          IF( med_diag%INTDISSIN%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj,   intdissin    )
+             intdissin(:,:)  = 0.0 !!
+          ENDIF          
+          IF( med_diag%INTDISSISI%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj,   intdissisi    )
+             intdissisi(:,:)  = 0.0 !!
+          ENDIF          
+          IF( med_diag%INTTALK%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj,   inttalk    )
+             inttalk(:,:)  = 0.0 !!
+          ENDIF          
+          IF( med_diag%O2min%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj,   o2min    )
+             o2min(:,:)  = 1.e3 !! set to high value as we're looking for min(o2)
+          ENDIF          
+          IF( med_diag%ZO2min%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj,   zo2min    )
+             zo2min(:,:)  = 0.0 !!
+          ENDIF          
+          IF( med_diag%FBDDTALK%dgsave  ) THEN
+             CALL wrk_alloc( jpi, jpj, fbddtalk  )
+             fbddtalk(:,:)  = 0.0 !! 
+          ENDIF
+          IF( med_diag%FBDDTDIC%dgsave  ) THEN
+             CALL wrk_alloc( jpi, jpj, fbddtdic  )
+             fbddtdic(:,:)  = 0.0 !! 
+          ENDIF
+          IF( med_diag%FBDDTDIFE%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj, fbddtdife )
+             fbddtdife(:,:) = 0.0 !! 
+          ENDIF
+          IF( med_diag%FBDDTDIN%dgsave  ) THEN
+             CALL wrk_alloc( jpi, jpj, fbddtdin  )
+             fbddtdin(:,:)  = 0.0 !! 
+          ENDIF
+          IF( med_diag%FBDDTDISI%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj, fbddtdisi )
+             fbddtdisi(:,:) = 0.0 !! 
+          ENDIF
+          !! 
+          !! AXY (10/11/16): CMIP6 diagnostics, 3D
+          IF( med_diag%TPPD3%dgsave     ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, tppd3     )
+             tppd3(:,:,:)     = 0.0 !! 
+          ENDIF
+          IF( med_diag%BDDTALK3%dgsave  ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, bddtalk3  )
+             bddtalk3(:,:,:)  = 0.0 !! 
+          ENDIF
+          IF( med_diag%BDDTDIC3%dgsave  ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, bddtdic3  )
+             bddtdic3(:,:,:)  = 0.0 !! 
+          ENDIF
+          IF( med_diag%BDDTDIFE3%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, bddtdife3 )
+             bddtdife3(:,:,:) = 0.0 !! 
+          ENDIF
+          IF( med_diag%BDDTDIN3%dgsave  ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, bddtdin3  )
+             bddtdin3(:,:,:)  = 0.0 !! 
+          ENDIF
+          IF( med_diag%BDDTDISI3%dgsave ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, bddtdisi3 )
+             bddtdisi3(:,:,:) = 0.0 !! 
+          ENDIF
+          IF( med_diag%FD_NIT3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, fd_nit3   )
+             fd_nit3(:,:,:)   = 0.0 !! 
+          ENDIF
+          IF( med_diag%FD_SIL3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, fd_sil3   )
+             fd_sil3(:,:,:)   = 0.0 !! 
+          ENDIF
+          IF( med_diag%FD_CAR3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, fd_car3   )
+             fd_car3(:,:,:)   = 0.0 !! 
+          ENDIF
+          IF( med_diag%FD_CAL3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, fd_cal3   )
+             fd_cal3(:,:,:)   = 0.0 !! 
+          ENDIF
+          IF( med_diag%DCALC3%dgsave    ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, dcalc3    )
+             dcalc3(:,:,: )   = 0.0 !! 
+          ENDIF
+          IF( med_diag%EXPC3%dgsave     ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, expc3   )
+             expc3(:,:,: )    = 0.0 !! 
+          ENDIF
+          IF( med_diag%EXPN3%dgsave     ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, expn3   )
+             expn3(:,:,: )    = 0.0 !! 
+          ENDIF
+          IF( med_diag%FEDISS3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, fediss3   )
+             fediss3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%FESCAV3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, fescav3   )
+             fescav3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%MIGRAZP3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, migrazp3  )
+             migrazp3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%MIGRAZD3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, migrazd3  )
+             migrazd3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%MEGRAZP3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, megrazp3  )
+             megrazp3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%MEGRAZD3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, megrazd3  )
+             megrazd3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%MEGRAZZ3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, megrazz3  )
+             megrazz3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%O2SAT3%dgsave     ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, o2sat3    )
+             o2sat3(:,:,: )    = 0.0 !! 
+          ENDIF
+          IF( med_diag%PBSI3%dgsave      ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pbsi3     )
+             pbsi3(:,:,: )     = 0.0 !! 
+          ENDIF
+          IF( med_diag%PCAL3%dgsave      ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pcal3     )
+             pcal3(:,:,: )     = 0.0 !! 
+          ENDIF
+          IF( med_diag%REMOC3%dgsave     ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, remoc3    )
+             remoc3(:,:,: )    = 0.0 !! 
+          ENDIF
+          IF( med_diag%PNLIMJ3%dgsave    ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pnlimj3   )
+             pnlimj3(:,:,: )   = 0.0 !! 
+          ENDIF
+          IF( med_diag%PNLIMN3%dgsave    ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pnlimn3   )
+             pnlimn3(:,:,: )   = 0.0 !! 
+          ENDIF
+          IF( med_diag%PNLIMFE3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pnlimfe3  )
+             pnlimfe3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%PDLIMJ3%dgsave    ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pdlimj3   )
+             pdlimj3(:,:,: )   = 0.0 !! 
+          ENDIF
+          IF( med_diag%PDLIMN3%dgsave    ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pdlimn3   )
+             pdlimn3(:,:,: )   = 0.0 !! 
+          ENDIF
+          IF( med_diag%PDLIMFE3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pdlimfe3  )
+             pdlimfe3(:,:,: )  = 0.0 !! 
+          ENDIF
+          IF( med_diag%PDLIMSI3%dgsave   ) THEN
+             CALL wrk_alloc( jpi, jpj, jpk, pdlimsi3  )
+             pdlimsi3(:,:,: )  = 0.0 !! 
+          ENDIF
+
+       ENDIF
+       !! lk_iomput                                   
+       !!
+# if defined key_axy_nancheck
+       DO jn = 1,jptra
+          !! fq0 = MINVAL(trn(:,:,:,jn))
+          !! fq1 = MAXVAL(trn(:,:,:,jn))
+          fq2 = SUM(trn(:,:,:,jn))
+          !! if (lwp) write (numout,'(a,2i6,3(1x,1pe15.5))') 'NAN-CHECK', &
+          !! &        kt, jn, fq0, fq1, fq2
+          !! AXY (30/01/14): much to our surprise, the next line doesn't work on HECTOR
+          !!                 and has been replaced here with a specialist routine
+          !! if (fq2 /= fq2 ) then
+          if ( ieee_is_nan( fq2 ) ) then
+             !! there's a NaN here
+             if (lwp) write(numout,*) 'NAN detected in field', jn, 'at time', kt, 'at position:'
+             DO jk = 1,jpk
+                DO jj = 1,jpj
+                   DO ji = 1,jpi
+                      !! AXY (30/01/14): "isnan" problem on HECTOR
+                      !! if (trn(ji,jj,jk,jn) /= trn(ji,jj,jk,jn)) then
+                      if ( ieee_is_nan( trn(ji,jj,jk,jn) ) ) then
+                         if (lwp) write (numout,'(a,1pe12.2,4i6)') 'NAN-CHECK', &
+                         &        tmask(ji,jj,jk), ji, jj, jk, jn
+                      endif
+                   enddo
+                enddo
+             enddo
+             CALL ctl_stop( 'trcbio_medusa, NAN in incoming tracer field' )
+          endif
+       ENDDO
+       CALL flush(numout)
+# endif
+
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) 'trc_bio_medusa: variables initialised and checked'
+      CALL flush(numout)
+# endif 
+
+# if defined key_roam
+      !!----------------------------------------------------------------------
+      !! calculate atmospheric pCO2
+      !!----------------------------------------------------------------------
+      !!
+      !! what's atmospheric pCO2 doing? (data start in 1859)
+      iyr1  = nyear - 1859 + 1
+      iyr2  = iyr1 + 1
+      if (iyr1 .le. 1) then
+         !! before 1860
+         f_xco2a = hist_pco2(1)
+      elseif (iyr2 .ge. 242) then
+         !! after 2099
+         f_xco2a = hist_pco2(242)
+      else
+         !! just right
+         fq0 = hist_pco2(iyr1)
+         fq1 = hist_pco2(iyr2)
+         fq2 = real(nsec_day) / (60.0 * 60.0 * 24.0)
+         !! AXY (14/06/12): tweaked to make more sense (and be correct)
+#  if defined key_bs_axy_yrlen
+         fq3 = (real(nday_year) - 1.0 + fq2) / 360.0  !! bugfix: for 360d year with HadGEM2-ES forcing
+#  else
+         fq3 = (real(nday_year) - 1.0 + fq2) / 365.0  !! original use of 365 days (not accounting for leap year or 360d year)
+#  endif
+         fq4 = (fq0 * (1.0 - fq3)) + (fq1 * fq3)
+         f_xco2a = fq4
+      endif
+#  if defined key_axy_pi_co2
+      f_xco2a = 284.725          !! OCMIP pre-industrial pCO2
+#  endif
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA nyear     =', nyear
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA nsec_day  =', real(nsec_day)
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA nday_year =', real(nday_year)
+      !! AXY (29/01/14): remove surplus diagnostics
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq0       =', fq0
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq1       =', fq1
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq2       =', fq2
+      !! IF(lwp) WRITE(numout,*) ' MEDUSA fq3       =', fq3
+      IF(lwp) WRITE(numout,*) ' MEDUSA atm pCO2  =', f_xco2a
+# endif
+
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) 'trc_bio_medusa: ready for carbonate chemistry'
+      IF (lwp) write (numout,*) 'trc_bio_medusa: kt = ', kt
+      IF (lwp) write (numout,*) 'trc_bio_medusa: nittrc000 = ', nittrc000
+      CALL flush(numout)
+# endif 
+
+# if defined key_roam
+      !! AXY (20/11/14): alter to call on first MEDUSA timestep and then every
+      !!                 month (this is hardwired as 960 timesteps but should
+      !!                 be calculated and done properly
+      !! IF( kt == nit000 .or. mod(kt,1920) == 0 ) THEN
+      !! IF( kt == nittrc000 .or. mod(kt,960) == 0 ) THEN 
+      !!=============================
+      !! Jpalm -- 07-10-2016 -- need to change carb-chem frequency call :
+      !!          we don't want to call on the first time-step of all run submission, 
+      !!          but only on the very first time-step, and then every month
+      !!          So we call on nittrc000 if not restarted run, 
+      !!          else if one month after last call.
+      !!          assume one month is 30d --> 3600*24*30 : 2592000s
+      !!          try to call carb-chem at 1st month's tm-stp : x * 30d + 1*rdt(i.e: mod = rdt)   
+      !!          ++ need to pass carb-chem output var through restarts
+      If ( ( kt == nittrc000 .AND. .NOT.ln_rsttr ) .OR. mod(kt*rdt,2592000.) == rdt ) THEN
+         !!----------------------------------------------------------------------
+         !! Calculate the carbonate chemistry for the whole ocean on the first
+         !! simulation timestep and every month subsequently; the resulting 3D
+         !! field of omega calcite is used to determine the depth of the CCD
+         !!----------------------------------------------------------------------
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA calculating all carbonate chemistry at kt =', kt
+         CALL flush(numout)
+         !! blank flags
+         i2_omcal(:,:) = 0
+         i2_omarg(:,:) = 0
+         !! loop over 3D space
+         DO jk = 1,jpk
+            DO jj = 2,jpjm1
+               DO ji = 2,jpim1
+                  !! OPEN wet point IF..THEN loop
+                  if (tmask(ji,jj,jk).eq.1) then
+                     IF (lk_oasis) THEN
+                        f_xco2a = PCO2a_in_cpl(ji,jj)        !! use 2D atm xCO2 from atm coupling
+                     ENDIF
+                     !! do carbonate chemistry
+                     !!
+                     fdep2 = fsdept(ji,jj,jk)           !! set up level midpoint
+                     !! AXY (28/11/16): local seafloor depth
+                     !!                 previously mbathy(ji,jj) - 1, now mbathy(ji,jj)
+                     jmbathy = mbathy(ji,jj)
+                     !!
+                     !! set up required state variables
+                     zdic = max(0.,trn(ji,jj,jk,jpdic)) !! dissolved inorganic carbon
+                     zalk = max(0.,trn(ji,jj,jk,jpalk)) !! alkalinity
+                     ztmp = tsn(ji,jj,jk,jp_tem)        !! temperature
+                     zsal = tsn(ji,jj,jk,jp_sal)        !! salinity
+#  if defined key_mocsy
+                     zsil = max(0.,trn(ji,jj,jk,jpsil))        !! silicic acid
+                     zpho = max(0.,trn(ji,jj,jk,jpdin)) / 16.0 !! phosphate via DIN and Redfield
+#  endif
+		     !!
+		     !! AXY (28/02/14): check input fields
+		     if (ztmp .lt. -3.0 .or. ztmp .gt. 40.0 ) then
+                        IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T WARNING 3D, ', &
+                        tsb(ji,jj,jk,jp_tem), tsn(ji,jj,jk,jp_tem), ' at (',    &
+                        ji, ',', jj, ',', jk, ') at time', kt
+			IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T SWITCHING 3D, ', &
+			tsn(ji,jj,jk,jp_tem), ' -> ', tsb(ji,jj,jk,jp_tem)
+                        ztmp = tsb(ji,jj,jk,jp_tem)     !! temperature
+                     endif
+		     if (zsal .lt. 0.0 .or. zsal .gt. 45.0 ) then
+                        IF(lwp) WRITE(numout,*) ' trc_bio_medusa: S WARNING 3D, ', &
+                        tsb(ji,jj,jk,jp_sal), tsn(ji,jj,jk,jp_sal), ' at (',    &
+                        ji, ',', jj, ',', jk, ') at time', kt
+                     endif
+                     !!
+                     !! blank input variables not used at this stage (they relate to air-sea flux)
+                     f_kw660 = 1.0
+                     f_pp0   = 1.0
+                     !!
+                     !! calculate carbonate chemistry at grid cell midpoint
+#  if defined key_mocsy
+                     !! AXY (22/06/15): use Orr & Epitalon (2015) MOCSY-2 carbonate
+                     !!                 chemistry package
+                     CALL mocsy_interface( ztmp, zsal, zalk, zdic, zsil, zpho,         &    ! inputs
+                     f_pp0, fdep2, flatx, f_kw660, f_xco2a, 1,                         &    ! inputs
+                     f_ph, f_pco2w, f_fco2w, f_h2co3, f_hco3, f_co3, f_omarg(ji,jj),   &    ! outputs
+                     f_omcal(ji,jj), f_BetaD, f_rhosw, f_opres, f_insitut,             &    ! outputs
+                     f_pco2atm, f_fco2atm, f_schmidtco2, f_kwco2, f_K0,                &    ! outputs
+                     f_co2starair, f_co2flux, f_dpco2 )                                     ! outputs
+                     !!
+                     f_TDIC = (zdic / f_rhosw) * 1000. ! mmol / m3 -> umol / kg
+                     f_TALK = (zalk / f_rhosw) * 1000. !  meq / m3 ->  ueq / kg
+                     f_dcf  = f_rhosw
+#  else
+                     !! AXY (22/06/15): use old PML carbonate chemistry package (the
+                     !!                 MEDUSA-2 default)
+                     CALL trc_co2_medusa( ztmp, zsal, zdic, zalk, fdep2, f_kw660,      &    ! inputs
+                     f_xco2a, f_ph, f_pco2w, f_h2co3, f_hco3, f_co3, f_omcal(ji,jj),   &    ! outputs
+                     f_omarg(ji,jj), f_co2flux, f_TDIC, f_TALK, f_dcf, f_henry, iters)      ! outputs
+                     !! 
+                     !! AXY (28/02/14): check output fields
+                     if (iters .eq. 25) then
+                        IF(lwp) WRITE(numout,*) ' trc_bio_medusa: 3D ITERS WARNING, ', &
+                        iters, ' AT (', ji, ', ', jj, ', ', jk, ') AT ', kt
+                     endif
+#  endif
+                     !!
+                     !! store 3D outputs
+                     f3_pH(ji,jj,jk)    = f_ph
+                     f3_h2co3(ji,jj,jk) = f_h2co3
+                     f3_hco3(ji,jj,jk)  = f_hco3
+                     f3_co3(ji,jj,jk)   = f_co3
+                     f3_omcal(ji,jj,jk) = f_omcal(ji,jj)
+                     f3_omarg(ji,jj,jk) = f_omarg(ji,jj)
+                     !!
+                     !! CCD calculation: calcite
+                     if (i2_omcal(ji,jj) .eq. 0 .and. f_omcal(ji,jj) .lt. 1.0) then
+                        if (jk .eq. 1) then
+                           f2_ccd_cal(ji,jj) = fdep2
+                        else
+                           fq0 = f3_omcal(ji,jj,jk-1) - f_omcal(ji,jj)
+                           fq1 = f3_omcal(ji,jj,jk-1) - 1.0
+                           fq2 = fq1 / (fq0 + tiny(fq0))
+                           fq3 = fdep2 - fsdept(ji,jj,jk-1)
+                           fq4 = fq2 * fq3
+                           f2_ccd_cal(ji,jj) = fsdept(ji,jj,jk-1) + fq4
+                        endif
+                        i2_omcal(ji,jj)   = 1
+                     endif
+                     if ( i2_omcal(ji,jj) .eq. 0 .and. jk .eq. jmbathy ) then
+                        !! reached seafloor and still no dissolution; set to seafloor (W-point)
+                        f2_ccd_cal(ji,jj) = fsdepw(ji,jj,jk+1)
+                        i2_omcal(ji,jj)   = 1
+                     endif
+                     !!
+                     !! CCD calculation: aragonite
+                     if (i2_omarg(ji,jj) .eq. 0 .and. f_omarg(ji,jj) .lt. 1.0) then
+                        if (jk .eq. 1) then
+                           f2_ccd_arg(ji,jj) = fdep2
+                        else
+                           fq0 = f3_omarg(ji,jj,jk-1) - f_omarg(ji,jj)
+                           fq1 = f3_omarg(ji,jj,jk-1) - 1.0
+                           fq2 = fq1 / (fq0 + tiny(fq0))
+                           fq3 = fdep2 - fsdept(ji,jj,jk-1)
+                           fq4 = fq2 * fq3
+                           f2_ccd_arg(ji,jj) = fsdept(ji,jj,jk-1) + fq4
+                        endif
+                        i2_omarg(ji,jj)   = 1
+                     endif
+                     if ( i2_omarg(ji,jj) .eq. 0 .and. jk .eq. jmbathy ) then
+                        !! reached seafloor and still no dissolution; set to seafloor (W-point)
+                        f2_ccd_arg(ji,jj) = fsdepw(ji,jj,jk+1)
+                        i2_omarg(ji,jj)   = 1
+                     endif
+                  endif
+               ENDDO
+            ENDDO
+         ENDDO
+      ENDIF
+# endif
+
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) 'trc_bio_medusa: ready for full domain calculations'
+      CALL flush(numout)
+# endif 
+
+      !!----------------------------------------------------------------------
+      !! MEDUSA has unified equation through the water column
+      !! (Diff. from LOBSTER which has two sets: bio- and non-bio layers) 
+      !! Statement below in LOBSTER is different: DO jk = 1, jpkbm1          
+      !!----------------------------------------------------------------------
+      !!
+      !! NOTE: the ordering of the loops below differs from that of some other
+      !! models; looping over the vertical dimension is the outermost loop and
+      !! this complicates some calculations (e.g. storage of vertical fluxes
+      !! that can otherwise be done via a singular variable require 2D fields
+      !! here); however, these issues are relatively easily resolved, but the
+      !! loops CANNOT be reordered without potentially causing code efficiency
+      !! problems (e.g. array indexing means that reordering the loops would
+      !! require skipping between widely-spaced memory location; potentially
+      !! outside those immediately cached)
+      !!
+      !! OPEN vertical loop
+      DO jk = 1,jpk
+         !! OPEN horizontal loops
+         DO jj = 2,jpjm1
+         DO ji = 2,jpim1
+            !! OPEN wet point IF..THEN loop
+            if (tmask(ji,jj,jk).eq.1) then               
+               !!======================================================================
+               !! SETUP LOCAL GRID CELL
+               !!======================================================================
+               !!
+               !!---------------------------------------------------------------------
+               !! Some notes on grid vertical structure
+               !! - fsdepw(ji,jj,jk) is the depth of the upper surface of level jk
+               !! - fsde3w(ji,jj,jk) is *approximately* the midpoint of level jk
+               !! - fse3t(ji,jj,jk)  is the thickness of level jk
+               !!---------------------------------------------------------------------
+               !!
+               !! AXY (11/12/08): set up level thickness
+               fthk  = fse3t(ji,jj,jk)
+               !! AXY (25/02/10): set up level depth (top of level)
+               fdep  = fsdepw(ji,jj,jk)
+               !! AXY (01/03/10): set up level depth (bottom of level)
+               fdep1 = fdep + fthk
+               !! AXY (17/05/13): where am I?
+               flatx = gphit(ji,jj)
+               flonx = glamt(ji,jj)
+               !! AXY (28/11/16): local seafloor depth
+               !!                 previously mbathy(ji,jj) - 1, now mbathy(ji,jj)
+               jmbathy = mbathy(ji,jj)
+               !!
+               !! set up model tracers
+               !! negative values of state variables are not allowed to
+               !! contribute to the calculated fluxes
+               zchn = max(0.,trn(ji,jj,jk,jpchn)) !! non-diatom chlorophyll
+               zchd = max(0.,trn(ji,jj,jk,jpchd)) !! diatom chlorophyll
+               zphn = max(0.,trn(ji,jj,jk,jpphn)) !! non-diatoms
+               zphd = max(0.,trn(ji,jj,jk,jpphd)) !! diatoms
+               zpds = max(0.,trn(ji,jj,jk,jppds)) !! diatom silicon
+               !! AXY (28/01/10): probably need to take account of chl/biomass connection
+               if (zchn.eq.0.) zphn = 0.
+               if (zchd.eq.0.) zphd = 0.
+               if (zphn.eq.0.) zchn = 0.
+               if (zphd.eq.0.) zchd = 0.
+	       !! AXY (23/01/14): duh - why did I forget diatom silicon?
+	       if (zpds.eq.0.) zphd = 0.
+	       if (zphd.eq.0.) zpds = 0.
+               zzmi = max(0.,trn(ji,jj,jk,jpzmi)) !! microzooplankton
+               zzme = max(0.,trn(ji,jj,jk,jpzme)) !! mesozooplankton
+               zdet = max(0.,trn(ji,jj,jk,jpdet)) !! detrital nitrogen
+               zdin = max(0.,trn(ji,jj,jk,jpdin)) !! dissolved inorganic nitrogen
+               zsil = max(0.,trn(ji,jj,jk,jpsil)) !! dissolved silicic acid
+               zfer = max(0.,trn(ji,jj,jk,jpfer)) !! dissolved "iron"
+# if defined key_roam
+               zdtc = max(0.,trn(ji,jj,jk,jpdtc)) !! detrital carbon
+               zdic = max(0.,trn(ji,jj,jk,jpdic)) !! dissolved inorganic carbon
+               zalk = max(0.,trn(ji,jj,jk,jpalk)) !! alkalinity
+               zoxy = max(0.,trn(ji,jj,jk,jpoxy)) !! oxygen
+               !!
+               !! also need physical parameters for gas exchange calculations
+               ztmp = tsn(ji,jj,jk,jp_tem)
+               zsal = tsn(ji,jj,jk,jp_sal)
+               !!
+	       !! AXY (28/02/14): check input fields
+               if (ztmp .lt. -3.0 .or. ztmp .gt. 40.0 ) then
+                  IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T WARNING 2D, ', &
+                  tsb(ji,jj,jk,jp_tem), tsn(ji,jj,jk,jp_tem), ' at (',    &
+                  ji, ',', jj, ',', jk, ') at time', kt
+		  IF(lwp) WRITE(numout,*) ' trc_bio_medusa: T SWITCHING 2D, ', &
+                  tsn(ji,jj,jk,jp_tem), ' -> ', tsb(ji,jj,jk,jp_tem)
+                  ztmp = tsb(ji,jj,jk,jp_tem) !! temperature
+               endif
+               if (zsal .lt. 0.0 .or. zsal .gt. 45.0 ) then
+                  IF(lwp) WRITE(numout,*) ' trc_bio_medusa: S WARNING 2D, ', &
+                  tsb(ji,jj,jk,jp_sal), tsn(ji,jj,jk,jp_sal), ' at (',    &
+                  ji, ',', jj, ',', jk, ') at time', kt
+               endif
+# else
+               zdtc = zdet * xthetad              !! implicit detrital carbon
+# endif
+# if defined key_debug_medusa
+               if (idf.eq.1) then
+               !! AXY (15/01/10)
+                  if (trn(ji,jj,jk,jpdin).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE DIN ERROR =', trn(ji,jj,jk,jpdin)
+                     IF (lwp) write (numout,*) 'NEGATIVE DIN ERROR @', ji, jj, jk, kt
+                  endif
+                  if (trn(ji,jj,jk,jpsil).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE SIL ERROR =', trn(ji,jj,jk,jpsil)
+                     IF (lwp) write (numout,*) 'NEGATIVE SIL ERROR @', ji, jj, jk, kt
+                  endif
+#  if defined key_roam
+                  if (trn(ji,jj,jk,jpdic).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE DIC ERROR =', trn(ji,jj,jk,jpdic)
+                     IF (lwp) write (numout,*) 'NEGATIVE DIC ERROR @', ji, jj, jk, kt
+                  endif
+                  if (trn(ji,jj,jk,jpalk).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE ALK ERROR =', trn(ji,jj,jk,jpalk)
+                     IF (lwp) write (numout,*) 'NEGATIVE ALK ERROR @', ji, jj, jk, kt
+                  endif
+                  if (trn(ji,jj,jk,jpoxy).lt.0.) then
+                     IF (lwp) write (numout,*) '------------------------------'
+                     IF (lwp) write (numout,*) 'NEGATIVE OXY ERROR =', trn(ji,jj,jk,jpoxy)
+                     IF (lwp) write (numout,*) 'NEGATIVE OXY ERROR @', ji, jj, jk, kt
+                  endif
+#  endif
+               endif
+# endif
+# if defined key_debug_medusa
+               !! report state variable values
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fthk(',jk,') = ', fthk
+                  IF (lwp) write (numout,*) 'zphn(',jk,') = ', zphn
+                  IF (lwp) write (numout,*) 'zphd(',jk,') = ', zphd
+                  IF (lwp) write (numout,*) 'zpds(',jk,') = ', zpds
+                  IF (lwp) write (numout,*) 'zzmi(',jk,') = ', zzmi
+                  IF (lwp) write (numout,*) 'zzme(',jk,') = ', zzme
+                  IF (lwp) write (numout,*) 'zdet(',jk,') = ', zdet
+                  IF (lwp) write (numout,*) 'zdin(',jk,') = ', zdin
+                  IF (lwp) write (numout,*) 'zsil(',jk,') = ', zsil
+                  IF (lwp) write (numout,*) 'zfer(',jk,') = ', zfer
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'zdtc(',jk,') = ', zdtc
+                  IF (lwp) write (numout,*) 'zdic(',jk,') = ', zdic
+                  IF (lwp) write (numout,*) 'zalk(',jk,') = ', zalk
+                  IF (lwp) write (numout,*) 'zoxy(',jk,') = ', zoxy                  
+#  endif
+               endif
+# endif
+
+# if defined key_debug_medusa
+               if (idf.eq.1.AND.idfval.eq.1.AND.jk.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'dust      = ', dust(ji,jj)
+               endif
+# endif
+
+               !! sum tracers for inventory checks
+               IF( lk_iomput ) THEN
+                  IF ( med_diag%INVTN%dgsave )   THEN
+                     ftot_n(ji,jj)  = ftot_n(ji,jj) + &
+                             (fthk * ( zphn + zphd + zzmi + zzme + zdet + zdin ) )
+                  ENDIF
+                  IF ( med_diag%INVTSI%dgsave )  THEN
+                     ftot_si(ji,jj) = ftot_si(ji,jj) + & 
+                             (fthk * ( zpds + zsil ) )
+                  ENDIF
+                  IF ( med_diag%INVTFE%dgsave )  THEN
+                     ftot_fe(ji,jj) = ftot_fe(ji,jj) + & 
+                             (fthk * ( xrfn * ( zphn + zphd + zzmi + zzme + zdet ) + zfer ) )
+                  ENDIF
+# if defined key_roam
+                  IF ( med_diag%INVTC%dgsave )  THEN
+                     ftot_c(ji,jj)  = ftot_c(ji,jj) + & 
+                             (fthk * ( (xthetapn * zphn) + (xthetapd * zphd) + &
+                             (xthetazmi * zzmi) + (xthetazme * zzme) + zdtc +   &
+                             zdic ) )
+                  ENDIF
+                  IF ( med_diag%INVTALK%dgsave ) THEN
+                     ftot_a(ji,jj)  = ftot_a(ji,jj) + (fthk * ( zalk ) )
+                  ENDIF
+                  IF ( med_diag%INVTO2%dgsave )  THEN
+                     ftot_o2(ji,jj) = ftot_o2(ji,jj) + (fthk * ( zoxy ) )
+                  ENDIF
+                  !!
+                  !! AXY (10/11/16): CMIP6 diagnostics
+                  IF ( med_diag%INTDISSIC%dgsave ) THEN
+                     intdissic(ji,jj) = intdissic(ji,jj) + (fthk * zdic)
+                  ENDIF
+                  IF ( med_diag%INTDISSIN%dgsave ) THEN
+                     intdissin(ji,jj) = intdissin(ji,jj) + (fthk * zdin)
+                  ENDIF
+                  IF ( med_diag%INTDISSISI%dgsave ) THEN
+                     intdissisi(ji,jj) = intdissisi(ji,jj) + (fthk * zsil)
+                  ENDIF
+                  IF ( med_diag%INTTALK%dgsave ) THEN
+                     inttalk(ji,jj) = inttalk(ji,jj) + (fthk * zalk)
+                  ENDIF
+                  IF ( med_diag%O2min%dgsave ) THEN
+                     if ( zoxy < o2min(ji,jj) ) then
+                        o2min(ji,jj)  = zoxy
+                        IF ( med_diag%ZO2min%dgsave ) THEN
+                           zo2min(ji,jj) = (fdep + fdep1) / 2. !! layer midpoint
+                        ENDIF
+                     endif
+                  ENDIF
+# endif
+               ENDIF
+
+               CALL flush(numout)
+
+               !!======================================================================
+               !! LOCAL GRID CELL CALCULATIONS
+               !!======================================================================
+               !!
+# if defined key_roam
+               if ( jk .eq. 1 ) then
+                  !!----------------------------------------------------------------------
+                  !! Air-sea gas exchange
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! AXY (17/07/14): zwind_i and zwind_j do not exist in this
+                  !!                 version of NEMO because it does not include
+                  !!                 the SBC changes that our local version has
+                  !!                 for accessing the HadGEM2 forcing; they 
+                  !!                 could be added, but an alternative approach
+                  !!                 is to make use of wndm from oce_trc.F90
+                  !!                 which is wind speed at 10m (which is what
+                  !!                 is required here; this may need to be
+                  !!                 revisited when MEDUSA properly interacts
+                  !!                 with UKESM1 physics
+                  !!
+                  f_wind  = wndm(ji,jj)
+                  IF (lk_oasis) THEN
+                     f_xco2a = PCO2a_in_cpl(ji,jj)        !! use 2D atm xCO2 from atm coupling
+                  ENDIF
+                  !!
+                  !! AXY (23/06/15): as part of an effort to update the carbonate chemistry
+                  !!                 in MEDUSA, the gas transfer velocity used in the carbon
+                  !!                 and oxygen cycles has been harmonised and is calculated
+                  !!                 by the same function here; this harmonisation includes
+                  !!                 changes to the PML carbonate chemistry scheme so that
+                  !!                 it too makes use of the same gas transfer velocity; the
+                  !!                 preferred parameterisation of this is Wanninkhof (2014),
+                  !!                 option 7
+                  !!
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: entering gas_transfer'
+                     CALL flush(numout)
+#   endif
+                  CALL gas_transfer( f_wind, 1, 7, &  ! inputs
+                                     f_kw660 )        ! outputs
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: exiting gas_transfer'
+                     CALL flush(numout)
+#   endif
+                  !!
+                  !! air pressure (atm); ultimately this will use air pressure at the base
+                  !! of the UKESM1 atmosphere 
+                  !!                                     
+                  f_pp0   = 1.0
+                  !!
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA ztmp    =', ztmp
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA zwind_i =', zwind_i(ji,jj)
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA zwind_j =', zwind_j(ji,jj)
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA f_wind  =', f_wind
+                  !! IF(lwp) WRITE(numout,*) ' MEDUSA fr_i    =', fr_i(ji,jj)
+                  !!
+#  if defined key_axy_carbchem
+#   if defined key_mocsy
+                  !!
+                  !! AXY (22/06/15): use Orr & Epitalon (2015) MOCSY-2 carbonate
+                  !!                 chemistry package; note that depth is set to
+                  !!                 zero in this call
+                  CALL mocsy_interface( ztmp, zsal, zalk, zdic, zsil, zpho,        &  ! inputs
+                  f_pp0, 0.0, flatx, f_kw660, f_xco2a, 1,                          &  ! inputs
+                  f_ph, f_pco2w, f_fco2w, f_h2co3, f_hco3, f_co3, f_omarg(ji,jj),  &  ! outputs
+                  f_omcal(ji,jj), f_BetaD, f_rhosw, f_opres, f_insitut,            &  ! outputs
+                  f_pco2atm, f_fco2atm, f_schmidtco2, f_kwco2, f_K0,               &  ! outputs
+                  f_co2starair, f_co2flux, f_dpco2 )                                  ! outputs
+                  !!
+                  f_TDIC = (zdic / f_rhosw) * 1000. ! mmol / m3 -> umol / kg
+                  f_TALK = (zalk / f_rhosw) * 1000. !  meq / m3 ->  ueq / kg
+                  f_dcf  = f_rhosw
+#   else                  
+                  iters = 0
+                  !!
+                  !! carbon dioxide (CO2); Jerry Blackford code (ostensibly OCMIP-2, but not)
+                  CALL trc_co2_medusa( ztmp, zsal, zdic, zalk, 0.0, f_kw660, f_xco2a,  &  ! inputs
+                  f_ph, f_pco2w, f_h2co3, f_hco3, f_co3, f_omcal(ji,jj),               &  ! outputs
+                  f_omarg(ji,jj), f_co2flux, f_TDIC, f_TALK, f_dcf, f_henry, iters )      ! outputs
+                  !!
+                  !! AXY (09/01/14): removed iteration and NaN checks; these have
+                  !!                 been moved to trc_co2_medusa together with a
+                  !!                 fudge that amends erroneous values (this is
+                  !!                 intended to be a temporary fudge!); the
+                  !!                 output warnings are retained here so that
+                  !!                 failure position can be determined
+                  if (iters .eq. 25) then
+                     IF(lwp) WRITE(numout,*) ' trc_bio_medusa: ITERS WARNING, ', &
+                     iters, ' AT (', ji, ', ', jj, ', ', jk, ') AT ', kt
+                  endif
+#   endif
+#  else
+                  !! AXY (18/04/13): switch off carbonate chemistry calculations; provide
+                  !!                 quasi-sensible alternatives
+                  f_ph           = 8.1
+                  f_pco2w        = f_xco2a
+                  f_h2co3        = 0.005 * zdic
+                  f_hco3         = 0.865 * zdic
+                  f_co3          = 0.130 * zdic
+                  f_omcal(ji,jj) = 4.
+                  f_omarg(ji,jj) = 2.
+                  f_co2flux      = 0.
+                  f_TDIC         = zdic
+                  f_TALK         = zalk
+                  f_dcf          = 1.026
+                  f_henry        = 1.
+                  !! AXY (23/06/15): add in some extra MOCSY diagnostics
+                  f_fco2w        = f_xco2a
+                  f_BetaD        = 1.
+                  f_rhosw        = 1.026
+                  f_opres        = 0.
+                  f_insitut      = ztmp
+                  f_pco2atm      = f_xco2a
+                  f_fco2atm      = f_xco2a
+                  f_schmidtco2   = 660.
+                  f_kwco2        = 0.
+                  f_K0           = 0.
+                  f_co2starair   = f_xco2a
+                  f_dpco2        = 0.
+#  endif
+                  !!
+                  !! mmol/m2/s -> mmol/m3/d; correct for sea-ice; divide through by layer thickness
+                  f_co2flux = (1. - fr_i(ji,jj)) * f_co2flux * 86400. / fthk
+                  !!
+                  !! oxygen (O2); OCMIP-2 code
+                  !! AXY (23/06/15): amend input list for oxygen to account for common gas
+                  !!                 transfer velocity
+                  !! CALL trc_oxy_medusa( ztmp, zsal, f_uwind, f_vwind, f_pp0, zoxy / 1000., fthk,  &  ! inputs
+                  !! f_kw660, f_o2flux, f_o2sat )                                                      ! outputs
+                  CALL trc_oxy_medusa( ztmp, zsal, f_kw660, f_pp0, zoxy,  &  ! inputs
+                  f_kwo2, f_o2flux, f_o2sat )                                ! outputs
+                  !!
+                  !! mmol/m2/s -> mol/m3/d; correct for sea-ice; divide through by layer thickness
+                  f_o2flux  = (1. - fr_i(ji,jj)) * f_o2flux * 86400. / fthk
+                  !!
+                  !! Jpalm (08-2014)
+                  !! DMS surface concentration calculation
+                  !! initialy added for UKESM1 model.
+                  !! using MET-OFFICE subroutine.
+                  !! DMS module only needs Chl concentration and MLD
+                  !! to get an aproximate value of DMS concentration.
+                  !! air-sea fluxes are calculated by atmospheric chemitry model
+                  !! from atm and oc-surface concentrations.
+                  !!
+                  !! AXY (13/03/15): this is amended to calculate all of the DMS
+                  !!                 estimates examined during UKESM1 (see comments
+                  !!                 in trcdms_medusa.F90)
+                  !!
+                  IF (jdms .eq. 1) THEN
+                     !!
+                     !! feed in correct inputs
+                     if (jdms_input .eq. 0) then
+                        !! use instantaneous inputs
+                        CALL trc_dms_medusa( zchn, zchd, hmld(ji,jj), qsr(ji,jj), zdin, &  ! inputs
+                        dms_andr, dms_simo, dms_aran, dms_hall )                           ! outputs
+                     else
+                        !! use diel-average inputs
+                        CALL trc_dms_medusa( zn_dms_chn(ji,jj), zn_dms_chd(ji,jj), &  ! inputs
+                        zn_dms_mld(ji,jj), zn_dms_qsr(ji,jj), zn_dms_din(ji,jj),   &  ! inputs
+                        dms_andr, dms_simo, dms_aran, dms_hall )                      ! outputs
+                     endif
+                     !!
+                     !! assign correct output to variable passed to atmosphere
+                     if     (jdms_model .eq. 1) then
+                        dms_surf = dms_andr
+                     elseif (jdms_model .eq. 2) then
+                        dms_surf = dms_simo
+                     elseif (jdms_model .eq. 3) then
+                        dms_surf = dms_aran
+                     elseif (jdms_model .eq. 4) then
+                        dms_surf = dms_hall
+                     endif
+                     !!
+                     !! 2D diag through iom_use
+                     IF( lk_iomput ) THEN
+                       IF( med_diag%DMS_SURF%dgsave ) THEN
+                         dms_surf2d(ji,jj) = dms_surf
+                       ENDIF
+                       IF( med_diag%DMS_ANDR%dgsave ) THEN
+                         dms_andr2d(ji,jj) = dms_andr
+                       ENDIF
+                       IF( med_diag%DMS_SIMO%dgsave ) THEN
+                         dms_simo2d(ji,jj) = dms_simo
+                       ENDIF
+                       IF( med_diag%DMS_ARAN%dgsave ) THEN
+                         dms_aran2d(ji,jj) = dms_aran
+                       ENDIF
+                       IF( med_diag%DMS_HALL%dgsave ) THEN
+                         dms_hall2d(ji,jj) = dms_hall
+                       ENDIF
+#   if defined key_debug_medusa
+                       IF (lwp) write (numout,*) 'trc_bio_medusa: finish calculating dms'
+                     CALL flush(numout)
+#   endif 
+                     ENDIF
+                     !! End iom
+                  ENDIF
+                  !! End DMS Loop
+                  !!
+                  !! store 2D outputs
+                  !!
+                  !! JPALM -- 17-11-16 -- put fgco2 out of diag request
+                  !!                    is needed for coupling; pass through restart
+                  !! IF( med_diag%FGCO2%dgsave ) THEN
+                     !! convert from  mol/m2/day to kg/m2/s
+                     fgco2(ji,jj) = f_co2flux * fthk * CO2flux_conv  !! mmol-C/m3/d -> kg-CO2/m2/s
+                  !! ENDIF
+                  IF ( lk_iomput ) THEN
+                      IF( med_diag%ATM_PCO2%dgsave ) THEN
+                         f_pco2a2d(ji,jj) = f_pco2atm
+                      ENDIF
+                      IF( med_diag%OCN_PCO2%dgsave ) THEN
+                         f_pco2w2d(ji,jj) = f_pco2w
+                      ENDIF
+                      IF( med_diag%CO2FLUX%dgsave ) THEN
+                         f_co2flux2d(ji,jj) = f_co2flux * fthk           !! mmol/m3/d -> mmol/m2/d
+                      ENDIF
+                      IF( med_diag%TCO2%dgsave ) THEN
+                         f_TDIC2d(ji,jj) = f_TDIC
+                      ENDIF
+                      IF( med_diag%TALK%dgsave ) THEN
+                         f_TALK2d(ji,jj) = f_TALK
+                      ENDIF
+                      IF( med_diag%KW660%dgsave ) THEN
+                         f_kw6602d(ji,jj) = f_kw660
+                      ENDIF
+                      IF( med_diag%ATM_PP0%dgsave ) THEN
+                         f_pp02d(ji,jj) = f_pp0
+                      ENDIF
+                      IF( med_diag%O2FLUX%dgsave ) THEN
+                         f_o2flux2d(ji,jj) = f_o2flux
+                      ENDIF
+                      IF( med_diag%O2SAT%dgsave ) THEN
+                         f_o2sat2d(ji,jj) = f_o2sat
+                      ENDIF
+                      !! AXY (24/11/16): add in extra MOCSY diagnostics
+                      IF( med_diag%ATM_XCO2%dgsave ) THEN
+                         f_xco2a_2d(ji,jj) = f_xco2a
+                      ENDIF
+                      IF( med_diag%OCN_FCO2%dgsave ) THEN
+                         f_fco2w_2d(ji,jj) = f_fco2w
+                      ENDIF
+                      IF( med_diag%ATM_FCO2%dgsave ) THEN
+                         f_fco2a_2d(ji,jj) = f_fco2atm
+                      ENDIF
+                      IF( med_diag%OCN_RHOSW%dgsave ) THEN
+                         f_ocnrhosw_2d(ji,jj) = f_rhosw
+                      ENDIF
+                      IF( med_diag%OCN_SCHCO2%dgsave ) THEN
+                         f_ocnschco2_2d(ji,jj) = f_schmidtco2
+                      ENDIF
+                      IF( med_diag%OCN_KWCO2%dgsave ) THEN
+                         f_ocnkwco2_2d(ji,jj) = f_kwco2
+                      ENDIF
+                      IF( med_diag%OCN_K0%dgsave ) THEN
+                         f_ocnk0_2d(ji,jj) = f_K0
+                      ENDIF
+                      IF( med_diag%CO2STARAIR%dgsave ) THEN
+                         f_co2starair_2d(ji,jj) = f_co2starair
+                      ENDIF
+                      IF( med_diag%OCN_DPCO2%dgsave ) THEN
+                         f_ocndpco2_2d(ji,jj) = f_dpco2
+                      ENDIF
+                  ENDIF
+                  !! 
+               endif
+               !! End jk = 1 loop within ROAM key 
+
+               !! AXY (11/11/16): CMIP6 oxygen saturation 3D diagnostic
+               IF ( med_diag%O2SAT3%dgsave ) THEN
+                  call oxy_sato( ztmp, zsal, f_o2sat3 )
+                  o2sat3(ji, jj, jk) = f_o2sat3
+               ENDIF
+
+# endif
+
+               if ( jk .eq. 1 ) then
+                  !!----------------------------------------------------------------------
+                  !! River inputs
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! runoff comes in as        kg / m2 / s
+                  !! used and written out as   m3 / m2 / d (= m / d)
+                  !! where                     1000 kg / m2 / d = 1 m3 / m2 / d = 1 m / d
+                  !!
+                  !! AXY (17/07/14): the compiler doesn't like this line for some reason;
+                  !!                 as MEDUSA doesn't even use runoff for riverine inputs,
+                  !!                 a temporary solution is to switch off runoff entirely
+                  !!                 here; again, this change is one of several that will 
+                  !!                 need revisiting once MEDUSA has bedded down in UKESM1;
+                  !!                 particularly so if the land scheme provides information
+                  !!                 concerning nutrient fluxes
+                  !!
+                  !! f_runoff(ji,jj) = sf_rnf(1)%fnow(ji,jj,1) / 1000. * 60. * 60. * 24.
+                  f_runoff(ji,jj) = 0.0
+                  !!
+                  !! nutrients are added via rivers to the model in one of two ways:
+                  !!   1. via river concentration; i.e. the average nutrient concentration
+                  !!      of a river water is described by a spatial file, and this is
+                  !!      multiplied by runoff to give a nutrient flux
+                  !!   2. via direct river flux; i.e. the average nutrient flux due to
+                  !!      rivers is described by a spatial file, and this is simply applied
+                  !!      as a direct nutrient flux (i.e. it does not relate or respond to
+                  !!      model runoff)
+                  !! nutrient fields are derived from the GlobalNEWS 2 database; carbon and
+                  !! alkalinity are derived from continent-scale DIC estimates (Huang et al., 
+                  !! 2012) and some Arctic river alkalinity estimates (Katya?)
+                  !! 
+                  !! as of 19/07/12, riverine nutrients can now be spread vertically across 
+                  !! several grid cells rather than just poured into the surface box; this
+                  !! block of code is still executed, however, to set up the total amounts
+                  !! of nutrient entering via rivers
+                  !!
+                  !! nitrogen
+                  if (jriver_n .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_n(ji,jj) = f_runoff(ji,jj) * riv_n(ji,jj)
+                  elseif (jriver_n .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_n(ji,jj) = riv_n(ji,jj)
+                  endif
+                  !!
+                  !! silicon
+                  if (jriver_si .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_si(ji,jj) = f_runoff(ji,jj) * riv_si(ji,jj)
+                  elseif (jriver_si .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_si(ji,jj) = riv_si(ji,jj)
+                  endif
+                  !!
+                  !! carbon
+                  if (jriver_c .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_c(ji,jj) = f_runoff(ji,jj) * riv_c(ji,jj)
+                  elseif (jriver_c .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_c(ji,jj) = riv_c(ji,jj)
+                  endif
+                  !!
+                  !! alkalinity
+                  if (jriver_alk .eq. 1) then
+                     !! river concentration specified; use runoff to calculate input
+                     f_riv_alk(ji,jj) = f_runoff(ji,jj) * riv_alk(ji,jj)
+                  elseif (jriver_alk .eq. 2) then
+                     !! river flux specified; independent of runoff
+                     f_riv_alk(ji,jj) = riv_alk(ji,jj)
+                  endif
+
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Chlorophyll calculations
+               !!----------------------------------------------------------------------
+               !!
+               !! non-diatoms
+	       if (zphn.GT.rsmall) then
+                  fthetan = max(tiny(zchn), (zchn * xxi) / (zphn + tiny(zphn)))
+                  faln    = xaln * fthetan
+               else
+                  fthetan = 0.
+                  faln    = 0.
+               endif
+               !!
+               !! diatoms
+	       if (zphd.GT.rsmall) then
+                  fthetad = max(tiny(zchd), (zchd * xxi) / (zphd + tiny(zphd)))
+                  fald    = xald * fthetad
+               else
+                  fthetad = 0.
+                  fald    = 0.
+               endif
+
+# if defined key_debug_medusa
+               !! report biological calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'faln(',jk,') = ', faln
+                  IF (lwp) write (numout,*) 'fald(',jk,') = ', fald
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Phytoplankton light limitation
+               !!----------------------------------------------------------------------
+               !!
+               !! It is assumed xpar is the depth-averaged (vertical layer) PAR 
+               !! Light limitation (check self-shading) in W/m2
+               !!
+               !! Note that there is no temperature dependence in phytoplankton
+               !! growth rate or any other function. 
+               !! In calculation of Chl/Phy ratio tiny(phyto) is introduced to avoid
+               !! NaNs in case of Phy==0.  
+               !!
+               !! fthetad and fthetan are Chl:C ratio (gChl/gC) in diat and non-diat: 
+               !! for 1:1 Chl:P ratio (mgChl/mmolN) theta=0.012
+               !!
+               !! AXY (16/07/09)
+               !! temperature for new Eppley style phytoplankton growth
+               loc_T   = tsn(ji,jj,jk,jp_tem)
+               fun_T   = 1.066**(1.0 * loc_T)
+               !! AXY (16/05/11): add in new Q10 (1.5, not 2.0) for
+               !phytoplankton
+               !!                 growth; remin. unaffected
+               fun_Q10 = jq10**((loc_T - 0.0) / 10.0)
+               if (jphy.eq.1) then
+                  xvpnT = xvpn * fun_T
+                  xvpdT = xvpd * fun_T
+               elseif (jphy.eq.2) then
+                  xvpnT = xvpn * fun_Q10
+                  xvpdT = xvpd * fun_Q10
+               else
+                  xvpnT = xvpn
+                  xvpdT = xvpd
+               endif
+               !!
+               !! non-diatoms
+               fchn1   = (xvpnT * xvpnT) + (faln * faln * xpar(ji,jj,jk) * xpar(ji,jj,jk))
+               if (fchn1.GT.rsmall) then
+                  fchn    = xvpnT / (sqrt(fchn1) + tiny(fchn1))
+               else
+                  fchn    = 0.
+               endif
+               fjln    = fchn * faln * xpar(ji,jj,jk) !! non-diatom J term
+               fjlim_pn = fjln / xvpnT
+               !!
+               !! diatoms
+               fchd1   = (xvpdT * xvpdT) + (fald * fald * xpar(ji,jj,jk) * xpar(ji,jj,jk))
+               if (fchd1.GT.rsmall) then
+                  fchd    = xvpdT / (sqrt(fchd1) + tiny(fchd1))
+               else
+                  fchd    = 0.
+               endif
+               fjld    = fchd * fald * xpar(ji,jj,jk) !! diatom J term
+               fjlim_pd = fjld / xvpdT
+      
+# if defined key_debug_medusa
+               !! report phytoplankton light limitation
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fchn(',jk,') = ', fchn
+                  IF (lwp) write (numout,*) 'fchd(',jk,') = ', fchd
+                  IF (lwp) write (numout,*) 'fjln(',jk,') = ', fjln
+                  IF (lwp) write (numout,*) 'fjld(',jk,') = ', fjld
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Phytoplankton nutrient limitation
+               !!----------------------------------------------------------------------
+               !!
+               !! non-diatoms (N, Fe)
+               fnln = zdin / (zdin + xnln) !! non-diatom Qn term
+               ffln = zfer / (zfer + xfln) !! non-diatom Qf term
+               !!
+               !! diatoms (N, Si, Fe)
+               fnld = zdin / (zdin + xnld) !! diatom Qn term
+               fsld = zsil / (zsil + xsld) !! diatom Qs term
+               ffld = zfer / (zfer + xfld) !! diatom Qf term
+
+# if defined key_debug_medusa
+               !! report phytoplankton nutrient limitation
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fnln(',jk,') = ', fnln
+                  IF (lwp) write (numout,*) 'fnld(',jk,') = ', fnld
+                  IF (lwp) write (numout,*) 'ffln(',jk,') = ', ffln
+                  IF (lwp) write (numout,*) 'ffld(',jk,') = ', ffld
+                  IF (lwp) write (numout,*) 'fsld(',jk,') = ', fsld
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Primary production (non-diatoms)
+               !! (note: still needs multiplying by phytoplankton concentration)
+               !!----------------------------------------------------------------------
+               !!
+               if (jliebig .eq. 0) then
+                  !! multiplicative nutrient limitation
+                  fpnlim = fnln * ffln
+               elseif (jliebig .eq. 1) then
+                  !! Liebig Law (= most limiting) nutrient limitation
+                  fpnlim = min(fnln, ffln)
+               endif
+               fprn = fjln * fpnlim
+
+               !!----------------------------------------------------------------------
+               !! Primary production (diatoms)
+               !! (note: still needs multiplying by phytoplankton concentration)
+               !!
+               !! production here is split between nitrogen production and that of
+               !! silicon; depending upon the "intracellular" ratio of Si:N, model
+               !! diatoms will uptake nitrogen/silicon differentially; this borrows
+               !! from the diatom model of Mongin et al. (2006)
+               !!----------------------------------------------------------------------
+               !!
+               if (jliebig .eq. 0) then
+                  !! multiplicative nutrient limitation
+                  fpdlim = fnld * ffld
+               elseif (jliebig .eq. 1) then
+                  !! Liebig Law (= most limiting) nutrient limitation
+                  fpdlim = min(fnld, ffld)
+               endif
+               !!
+	       if (zphd.GT.rsmall .AND. zpds.GT.rsmall) then
+                  !! "intracellular" elemental ratios
+                  ! fsin  = zpds / (zphd + tiny(zphd))
+                  ! fnsi  = zphd / (zpds + tiny(zpds))
+                  fsin = 0.0
+                  IF( zphd .GT. rsmall) fsin  = zpds / zphd
+                  fnsi = 0.0
+                  IF( zpds .GT. rsmall) fnsi  = zphd / zpds
+                  !! AXY (23/02/10): these next variables derive from Mongin et al. (2003)
+                  fsin1 = 3.0 * xsin0 !! = 0.6
+                  fnsi1 = 1.0 / fsin1 !! = 1.667
+                  fnsi2 = 1.0 / xsin0 !! = 5.0
+                  !!
+                  !! conditionalities based on ratios
+                  !! nitrogen (and iron and carbon)
+                  if (fsin.le.xsin0) then
+                     fprd  = 0.0
+                     fsld2 = 0.0
+                  elseif (fsin.lt.fsin1) then
+                     fprd  = xuif * ((fsin - xsin0) / (fsin + tiny(fsin))) * (fjld * fpdlim)
+                     fsld2 = xuif * ((fsin - xsin0) / (fsin + tiny(fsin)))
+                  elseif (fsin.ge.fsin1) then
+                     fprd  = (fjld * fpdlim)
+                     fsld2 = 1.0
+                  endif
+                  !!
+                  !! silicon
+                  if (fsin.lt.fnsi1) then
+                     fprds = (fjld * fsld)
+                  elseif (fsin.lt.fnsi2) then
+                     fprds = xuif * ((fnsi - xnsi0) / (fnsi + tiny(fnsi))) * (fjld * fsld)
+                  else
+                     fprds = 0.0
+                  endif     
+               else
+                  fsin  = 0.0
+                  fnsi  = 0.0
+                  fprd  = 0.0
+                  fsld2 = 0.0
+                  fprds = 0.0
+               endif
+
+# if defined key_debug_medusa
+               !! report phytoplankton growth (including diatom silicon submodel)
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fsin(',jk,')   = ', fsin
+                  IF (lwp) write (numout,*) 'fnsi(',jk,')   = ', fnsi
+                  IF (lwp) write (numout,*) 'fsld2(',jk,')  = ', fsld2
+                  IF (lwp) write (numout,*) 'fprn(',jk,')   = ', fprn
+                  IF (lwp) write (numout,*) 'fprd(',jk,')   = ', fprd
+                  IF (lwp) write (numout,*) 'fprds(',jk,')  = ', fprds
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Mixed layer primary production
+               !! this block calculates the amount of primary production that occurs
+               !! within the upper mixed layer; this allows the separate diagnosis
+               !! of "sub-surface" primary production; it does assume that short-
+               !! term variability in mixed layer depth doesn't mess with things
+               !! though
+               !!----------------------------------------------------------------------
+               !!
+               if (fdep1.le.hmld(ji,jj)) then
+                  !! this level is entirely in the mixed layer
+                  fq0 = 1.0
+               elseif (fdep.ge.hmld(ji,jj)) then
+                  !! this level is entirely below the mixed layer
+                  fq0 = 0.0
+               else
+                  !! this level straddles the mixed layer
+                  fq0 = (hmld(ji,jj) - fdep) / fthk
+               endif
+               !!
+               fprn_ml(ji,jj) = fprn_ml(ji,jj) + (fprn * zphn * fthk * fq0)
+               fprd_ml(ji,jj) = fprd_ml(ji,jj) + (fprd * zphd * fthk * fq0)
+               
+               !!----------------------------------------------------------------------
+               !! Vertical Integral --
+               !!----------------------------------------------------------------------
+               ftot_pn(ji,jj)  = ftot_pn(ji,jj)  + (zphn * fthk)   !! vertical integral non-diatom phytoplankton
+               ftot_pd(ji,jj)  = ftot_pd(ji,jj)  + (zphd * fthk)   !! vertical integral diatom phytoplankton
+               ftot_zmi(ji,jj) = ftot_zmi(ji,jj) + (zzmi * fthk)   !! vertical integral microzooplankton
+               ftot_zme(ji,jj) = ftot_zme(ji,jj) + (zzme * fthk)   !! vertical integral mesozooplankton
+               ftot_det(ji,jj) = ftot_det(ji,jj) + (zdet * fthk)   !! vertical integral slow detritus, nitrogen
+               ftot_dtc(ji,jj) = ftot_dtc(ji,jj) + (zdtc * fthk)   !! vertical integral slow detritus, carbon
+               
+               !!----------------------------------------------------------------------
+               !! More chlorophyll calculations
+               !!----------------------------------------------------------------------
+               !!
+               !! frn = (xthetam / fthetan) * (fprn / (fthetan * xpar(ji,jj,jk)))
+               !! frd = (xthetam / fthetad) * (fprd / (fthetad * xpar(ji,jj,jk)))
+               frn = (xthetam * fchn * fnln * ffln       ) / (fthetan + tiny(fthetan))
+               !! AXY (12/05/09): there's potentially a problem here; fsld, silicic acid 
+               !!   limitation, is used in the following line to regulate chlorophyll 
+               !!   growth in a manner that is inconsistent with its use in the regulation 
+               !!   of biomass growth; the Mongin term term used in growth is more complex
+               !!   than the simple multiplicative function used below
+               !! frd = (xthetam * fchd * fnld * ffld * fsld) / (fthetad + tiny(fthetad))
+               !! AXY (12/05/09): this replacement line uses the new variable, fsld2, to
+               !!   regulate chlorophyll growth
+               frd = (xthetamd * fchd * fnld * ffld * fsld2) / (fthetad + tiny(fthetad))
+
+# if defined key_debug_medusa
+               !! report chlorophyll calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fthetan(',jk,') = ', fthetan
+                  IF (lwp) write (numout,*) 'fthetad(',jk,') = ', fthetad
+                  IF (lwp) write (numout,*) 'frn(',jk,')     = ', frn
+                  IF (lwp) write (numout,*) 'frd(',jk,')     = ', frd
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Zooplankton Grazing 
+               !! this code supplements the base grazing model with one that
+               !! considers the C:N ratio of grazed food and balances this against
+               !! the requirements of zooplankton growth; this model is derived 
+               !! from that of Anderson & Pondaven (2003)
+               !!
+               !! the current version of the code assumes a fixed C:N ratio for
+               !! detritus (in contrast to Anderson & Pondaven, 2003), though the
+               !! full equations are retained for future extension
+               !!----------------------------------------------------------------------
+               !!
+               !!----------------------------------------------------------------------
+               !! Microzooplankton first
+               !!----------------------------------------------------------------------
+               !!
+               fmi1    = (xkmi * xkmi) + (xpmipn * zphn * zphn) + (xpmid * zdet * zdet)
+               fmi     = xgmi * zzmi / fmi1
+               fgmipn  = fmi * xpmipn * zphn * zphn   !! grazing on non-diatoms
+               fgmid   = fmi * xpmid  * zdet * zdet   !! grazing on detrital nitrogen
+# if defined key_roam
+               fgmidc  = rsmall !acc
+               IF ( zdet .GT. rsmall ) fgmidc  = (zdtc / (zdet + tiny(zdet))) * fgmid  !! grazing on detrital carbon
+# else
+               !! AXY (26/11/08): implicit detrital carbon change
+               fgmidc  = xthetad * fgmid              !! grazing on detrital carbon
+# endif
+               !!
+               !! which translates to these incoming N and C fluxes
+               finmi   = (1.0 - xphi) * (fgmipn + fgmid)
+               ficmi   = (1.0 - xphi) * ((xthetapn * fgmipn) + fgmidc)
+               !!
+               !! the ideal food C:N ratio for microzooplankton
+               !! xbetan = 0.77; xthetaz = 5.625; xbetac = 0.64; xkc = 0.80
+               fstarmi = (xbetan * xthetazmi) / (xbetac * xkc)
+               !!
+               !! process these to determine proportioning of grazed N and C
+               !! (since there is no explicit consideration of respiration,
+               !! only growth and excretion are calculated here)
+               fmith   = (ficmi / (finmi + tiny(finmi)))
+               if (fmith.ge.fstarmi) then
+                  fmigrow = xbetan * finmi
+                  fmiexcr = 0.0
+               else
+                  fmigrow = (xbetac * xkc * ficmi) / xthetazmi
+                  fmiexcr = ficmi * ((xbetan / (fmith + tiny(fmith))) - ((xbetac * xkc) / xthetazmi))
+               endif
+# if defined key_roam
+               fmiresp = (xbetac * ficmi) - (xthetazmi * fmigrow)
+# endif
+
+# if defined key_debug_medusa
+               !! report microzooplankton grazing
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fmi1(',jk,')    = ', fmi1
+                  IF (lwp) write (numout,*) 'fmi(',jk,')     = ', fmi
+                  IF (lwp) write (numout,*) 'fgmipn(',jk,')  = ', fgmipn
+                  IF (lwp) write (numout,*) 'fgmid(',jk,')   = ', fgmid
+                  IF (lwp) write (numout,*) 'fgmidc(',jk,')  = ', fgmidc
+                  IF (lwp) write (numout,*) 'finmi(',jk,')   = ', finmi
+                  IF (lwp) write (numout,*) 'ficmi(',jk,')   = ', ficmi
+                  IF (lwp) write (numout,*) 'fstarmi(',jk,') = ', fstarmi
+                  IF (lwp) write (numout,*) 'fmith(',jk,')   = ', fmith
+                  IF (lwp) write (numout,*) 'fmigrow(',jk,') = ', fmigrow
+                  IF (lwp) write (numout,*) 'fmiexcr(',jk,') = ', fmiexcr
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'fmiresp(',jk,') = ', fmiresp
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Mesozooplankton second
+               !!----------------------------------------------------------------------
+               !!
+               fme1    = (xkme * xkme) + (xpmepn * zphn * zphn) + (xpmepd * zphd * zphd) + & 
+                         (xpmezmi * zzmi * zzmi) + (xpmed * zdet * zdet)
+               fme     = xgme * zzme / fme1
+               fgmepn  = fme * xpmepn  * zphn * zphn  !! grazing on non-diatoms
+               fgmepd  = fme * xpmepd  * zphd * zphd  !! grazing on diatoms
+               fgmepds = fsin * fgmepd                !! grazing on diatom silicon
+               fgmezmi = fme * xpmezmi * zzmi * zzmi  !! grazing on microzooplankton
+               fgmed   = fme * xpmed   * zdet * zdet  !! grazing on detrital nitrogen
+# if defined key_roam
+               fgmedc  = rsmall !acc
+               IF ( zdet .GT. rsmall ) fgmedc  = (zdtc / (zdet + tiny(zdet))) * fgmed  !! grazing on detrital carbon
+# else
+               !! AXY (26/11/08): implicit detrital carbon change
+               fgmedc  = xthetad * fgmed              !! grazing on detrital carbon
+# endif
+               !!
+               !! which translates to these incoming N and C fluxes
+               finme   = (1.0 - xphi) * (fgmepn + fgmepd + fgmezmi + fgmed)
+               ficme   = (1.0 - xphi) * ((xthetapn * fgmepn) + (xthetapd * fgmepd) + &
+                        (xthetazmi * fgmezmi) + fgmedc)
+               !!
+               !! the ideal food C:N ratio for mesozooplankton
+               !! xbetan = 0.77; xthetaz = 5.625; xbetac = 0.64; xkc = 0.80
+               fstarme = (xbetan * xthetazme) / (xbetac * xkc)
+               !!
+               !! process these to determine proportioning of grazed N and C
+               !! (since there is no explicit consideration of respiration,
+               !! only growth and excretion are calculated here)
+               fmeth   = (ficme / (finme + tiny(finme)))
+               if (fmeth.ge.fstarme) then
+                  fmegrow = xbetan * finme
+                  fmeexcr = 0.0
+               else
+                  fmegrow = (xbetac * xkc * ficme) / xthetazme
+                  fmeexcr = ficme * ((xbetan / (fmeth + tiny(fmeth))) - ((xbetac * xkc) / xthetazme))
+               endif
+# if defined key_roam
+               fmeresp = (xbetac * ficme) - (xthetazme * fmegrow)
+# endif
+
+# if defined key_debug_medusa
+               !! report mesozooplankton grazing
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fme1(',jk,')    = ', fme1
+                  IF (lwp) write (numout,*) 'fme(',jk,')     = ', fme
+                  IF (lwp) write (numout,*) 'fgmepn(',jk,')  = ', fgmepn
+                  IF (lwp) write (numout,*) 'fgmepd(',jk,')  = ', fgmepd
+                  IF (lwp) write (numout,*) 'fgmepds(',jk,') = ', fgmepds
+                  IF (lwp) write (numout,*) 'fgmezmi(',jk,') = ', fgmezmi
+                  IF (lwp) write (numout,*) 'fgmed(',jk,')   = ', fgmed
+                  IF (lwp) write (numout,*) 'fgmedc(',jk,')  = ', fgmedc
+                  IF (lwp) write (numout,*) 'finme(',jk,')   = ', finme
+                  IF (lwp) write (numout,*) 'ficme(',jk,')   = ', ficme
+                  IF (lwp) write (numout,*) 'fstarme(',jk,') = ', fstarme
+                  IF (lwp) write (numout,*) 'fmeth(',jk,')   = ', fmeth
+                  IF (lwp) write (numout,*) 'fmegrow(',jk,') = ', fmegrow
+                  IF (lwp) write (numout,*) 'fmeexcr(',jk,') = ', fmeexcr
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'fmeresp(',jk,') = ', fmeresp
+#  endif
+               endif
+# endif
+
+               fzmi_i(ji,jj)  = fzmi_i(ji,jj)  + fthk * (  &
+                  fgmipn + fgmid )
+               fzmi_o(ji,jj)  = fzmi_o(ji,jj)  + fthk * (  &
+                  fmigrow + (xphi * (fgmipn + fgmid)) + fmiexcr + ((1.0 - xbetan) * finmi) )
+               fzme_i(ji,jj)  = fzme_i(ji,jj)  + fthk * (  &
+                  fgmepn + fgmepd + fgmezmi + fgmed )
+               fzme_o(ji,jj)  = fzme_o(ji,jj)  + fthk * (  &
+                  fmegrow + (xphi * (fgmepn + fgmepd + fgmezmi + fgmed)) + fmeexcr + ((1.0 - xbetan) * finme) )
+
+               !!----------------------------------------------------------------------
+               !! Plankton metabolic losses
+               !! Linear loss processes assumed to be metabolic in origin
+               !!----------------------------------------------------------------------
+               !!
+               fdpn2  = xmetapn  * zphn
+               fdpd2  = xmetapd  * zphd
+               fdpds2 = xmetapd  * zpds
+               fdzmi2 = xmetazmi * zzmi
+               fdzme2 = xmetazme * zzme
+
+               !!----------------------------------------------------------------------
+               !! Plankton mortality losses
+               !! EKP (26/02/09): phytoplankton hyperbolic mortality term introduced 
+               !! to improve performance in gyres
+               !!----------------------------------------------------------------------
+               !!
+               !! non-diatom phytoplankton
+               if (jmpn.eq.1) fdpn = xmpn * zphn               !! linear
+               if (jmpn.eq.2) fdpn = xmpn * zphn * zphn        !! quadratic
+               if (jmpn.eq.3) fdpn = xmpn * zphn * &           !! hyperbolic
+                  (zphn / (xkphn + zphn))
+               if (jmpn.eq.4) fdpn = xmpn * zphn * &           !! sigmoid
+                  ((zphn * zphn) / (xkphn + (zphn * zphn)))
+               !!
+               !! diatom phytoplankton
+               if (jmpd.eq.1) fdpd = xmpd * zphd               !! linear
+               if (jmpd.eq.2) fdpd = xmpd * zphd * zphd        !! quadratic
+               if (jmpd.eq.3) fdpd = xmpd * zphd * &           !! hyperbolic
+                  (zphd / (xkphd + zphd))
+               if (jmpd.eq.4) fdpd = xmpd * zphd * &           !! sigmoid
+                  ((zphd * zphd) / (xkphd + (zphd * zphd)))
+               fdpds = fdpd * fsin
+               !!
+               !! microzooplankton
+               if (jmzmi.eq.1) fdzmi = xmzmi * zzmi            !! linear
+               if (jmzmi.eq.2) fdzmi = xmzmi * zzmi * zzmi     !! quadratic
+               if (jmzmi.eq.3) fdzmi = xmzmi * zzmi * &        !! hyperbolic
+                  (zzmi / (xkzmi + zzmi))
+               if (jmzmi.eq.4) fdzmi = xmzmi * zzmi * &        !! sigmoid
+                  ((zzmi * zzmi) / (xkzmi + (zzmi * zzmi)))
+               !!
+               !! mesozooplankton
+               if (jmzme.eq.1) fdzme = xmzme * zzme            !! linear
+               if (jmzme.eq.2) fdzme = xmzme * zzme * zzme     !! quadratic
+               if (jmzme.eq.3) fdzme = xmzme * zzme * &        !! hyperbolic
+                  (zzme / (xkzme + zzme))
+               if (jmzme.eq.4) fdzme = xmzme * zzme * &        !! sigmoid
+                  ((zzme * zzme) / (xkzme + (zzme * zzme)))
+
+               !!----------------------------------------------------------------------
+               !! Detritus remineralisation
+               !! Constant or temperature-dependent
+               !!----------------------------------------------------------------------
+               !!
+               if (jmd.eq.1) then
+                  !! temperature-dependent
+                  fdd  = xmd  * fun_T * zdet
+# if defined key_roam
+                  fddc = xmdc * fun_T * zdtc
+# endif
+               elseif (jmd.eq.2) then
+                  !! AXY (16/05/13): add in Q10-based parameterisation (def in nmlst)
+                  !! temperature-dependent
+                  fdd  = xmd  * fun_Q10 * zdet
+#if defined key_roam
+                  fddc = xmdc * fun_Q10 * zdtc
+#endif
+               else
+                  !! temperature-independent
+                  fdd  = xmd  * zdet
+# if defined key_roam
+                  fddc = xmdc * zdtc
+# endif
+               endif
+               !!
+               !! AXY (22/07/09): accelerate detrital remineralisation in the bottom box
+               if ((jk.eq.jmbathy) .and. jsfd.eq.1) then
+                  fdd  = 1.0  * zdet
+# if defined key_roam
+                  fddc = 1.0  * zdtc
+# endif
+               endif
+               
+# if defined key_debug_medusa
+               !! report plankton mortality and remineralisation
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fdpn2(',jk,') = ', fdpn2
+                  IF (lwp) write (numout,*) 'fdpd2(',jk,') = ', fdpd2
+                  IF (lwp) write (numout,*) 'fdpds2(',jk,')= ', fdpds2
+                  IF (lwp) write (numout,*) 'fdzmi2(',jk,')= ', fdzmi2
+                  IF (lwp) write (numout,*) 'fdzme2(',jk,')= ', fdzme2
+                  IF (lwp) write (numout,*) 'fdpn(',jk,')  = ', fdpn
+                  IF (lwp) write (numout,*) 'fdpd(',jk,')  = ', fdpd
+                  IF (lwp) write (numout,*) 'fdpds(',jk,') = ', fdpds
+                  IF (lwp) write (numout,*) 'fdzmi(',jk,') = ', fdzmi
+                  IF (lwp) write (numout,*) 'fdzme(',jk,') = ', fdzme
+                  IF (lwp) write (numout,*) 'fdd(',jk,')   = ', fdd
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'fddc(',jk,')  = ', fddc
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Detritus addition to benthos
+               !! If activated, slow detritus in the bottom box will enter the
+               !! benthic pool
+               !!----------------------------------------------------------------------
+               !!
+               if ((jk.eq.jmbathy) .and. jorgben.eq.1) then
+                  !! this is the BOTTOM OCEAN BOX -> into the benthic pool!
+                  !!
+                  f_sbenin_n(ji,jj)  = (zdet * vsed * 86400.)
+                  f_sbenin_fe(ji,jj) = (zdet * vsed * 86400. * xrfn)
+# if defined key_roam
+                  f_sbenin_c(ji,jj)  = (zdtc * vsed * 86400.)
+# else
+                  f_sbenin_c(ji,jj)  = (zdet * vsed * 86400. * xthetad)
+# endif
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Iron chemistry and fractionation
+               !! following the Parekh et al. (2004) scheme adopted by the Met.
+               !! Office, Medusa models total iron but considers "free" and
+               !! ligand-bound forms for the purposes of scavenging (only "free"
+               !! iron can be scavenged
+               !!----------------------------------------------------------------------
+               !!
+               !! total iron concentration (mmol Fe / m3 -> umol Fe / m3)
+               xFeT        = zfer * 1.e3
+               !!
+               !! calculate fractionation (based on Diat-HadOCC; in turn based on Parekh et al., 2004)
+               xb_coef_tmp = xk_FeL * (xLgT - xFeT) - 1.0
+               xb2M4ac     = max(((xb_coef_tmp * xb_coef_tmp) + (4.0 * xk_FeL * xLgT)), 0.0)
+               !!
+               !! "free" ligand concentration
+               xLgF        = 0.5 * (xb_coef_tmp + (xb2M4ac**0.5)) / xk_FeL
+               !!
+               !! ligand-bound iron concentration
+               xFeL        = xLgT - xLgF
+               !!
+               !! "free" iron concentration (and convert to mmol Fe / m3)
+               xFeF        = (xFeT - xFeL) * 1.e-3
+               xFree(ji,jj)= xFeF / (zfer + tiny(zfer))
+               !!
+               !! scavenging of iron (multiple schemes); I'm only really happy with the 
+               !! first one at the moment - the others involve assumptions (sometimes
+               !! guessed at by me) that are potentially questionable
+               !!
+               if (jiron.eq.1) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 1: Dutkiewicz et al. (2005)
+                  !! This scheme includes a single scavenging term based solely on a
+                  !! fixed rate and the availablility of "free" iron
+                  !!----------------------------------------------------------------------
+                  !!
+                  ffescav     = xk_sc_Fe * xFeF                     ! = mmol/m3/d
+                  !!
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! Mick's code contains a further (optional) implicit "scavenging" of 
+                  !! iron that sets an upper bound on "free" iron concentration, and 
+                  !! essentially caps the concentration of total iron as xFeL + "free" 
+                  !! iron; since the former is constrained by a fixed total ligand 
+                  !! concentration (= 1.0 umol/m3), and the latter isn't allowed above 
+                  !! this upper bound, total iron is constrained to a maximum of ...
+                  !!
+                  !!    xFeL + min(xFeF, 0.3 umol/m3) = 1.0 + 0.3 = 1.3 umol / m3
+                  !! 
+                  !! In Mick's code, the actual value of total iron is reset to this
+                  !! sum (i.e. TFe = FeL + Fe'; but Fe' <= 0.3 umol/m3); this isn't
+                  !! our favoured approach to tracer updating here (not least because
+                  !! of the leapfrog), so here the amount scavenged is augmented by an
+                  !! additional amount that serves to drag total iron back towards that
+                  !! expected from this limitation on iron concentration ...
+                  !!
+                  xmaxFeF     = min((xFeF * 1.e3), 0.3)             ! = umol/m3
+                  !!
+                  !! Here, the difference between current total Fe and (FeL + Fe') is
+                  !! calculated and added to the scavenging flux already calculated
+                  !! above ...
+                  !!
+                  fdeltaFe    = (xFeT - (xFeL + xmaxFeF)) * 1.e-3   ! = mmol/m3
+                  !!
+                  !! This assumes that the "excess" iron is dissipated with a time-
+                  !! scale of 1 day; seems reasonable to me ... (famous last words)
+                  !!
+                  ffescav     = ffescav + fdeltaFe                  ! = mmol/m3/d
+                  !!
+# if defined key_deep_fe_fix
+                  !! AXY (17/01/13)
+                  !! stop scavenging for iron concentrations below 0.5 umol / m3
+                  !! at depths greater than 1000 m; this aims to end MEDUSA's
+                  !! continual loss of iron at depth without impacting things
+                  !! at the surface too much; the justification for this is that
+                  !! it appears to be what Mick Follows et al. do in their work
+                  !! (as evidenced by the iron initial condition they supplied
+                  !! me with); to be honest, it looks like Follow et al. do this
+                  !! at shallower depths than 1000 m, but I'll stick with this
+                  !! for now; I suspect that this seemingly arbitrary approach
+                  !! effectively "parameterises" the particle-based scavenging
+                  !! rates that other models use (i.e. at depth there are no
+                  !! sinking particles, so scavenging stops); it might be fun
+                  !! justifying this in a paper though!
+                  !!
+                  if ((fdep.gt.1000.) .and. (xFeT.lt.0.5)) then
+                     ffescav = 0.
+                  endif
+# endif
+                  !!
+               elseif (jiron.eq.2) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 2: Moore et al. (2004)
+                  !! This scheme includes a single scavenging term that accounts for
+                  !! both suspended and sinking particles in the water column; this
+                  !! term scavenges total iron rather than "free" iron
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! total iron concentration (mmol Fe / m3 -> umol Fe / m3)
+                  xFeT        = zfer * 1.e3
+                  !!
+                  !! this has a base scavenging rate (12% / y) which is modified by local
+                  !! particle concentration and sinking flux (and dust - but I'm ignoring
+                  !! that here for now) and which is accelerated when Fe concentration gets
+                  !! 0.6 nM (= 0.6 umol/m3 = 0.0006 mmol/m3), and decreased as concentrations
+                  !! below 0.4 nM (= 0.4 umol/m3 = 0.0004 mmol/m3)
+                  !!
+                  !! base scavenging rate (0.12 / y)
+                  fbase_scav = 0.12 / 365.25
+                  !!
+                  !! calculate sinking particle part of scaling factor
+                  !! this takes local fast sinking carbon (mmol C / m2 / d) and
+                  !! gets it into nmol C / cm3 / s ("rdt" below is the number of seconds in
+                  !! a model timestep)
+                  !!
+                  !! fscal_sink = ffastc(ji,jj) * 1.e2 / (86400.)
+                  !!
+                  !! ... actually, re-reading Moore et al.'s equations, it looks like he uses
+                  !! his sinking flux directly, without scaling it by time-step or anything,
+                  !! so I'll copy this here ...
+                  !!
+                  fscal_sink = ffastc(ji,jj) * 1.e2
+                  !!
+                  !! calculate particle part of scaling factor
+                  !! this totals up the carbon in suspended particles (Pn, Pd, Zmi, Zme, D),
+                  !! which comes out in mmol C / m3 (= nmol C / cm3), and then multiplies it
+                  !! by a magic factor, 0.002, to get it into nmol C / cm2 / s
+                  !!
+                  fscal_part = ((xthetapn * zphn) + (xthetapd * zphd) + (xthetazmi * zzmi) + &
+                  (xthetazme * zzme) + (xthetad * zdet)) * 0.002
+                  !!
+                  !! calculate scaling factor for base scavenging rate
+                  !! this uses the (now correctly scaled) sinking flux and standing
+                  !! particle concentration, divides through by some sort of reference
+                  !! value (= 0.0066 nmol C / cm2 / s) and then uses this, or not if its
+                  !! too high, to rescale the base scavenging rate
+                  !!
+                  fscal_scav = fbase_scav * min(((fscal_sink + fscal_part) / 0.0066), 4.0)
+                  !!
+                  !! the resulting scavenging rate is then scaled further according to the
+                  !! local iron concentration (i.e. diminished in low iron regions; enhanced
+                  !! in high iron regions; less alone in intermediate iron regions)
+                  !!
+                  if (xFeT.lt.0.4) then
+                     !!
+                     !! low iron region
+                     !!
+                     fscal_scav = fscal_scav * (xFeT / 0.4)
+                     !!
+                  elseif (xFeT.gt.0.6) then
+                     !!
+                     !! high iron region
+                     !!
+                     fscal_scav = fscal_scav + ((xFeT / 0.6) * (6.0 / 1.4))
+                     !!
+                  else
+                     !!
+                     !! intermediate iron region: do nothing
+                     !!
+                  endif
+                  !! 
+                  !! apply the calculated scavenging rate ...
+                  !!
+                  ffescav = fscal_scav * zfer
+                  !!
+               elseif (jiron.eq.3) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 3: Moore et al. (2008)
+                  !! This scheme includes a single scavenging term that accounts for
+                  !! sinking particles in the water column, and includes organic C,
+                  !! biogenic opal, calcium carbonate and dust in this (though the
+                  !! latter is ignored here until I work out what units the incoming
+                  !! "dust" flux is in); this term scavenges total iron rather than 
+                  !! "free" iron
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! total iron concentration (mmol Fe / m3 -> umol Fe / m3)
+                  xFeT        = zfer * 1.e3
+                  !!
+                  !! this has a base scavenging rate which is modified by local
+                  !! particle sinking flux (including dust - but I'm ignoring that 
+                  !! here for now) and which is accelerated when Fe concentration
+                  !! is > 0.6 nM (= 0.6 umol/m3 = 0.0006 mmol/m3), and decreased as 
+                  !! concentrations < 0.5 nM (= 0.5 umol/m3 = 0.0005 mmol/m3)
+                  !!
+                  !! base scavenging rate (Fe_b in paper; units may be wrong there)
+                  fbase_scav = 0.00384 ! (ng)^-1 cm
+                  !!
+                  !! calculate sinking particle part of scaling factor; this converts
+                  !! mmol / m2 / d fluxes of organic carbon, silicon and calcium
+                  !! carbonate into ng / cm2 / s fluxes; it is assumed here that the
+                  !! mass conversions simply consider the mass of the main element
+                  !! (C, Si and Ca) and *not* the mass of the molecules that they are
+                  !! part of; Moore et al. (2008) is unclear on the conversion that
+                  !! should be used
+                  !!
+                  !! milli -> nano; mol -> gram; /m2 -> /cm2; /d -> /s
+                  fscal_csink  = (ffastc(ji,jj)  * 1.e6 * xmassc  * 1.e-4 / 86400.)      ! ng C  / cm2 / s
+                  fscal_sisink = (ffastsi(ji,jj) * 1.e6 * xmasssi * 1.e-4 / 86400.)      ! ng Si / cm2 / s
+                  fscal_casink = (ffastca(ji,jj) * 1.e6 * xmassca * 1.e-4 / 86400.)      ! ng Ca / cm2 / s
+                  !! 
+                  !! sum up these sinking fluxes and convert to ng / cm by dividing
+                  !! through by a sinking rate of 100 m / d = 1.157 cm / s
+                  fscal_sink   = ((fscal_csink * 6.) + fscal_sisink + fscal_casink) / &
+                  (100. * 1.e3 / 86400)                                                  ! ng / cm
+                  !!
+                  !! now calculate the scavenging rate based upon the base rate and
+                  !! this particle flux scaling; according to the published units,
+                  !! the result actually has *no* units, but as it must be expressed
+                  !! per unit time for it to make any sense, I'm assuming a missing
+                  !! "per second"
+                  fscal_scav = fbase_scav * fscal_sink                                   ! / s
+                  !!
+                  !! the resulting scavenging rate is then scaled further according to the
+                  !! local iron concentration (i.e. diminished in low iron regions; enhanced
+                  !! in high iron regions; less alone in intermediate iron regions)
+                  !!
+                  if (xFeT.lt.0.5) then
+                     !!
+                     !! low iron region (0.5 instead of the 0.4 in Moore et al., 2004)
+                     !!
+                     fscal_scav = fscal_scav * (xFeT / 0.5)
+                     !!
+                  elseif (xFeT.gt.0.6) then
+                     !!
+                     !! high iron region (functional form different in Moore et al., 2004)
+                     !!
+                     fscal_scav = fscal_scav + ((xFeT - 0.6) * 0.00904)
+                     !!
+                  else
+                     !!
+                     !! intermediate iron region: do nothing
+                     !!
+                  endif
+                  !! 
+                  !! apply the calculated scavenging rate ...
+                  !!
+                  ffescav = fscal_scav * zfer
+                  !!
+               elseif (jiron.eq.4) then
+                  !!----------------------------------------------------------------------
+                  !! Scheme 4: Galbraith et al. (2010)
+                  !! This scheme includes two scavenging terms, one for organic,
+                  !! particle-based scavenging, and another for inorganic scavenging;
+                  !! both terms scavenge "free" iron only
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! Galbraith et al. (2010) present a more straightforward outline of 
+                  !! the scheme in Parekh et al. (2005) ...
+                  !! 
+                  !! sinking particulate carbon available for scavenging
+                  !! this assumes a sinking rate of 100 m / d (Moore & Braucher, 2008),
+                  xCscav1     = (ffastc(ji,jj) * xmassc) / 100. ! = mg C / m3
+                  !! 
+                  !! scale by Honeyman et al. (1981) exponent coefficient
+                  !! multiply by 1.e-3 to express C flux in g C rather than mg C
+                  xCscav2     = (xCscav1 * 1.e-3)**0.58
+                  !!
+                  !! multiply by Galbraith et al. (2010) scavenging rate
+                  xk_org      = 0.5 ! ((g C m/3)^-1) / d
+                  xORGscav    = xk_org * xCscav2 * xFeF
+                  !!
+                  !! Galbraith et al. (2010) also include an inorganic bit ...
+                  !! 
+                  !! this occurs at a fixed rate, again based on the availability of
+                  !! "free" iron
+                  !!
+                  !! k_inorg  = 1000 d**-1 nmol Fe**-0.5 kg**-0.5
+                  !!
+                  !! to implement this here, scale xFeF by 1026 to put in units of
+                  !! umol/m3 which approximately equal nmol/kg
+                  !!
+                  xk_inorg    = 1000. ! ((nmol Fe / kg)^1.5)
+                  xINORGscav  = (xk_inorg * (xFeF * 1026.)**1.5) * 1.e-3
+                  !!
+                  !! sum these two terms together
+                  ffescav     = xORGscav + xINORGscav
+               else
+                  !!----------------------------------------------------------------------
+                  !! No Scheme: you coward!
+                  !! This scheme puts its head in the sand and eskews any decision about
+                  !! how iron is removed from the ocean; prepare to get deluged in iron
+                  !! you fool!
+                  !!----------------------------------------------------------------------
+                  ffescav     = 0.
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Other iron cycle processes
+               !!----------------------------------------------------------------------
+               !!
+               !! aeolian iron deposition
+               if (jk.eq.1) then
+                  !! zirondep   is in mmol-Fe / m2 / day
+                  !! ffetop     is in mmol-dissolved-Fe / m3 / day
+                  ffetop  = zirondep(ji,jj) * xfe_sol / fthk 
+               else
+                  ffetop  = 0.0
+               endif
+               !!
+               !! seafloor iron addition
+               !! AXY (10/07/12): amended to only apply sedimentary flux up to ~500 m down
+               !! if (jk.eq.(mbathy(ji,jj)-1).AND.jk.lt.i1100) then
+               if ((jk.eq.jmbathy).AND.jk.le.i0500) then
+                  !! Moore et al. (2004) cite a coastal California value of 5 umol/m2/d, but adopt a
+                  !! global value of 2 umol/m2/d for all areas < 1100 m; here we use this latter value
+                  !! but apply it everywhere
+                  !! AXY (21/07/09): actually, let's just apply it below 1100 m (levels 1-37)
+                  ffebot  = (xfe_sed / fthk)
+               else
+                  ffebot  = 0.0
+               endif
+
+               !! AXY (16/12/09): remove iron addition/removal processes
+               !! For the purposes of the quarter degree run, the iron cycle is being pegged to the
+               !! initial condition supplied by Mick Follows via restoration with a 30 day period;
+               !! iron addition at the seafloor is still permitted with the idea that this extra
+               !! iron will be removed by the restoration away from the source
+               !! ffescav = 0.0
+               !! ffetop  = 0.0
+               !! ffebot  = 0.0
+
+# if defined key_debug_medusa
+               !! report miscellaneous calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'xfe_sol  = ', xfe_sol
+                  IF (lwp) write (numout,*) 'xfe_mass = ', xfe_mass
+                  IF (lwp) write (numout,*) 'ffetop(',jk,')  = ', ffetop
+                  IF (lwp) write (numout,*) 'ffebot(',jk,')  = ', ffebot
+                  IF (lwp) write (numout,*) 'xFree(',jk,')   = ', xFree(ji,jj)
+                  IF (lwp) write (numout,*) 'ffescav(',jk,') = ', ffescav
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Miscellaneous
+               !!----------------------------------------------------------------------
+               !!
+               !! diatom frustule dissolution
+               fsdiss  = xsdiss * zpds
+
+# if defined key_debug_medusa
+               !! report miscellaneous calculations
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fsdiss(',jk,')  = ', fsdiss
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Slow detritus creation
+               !!----------------------------------------------------------------------
+               !! this variable integrates the creation of slow sinking detritus
+               !! to allow the split between fast and slow detritus to be 
+               !! diagnosed
+               fslown  = fdpn + fdzmi + ((1.0 - xfdfrac1) * fdpd) + &
+               ((1.0 - xfdfrac2) * fdzme) + ((1.0 - xbetan) * (finmi + finme))
+               !!
+               !! this variable records the slow detrital sinking flux at this
+               !! particular depth; it is used in the output of this flux at
+               !! standard depths in the diagnostic outputs; needs to be
+               !! adjusted from per second to per day because of parameter vsed
+               fslownflux(ji,jj) = zdet * vsed * 86400.
+# if defined key_roam
+               !!
+               !! and the same for detrital carbon
+               fslowc  = (xthetapn * fdpn) + (xthetazmi * fdzmi) + &
+               (xthetapd * (1.0 - xfdfrac1) * fdpd) + &
+               (xthetazme * (1.0 - xfdfrac2) * fdzme) + &
+               ((1.0 - xbetac) * (ficmi + ficme))
+               !!
+               !! this variable records the slow detrital sinking flux at this
+               !! particular depth; it is used in the output of this flux at
+               !! standard depths in the diagnostic outputs; needs to be
+               !! adjusted from per second to per day because of parameter vsed
+               fslowcflux(ji,jj) = zdtc * vsed * 86400.
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Nutrient regeneration
+               !! this variable integrates total nitrogen regeneration down the
+               !! watercolumn; its value is stored and output as a 2D diagnostic;
+               !! the corresponding dissolution flux of silicon (from sources
+               !! other than fast detritus) is also integrated; note that,
+               !! confusingly, the linear loss terms from plankton compartments
+               !! are labelled as fdX2 when one might have expected fdX or fdX1
+               !!----------------------------------------------------------------------
+               !!
+               !! nitrogen
+               fregen   = (( (xphi * (fgmipn + fgmid)) +                &  ! messy feeding
+               (xphi * (fgmepn + fgmepd + fgmezmi + fgmed)) +           &  ! messy feeding
+               fmiexcr + fmeexcr + fdd +                                &  ! excretion + D remin.
+               fdpn2 + fdpd2 + fdzmi2 + fdzme2) * fthk)                    ! linear mortality
+               !!
+               !! silicon
+               fregensi = (( fsdiss + ((1.0 - xfdfrac1) * fdpds) +      &  ! dissolution + non-lin. mortality
+               ((1.0 - xfdfrac3) * fgmepds) +                           &  ! egestion by zooplankton
+               fdpds2) * fthk)                                             ! linear mortality
+# if defined key_roam
+               !!
+               !! carbon
+               fregenc  = (( (xphi * ((xthetapn * fgmipn) + fgmidc)) +  &  ! messy feeding
+               (xphi * ((xthetapn * fgmepn) + (xthetapd * fgmepd) +     &  ! messy feeding
+               (xthetazmi * fgmezmi) + fgmedc)) +                       &  ! messy feeding
+               fmiresp + fmeresp + fddc +                               &  ! respiration + D remin.
+               (xthetapn * fdpn2) + (xthetapd * fdpd2) +                &  ! linear mortality
+               (xthetazmi * fdzmi2) + (xthetazme * fdzme2)) * fthk)        ! linear mortality
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Fast-sinking detritus terms
+               !! "local" variables declared so that conservation can be checked;
+               !! the calculated terms are added to the fast-sinking flux later on
+               !! only after the flux entering this level has experienced some
+               !! remineralisation
+               !! note: these fluxes need to be scaled by the level thickness
+               !!----------------------------------------------------------------------
+               !!
+               !! nitrogen:   diatom and mesozooplankton mortality
+               ftempn         = b0 * ((xfdfrac1 * fdpd)  + (xfdfrac2 * fdzme))
+               !!
+               !! silicon:    diatom mortality and grazed diatoms
+               ftempsi        = b0 * ((xfdfrac1 * fdpds) + (xfdfrac3 * fgmepds))
+               !!
+               !! iron:       diatom and mesozooplankton mortality
+               ftempfe        = b0 * (((xfdfrac1 * fdpd) + (xfdfrac2 * fdzme)) * xrfn)
+               !!
+               !! carbon:     diatom and mesozooplankton mortality
+               ftempc         = b0 * ((xfdfrac1 * xthetapd * fdpd) + & 
+                                (xfdfrac2 * xthetazme * fdzme))
+               !!
+# if defined key_roam
+               if (jrratio.eq.0) then
+                  !! CaCO3:      latitudinally-based fraction of total primary production
+                  !!               absolute latitude of current grid cell
+                  flat           = abs(gphit(ji,jj))
+                  !!               0.10 at equator; 0.02 at pole
+                  fcaco3         = xcaco3a + ((xcaco3b - xcaco3a) * ((90.0 - flat) / 90.0))
+               elseif (jrratio.eq.1) then
+                  !! CaCO3:      Ridgwell et al. (2007) submodel, version 1
+                  !!             this uses SURFACE omega calcite to regulate rain ratio
+                  if (f_omcal(ji,jj).ge.1.0) then
+                     fq1 = (f_omcal(ji,jj) - 1.0)**0.81
+                  else
+                     fq1 = 0.
+                  endif
+                  fcaco3 = xridg_r0 * fq1
+               elseif (jrratio.eq.2) then
+                  !! CaCO3:      Ridgwell et al. (2007) submodel, version 2
+                  !!             this uses FULL 3D omega calcite to regulate rain ratio
+                  if (f3_omcal(ji,jj,jk).ge.1.0) then
+                     fq1 = (f3_omcal(ji,jj,jk) - 1.0)**0.81
+                  else
+                     fq1 = 0.
+                  endif
+                  fcaco3 = xridg_r0 * fq1
+               endif
+# else
+               !! CaCO3:      latitudinally-based fraction of total primary production
+               !!               absolute latitude of current grid cell
+               flat           = abs(gphit(ji,jj))
+               !!               0.10 at equator; 0.02 at pole
+               fcaco3         = xcaco3a + ((xcaco3b - xcaco3a) * ((90.0 - flat) / 90.0))
+# endif
+               !! AXY (09/03/09): convert CaCO3 production from function of 
+               !! primary production into a function of fast-sinking material; 
+               !! technically, this is what Dunne et al. (2007) do anyway; they 
+               !! convert total primary production estimated from surface 
+               !! chlorophyll to an export flux for which they apply conversion 
+               !! factors to estimate the various elemental fractions (Si, Ca)
+               ftempca        = ftempc * fcaco3
+
+# if defined key_debug_medusa
+               !! integrate total fast detritus production
+               if (idf.eq.1) then
+                  fifd_n(ji,jj)  = fifd_n(ji,jj)  + (ftempn  * fthk)
+                  fifd_si(ji,jj) = fifd_si(ji,jj) + (ftempsi * fthk)
+                  fifd_fe(ji,jj) = fifd_fe(ji,jj) + (ftempfe * fthk)
+#  if defined key_roam
+                  fifd_c(ji,jj)  = fifd_c(ji,jj)  + (ftempc  * fthk)
+#  endif
+               endif
+
+               !! report quantities of fast-sinking detritus for each component
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'fdpd(',jk,')    = ', fdpd
+                  IF (lwp) write (numout,*) 'fdzme(',jk,')   = ', fdzme
+                  IF (lwp) write (numout,*) 'ftempn(',jk,')  = ', ftempn
+                  IF (lwp) write (numout,*) 'ftempsi(',jk,') = ', ftempsi
+                  IF (lwp) write (numout,*) 'ftempfe(',jk,') = ', ftempfe
+                  IF (lwp) write (numout,*) 'ftempc(',jk,')  = ', ftempc
+                  IF (lwp) write (numout,*) 'ftempca(',jk,') = ', ftempca
+                  IF (lwp) write (numout,*) 'flat(',jk,')    = ', flat
+                  IF (lwp) write (numout,*) 'fcaco3(',jk,')  = ', fcaco3
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! This version of MEDUSA offers a choice of three methods for
+               !! handling the remineralisation of fast detritus.  All three
+               !! do so in broadly the same way:
+               !!
+               !!   1.  Fast detritus is stored as a 2D array                   [ ffastX  ]
+               !!   2.  Fast detritus is added level-by-level                   [ ftempX  ]
+               !!   3.  Fast detritus is not remineralised in the top box       [ freminX ]
+               !!   4.  Remaining fast detritus is remineralised in the bottom  [ fsedX   ]
+               !!       box
+               !!
+               !! The three remineralisation methods are:
+               !!   
+               !!   1.  Ballast model (i.e. that published in Yool et al., 2011)
+               !!  (1b. Ballast-sans-ballast model)
+               !!   2.  Martin et al. (1987)
+               !!   3.  Henson et al. (2011)
+               !! 
+               !! The first of these couples C, N and Fe remineralisation to
+               !! the remineralisation of particulate Si and CaCO3, but the 
+               !! latter two treat remineralisation of C, N, Fe, Si and CaCO3
+               !! completely separately.  At present a switch within the code
+               !! regulates which submodel is used, but this should be moved
+               !! to the namelist file.
+               !! 
+               !! The ballast-sans-ballast submodel is an original development
+               !! feature of MEDUSA in which the ballast submodel's general
+               !! framework and parameterisation is used, but in which there
+               !! is no protection of organic material afforded by ballasting
+               !! minerals.  While similar, it is not the same as the Martin 
+               !! et al. (1987) submodel.
+               !!
+               !! Since the three submodels behave the same in terms of
+               !! accumulating sinking material and remineralising it all at
+               !! the seafloor, these portions of the code below are common to
+               !! all three.
+               !!----------------------------------------------------------------------
+
+               if (jexport.eq.1) then
+                  !!======================================================================
+                  !! BALLAST SUBMODEL
+                  !!======================================================================
+                  !! 
+                  !!----------------------------------------------------------------------
+                  !! Fast-sinking detritus fluxes, pt. 1: REMINERALISATION
+                  !! aside from explicitly modelled, slow-sinking detritus, the
+                  !! model includes an implicit representation of detrital
+                  !! particles that sink too quickly to be modelled with
+                  !! explicit state variables; this sinking flux is instead
+                  !! instantaneously remineralised down the water column using
+                  !! the version of Armstrong et al. (2002)'s ballast model
+                  !! used by Dunne et al. (2007); the version of this model
+                  !! here considers silicon and calcium carbonate ballast
+                  !! minerals; this section of the code redistributes the fast
+                  !! sinking material generated locally down the water column;
+                  !! this differs from Dunne et al. (2007) in that fast sinking
+                  !! material is distributed at *every* level below that it is
+                  !! generated, rather than at every level below some fixed
+                  !! depth; this scheme is also different in that sinking material 
+                  !! generated in one level is aggregated with that generated by
+                  !! shallower levels; this should make the ballast model more
+                  !! self-consistent (famous last words)
+                  !!----------------------------------------------------------------------
+                  !!
+                  if (jk.eq.1) then
+                     !! this is the SURFACE OCEAN BOX (no remineralisation)
+                     !!
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0
+                  elseif (jk.le.jmbathy) then
+                     !! this is an OCEAN BOX (remineralise some material)
+                     !!
+                     !! set up CCD depth to be used depending on user choice
+                     if (jocalccd.eq.0) then
+                        !! use default CCD field
+                        fccd_dep = ocal_ccd(ji,jj)
+                     elseif (jocalccd.eq.1) then
+                        !! use calculated CCD field
+                        fccd_dep = f2_ccd_cal(ji,jj)
+                     endif
+                     !!
+                     !! === organic carbon ===
+                     fq0      = ffastc(ji,jj)                        !! how much organic C enters this box        (mol)
+                     if (iball.eq.1) then
+                        fq1      = (fq0 * xmassc)                    !! how much it weighs                        (mass)
+                        fq2      = (ffastca(ji,jj) * xmassca)        !! how much CaCO3 enters this box            (mass)
+                        fq3      = (ffastsi(ji,jj) * xmasssi)        !! how much  opal enters this box            (mass)
+                        fq4      = (fq2 * xprotca) + (fq3 * xprotsi) !! total protected organic C                 (mass)
+                        !! this next term is calculated for C but used for N and Fe as well
+                        !! it needs to be protected in case ALL C is protected
+                        if (fq4.lt.fq1) then
+                           fprotf   = (fq4 / (fq1 + tiny(fq1)))      !! protected fraction of total organic C     (non-dim)
+                        else
+                           fprotf   = 1.0                            !! all organic C is protected                (non-dim)
+                        endif
+                        fq5      = (1.0 - fprotf)                    !! unprotected fraction of total organic C   (non-dim)
+                        fq6      = (fq0 * fq5)                       !! how much organic C is unprotected         (mol)
+                        fq7      = (fq6 * exp(-(fthk / xfastc)))     !! how much unprotected C leaves this box    (mol)
+                        fq8      = (fq7 + (fq0 * fprotf))            !! how much total C leaves this box          (mol)
+                        freminc  = (fq0 - fq8) / fthk                !! C remineralisation in this box            (mol)
+                        ffastc(ji,jj) = fq8                          
+# if defined key_debug_medusa
+                        !! report in/out/remin fluxes of carbon for this level
+                           if (idf.eq.1.AND.idfval.eq.1) then
+                              IF (lwp) write (numout,*) '------------------------------'
+                              IF (lwp) write (numout,*) 'totalC(',jk,')  = ', fq1
+                              IF (lwp) write (numout,*) 'prtctC(',jk,')  = ', fq4
+                              IF (lwp) write (numout,*) 'fprotf(',jk,')  = ', fprotf
+                              IF (lwp) write (numout,*) '------------------------------'
+                              IF (lwp) write (numout,*) 'IN   C(',jk,')  = ', fq0
+                              IF (lwp) write (numout,*) 'LOST C(',jk,')  = ', freminc * fthk
+                              IF (lwp) write (numout,*) 'OUT  C(',jk,')  = ', fq8
+                              IF (lwp) write (numout,*) 'NEW  C(',jk,')  = ', ftempc * fthk
+                           endif
+# endif
+                        else
+                        fq1      = fq0 * exp(-(fthk / xfastc))       !! how much organic C leaves this box        (mol)
+                        freminc  = (fq0 - fq1) / fthk                !! C remineralisation in this box            (mol)
+                        ffastc(ji,jj)  = fq1
+                     endif
+                     !!
+                     !! === organic nitrogen ===
+                     fq0      = ffastn(ji,jj)                        !! how much organic N enters this box        (mol)
+                     if (iball.eq.1) then
+                        fq5      = (1.0 - fprotf)                    !! unprotected fraction of total organic N   (non-dim)
+                        fq6      = (fq0 * fq5)                       !! how much organic N is unprotected         (mol)
+                        fq7      = (fq6 * exp(-(fthk / xfastc)))     !! how much unprotected N leaves this box    (mol)
+                        fq8      = (fq7 + (fq0 * fprotf))            !! how much total N leaves this box          (mol)
+                        freminn  = (fq0 - fq8) / fthk                !! N remineralisation in this box            (mol)
+                        ffastn(ji,jj)  = fq8
+# if defined key_debug_medusa
+                        !! report in/out/remin fluxes of carbon for this level
+                        if (idf.eq.1.AND.idfval.eq.1) then
+                           IF (lwp) write (numout,*) '------------------------------'
+                           IF (lwp) write (numout,*) 'totalN(',jk,')  = ', fq1
+                           IF (lwp) write (numout,*) 'prtctN(',jk,')  = ', fq4
+                           IF (lwp) write (numout,*) 'fprotf(',jk,')  = ', fprotf
+                           IF (lwp) write (numout,*) '------------------------------'
+                           if (freminn < 0.0) then
+                              IF (lwp) write (numout,*) '** FREMIN ERROR **'
+                           endif
+                           IF (lwp) write (numout,*) 'IN   N(',jk,')  = ', fq0
+                           IF (lwp) write (numout,*) 'LOST N(',jk,')  = ', freminn * fthk
+                           IF (lwp) write (numout,*) 'OUT  N(',jk,')  = ', fq8
+                           IF (lwp) write (numout,*) 'NEW  N(',jk,')  = ', ftempn * fthk
+                        endif
+# endif
+                     else
+                        fq1      = fq0 * exp(-(fthk / xfastc))       !! how much organic N leaves this box        (mol)
+                        freminn  = (fq0 - fq1) / fthk                !! N remineralisation in this box            (mol)
+                        ffastn(ji,jj)  = fq1
+                     endif
+                     !!
+                     !! === organic iron ===
+                     fq0      = ffastfe(ji,jj)                       !! how much organic Fe enters this box       (mol)
+                     if (iball.eq.1) then
+                        fq5      = (1.0 - fprotf)                    !! unprotected fraction of total organic Fe  (non-dim)
+                        fq6      = (fq0 * fq5)                       !! how much organic Fe is unprotected        (mol)
+                        fq7      = (fq6 * exp(-(fthk / xfastc)))     !! how much unprotected Fe leaves this box   (mol)
+                        fq8      = (fq7 + (fq0 * fprotf))            !! how much total Fe leaves this box         (mol)            
+                        freminfe = (fq0 - fq8) / fthk                !! Fe remineralisation in this box           (mol)
+                        ffastfe(ji,jj) = fq8
+                     else
+                        fq1      = fq0 * exp(-(fthk / xfastc))       !! how much total Fe leaves this box         (mol)      
+                        freminfe = (fq0 - fq1) / fthk                !! Fe remineralisation in this box           (mol)
+                        ffastfe(ji,jj) = fq1
+                     endif
+                     !!
+                     !! === biogenic silicon ===
+                     fq0      = ffastsi(ji,jj)                       !! how much  opal centers this box           (mol) 
+                     fq1      = fq0 * exp(-(fthk / xfastsi))         !! how much  opal leaves this box            (mol)
+                     freminsi = (fq0 - fq1) / fthk                   !! Si remineralisation in this box           (mol)
+                     ffastsi(ji,jj) = fq1
+                     !!
+                     !! === biogenic calcium carbonate ===
+                     fq0      = ffastca(ji,jj)                       !! how much CaCO3 enters this box            (mol)
+                     if (fdep.le.fccd_dep) then
+                        !! whole grid cell above CCD
+                        fq1      = fq0                               !! above lysocline, no Ca dissolves          (mol)
+                        freminca = 0.0                               !! above lysocline, no Ca dissolves          (mol)
+                        fccd(ji,jj) = real(jk)                       !! which is the last level above the CCD?    (#)
+                     elseif (fdep.ge.fccd_dep) then
+                        !! whole grid cell below CCD
+                        fq1      = fq0 * exp(-(fthk / xfastca))      !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     else
+                        !! partial grid cell below CCD
+                        fq2      = fdep1 - fccd_dep                  !! amount of grid cell below CCD             (m)
+                        fq1      = fq0 * exp(-(fq2 / xfastca))       !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     endif
+                     ffastca(ji,jj) = fq1 
+                  else
+                     !! this is BELOW THE LAST OCEAN BOX (do nothing)
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0              
+                  endif
+
+               elseif (jexport.eq.2.or.jexport.eq.3) then
+                  if (jexport.eq.2) then
+                     !!======================================================================
+                     !! MARTIN ET AL. (1987) SUBMODEL
+                     !!======================================================================
+                     !! 
+                     !!----------------------------------------------------------------------
+                     !! This submodel uses the classic Martin et al. (1987) curve
+                     !! to determine the attenuation of fast-sinking detritus down
+                     !! the water column.  All three organic elements, C, N and Fe,
+                     !! are handled identically, and their quantities in sinking
+                     !! particles attenuate according to a power relationship
+                     !! governed by parameter "b".  This is assigned a canonical 
+                     !! value of -0.858.  Biogenic opal and calcium carbonate are
+                     !! attentuated using the same function as in the ballast
+                     !! submodel
+                     !!----------------------------------------------------------------------
+                     !!
+                     fb_val = -0.858
+                  elseif (jexport.eq.3) then
+                     !!======================================================================
+                     !! HENSON ET AL. (2011) SUBMODEL
+                     !!======================================================================
+                     !!
+                     !!----------------------------------------------------------------------
+                     !! This submodel reconfigures the Martin et al. (1987) curve by
+                     !! allowing the "b" value to vary geographically.  Its value is
+                     !! set, following Henson et al. (2011), as a function of local
+                     !! sea surface temperature:
+                     !!   b = -1.06 + (0.024 * SST)
+                     !! This means that remineralisation length scales are longer in
+                     !! warm, tropical areas and shorter in cold, polar areas.  This
+                     !! does seem back-to-front (i.e. one would expect GREATER
+                     !! remineralisation in warmer waters), but is an outcome of 
+                     !! analysis of sediment trap data, and it may reflect details
+                     !! of ecosystem structure that pertain to particle production
+                     !! rather than simply Q10.
+                     !!----------------------------------------------------------------------
+                     !!
+                     fl_sst = tsn(ji,jj,1,jp_tem)
+                     fb_val = -1.06 + (0.024 * fl_sst)
+                  endif
+                  !!   
+                  if (jk.eq.1) then
+                     !! this is the SURFACE OCEAN BOX (no remineralisation)
+                     !!
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0
+                  elseif (jk.le.jmbathy) then
+                     !! this is an OCEAN BOX (remineralise some material)
+                     !!
+                     !! === organic carbon ===
+                     fq0      = ffastc(ji,jj)                        !! how much organic C enters this box        (mol)
+                     fq1      = fq0 * ((fdep1/fdep)**fb_val)         !! how much organic C leaves this box        (mol)
+                     freminc  = (fq0 - fq1) / fthk                   !! C remineralisation in this box            (mol)
+                     ffastc(ji,jj)  = fq1
+                     !!
+                     !! === organic nitrogen ===
+                     fq0      = ffastn(ji,jj)                        !! how much organic N enters this box        (mol)
+                     fq1      = fq0 * ((fdep1/fdep)**fb_val)         !! how much organic N leaves this box        (mol)
+                     freminn  = (fq0 - fq1) / fthk                   !! N remineralisation in this box            (mol)
+                     ffastn(ji,jj)  = fq1
+                     !!
+                     !! === organic iron ===
+                     fq0      = ffastfe(ji,jj)                       !! how much organic Fe enters this box       (mol)
+                     fq1      = fq0 * ((fdep1/fdep)**fb_val)         !! how much organic Fe leaves this box       (mol)
+                     freminfe = (fq0 - fq1) / fthk                   !! Fe remineralisation in this box           (mol)
+                     ffastfe(ji,jj) = fq1
+                     !!
+                     !! === biogenic silicon ===
+                     fq0      = ffastsi(ji,jj)                       !! how much  opal centers this box           (mol) 
+                     fq1      = fq0 * exp(-(fthk / xfastsi))         !! how much  opal leaves this box            (mol)
+                     freminsi = (fq0 - fq1) / fthk                   !! Si remineralisation in this box           (mol)
+                     ffastsi(ji,jj) = fq1
+                     !!
+                     !! === biogenic calcium carbonate ===
+                     fq0      = ffastca(ji,jj)                       !! how much CaCO3 enters this box            (mol)
+                     if (fdep.le.ocal_ccd(ji,jj)) then
+                        !! whole grid cell above CCD
+                        fq1      = fq0                               !! above lysocline, no Ca dissolves          (mol)
+                        freminca = 0.0                               !! above lysocline, no Ca dissolves          (mol)
+                        fccd(ji,jj) = real(jk)                       !! which is the last level above the CCD?    (#)
+                     elseif (fdep.ge.ocal_ccd(ji,jj)) then
+                        !! whole grid cell below CCD
+                        fq1      = fq0 * exp(-(fthk / xfastca))      !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     else
+                        !! partial grid cell below CCD
+                        fq2      = fdep1 - ocal_ccd(ji,jj)           !! amount of grid cell below CCD             (m)
+                        fq1      = fq0 * exp(-(fq2 / xfastca))       !! how much CaCO3 leaves this box            (mol)
+                        freminca = (fq0 - fq1) / fthk                !! Ca remineralisation in this box           (mol)
+                     endif
+                     ffastca(ji,jj) = fq1 
+                  else
+                     !! this is BELOW THE LAST OCEAN BOX (do nothing)
+                     freminc  = 0.0
+                     freminn  = 0.0
+                     freminfe = 0.0
+                     freminsi = 0.0
+                     freminca = 0.0              
+                  endif
+
+               endif
+
+               !!----------------------------------------------------------------------
+               !! Fast-sinking detritus fluxes, pt. 2: UPDATE FAST FLUXES
+               !! here locally calculated additions to the fast-sinking flux are added
+               !! to the total fast-sinking flux; this is done here such that material
+               !! produced in a particular layer is only remineralised below this
+               !! layer
+               !!----------------------------------------------------------------------
+               !!
+               !! add sinking material generated in this layer to running totals
+               !!
+               !! === organic carbon ===                          (diatom and mesozooplankton mortality)
+               ffastc(ji,jj)  = ffastc(ji,jj)  + (ftempc  * fthk)
+               !!
+               !! === organic nitrogen ===                        (diatom and mesozooplankton mortality)
+               ffastn(ji,jj)  = ffastn(ji,jj)  + (ftempn  * fthk)
+               !!
+               !! === organic iron ===                            (diatom and mesozooplankton mortality)
+               ffastfe(ji,jj) = ffastfe(ji,jj) + (ftempfe * fthk)
+               !!
+               !! === biogenic silicon ===                        (diatom mortality and grazed diatoms)
+               ffastsi(ji,jj) = ffastsi(ji,jj) + (ftempsi * fthk)
+               !!
+               !! === biogenic calcium carbonate ===              (latitudinally-based fraction of total primary production)
+               ffastca(ji,jj) = ffastca(ji,jj) + (ftempca * fthk)
+
+               !!----------------------------------------------------------------------
+               !! Fast-sinking detritus fluxes, pt. 3: SEAFLOOR
+               !! remineralise all remaining fast-sinking detritus to dissolved
+               !! nutrients; the sedimentation fluxes calculated here allow the
+               !! separation of what's remineralised sinking through the final
+               !! ocean box from that which is added to the final box by the
+               !! remineralisation of material that reaches the seafloor (i.e.
+               !! the model assumes that *all* material that hits the seafloor
+               !! is remineralised and that none is permanently buried; hey,
+               !! this is a giant GCM model that can't be run for long enough
+               !! to deal with burial fluxes!)
+               !!
+               !! in a change to this process, in part so that MEDUSA behaves
+               !! a little more like ERSEM et al., fast-sinking detritus (N, Fe
+               !! and C) is converted to slow sinking detritus at the seafloor
+               !! instead of being remineralised; the rationale is that in
+               !! shallower shelf regions (... that are not fully mixed!) this
+               !! allows the detrital material to return slowly to dissolved 
+               !! nutrient rather than instantaneously as now; the alternative
+               !! would be to explicitly handle seafloor organic material - a
+               !! headache I don't wish to experience at this point; note that
+               !! fast-sinking Si and Ca detritus is just remineralised as 
+               !! per usual
+               !! 
+               !! AXY (13/01/12)
+               !! in a further change to this process, again so that MEDUSA is
+               !! a little more like ERSEM et al., material that reaches the
+               !! seafloor can now be added to sediment pools and stored for
+               !! slow release; there are new 2D arrays for organic nitrogen,
+               !! iron and carbon and inorganic silicon and carbon that allow
+               !! fast and slow detritus that reaches the seafloor to be held
+               !! and released back to the water column more slowly; these arrays
+               !! are transferred via the tracer restart files between repeat
+               !! submissions of the model
+               !!----------------------------------------------------------------------
+               !! 
+               ffast2slowc  = 0.0
+               ffast2slown  = 0.0
+               ffast2slowfe = 0.0
+               !!
+               if (jk.eq.jmbathy) then
+                  !! this is the BOTTOM OCEAN BOX (remineralise everything)
+                  !!
+                  !! AXY (17/01/12): tweaked to include benthos pools
+                  !! 
+                  !! === organic carbon ===
+                  if (jfdfate.eq.0 .and. jorgben.eq.0) then
+                     freminc  = freminc + (ffastc(ji,jj) / fthk)    !! C remineralisation in this box            (mol/m3)
+                  elseif (jfdfate.eq.1 .and. jorgben.eq.0) then
+                     ffast2slowc = ffastc(ji,jj) / fthk             !! fast C -> slow C                          (mol/m3)
+                     fslowc      = fslowc + ffast2slowc
+                  elseif (jfdfate.eq.0 .and. jorgben.eq.1) then
+                     f_fbenin_c(ji,jj)  = ffastc(ji,jj)             !! fast C -> benthic C                       (mol/m2)
+                  endif
+                  fsedc(ji,jj)   = ffastc(ji,jj)                          !! record seafloor C                         (mol/m2)
+                  ffastc(ji,jj)  = 0.0
+                  !!
+                  !! === organic nitrogen ===
+                  if (jfdfate.eq.0 .and. jorgben.eq.0) then
+                     freminn  = freminn + (ffastn(ji,jj) / fthk)    !! N remineralisation in this box            (mol/m3)
+                  elseif (jfdfate.eq.1 .and. jorgben.eq.0) then
+                     ffast2slown = ffastn(ji,jj) / fthk             !! fast N -> slow N                          (mol/m3)
+                     fslown      = fslown + ffast2slown
+                  elseif (jfdfate.eq.0 .and. jorgben.eq.1) then
+                     f_fbenin_n(ji,jj)  = ffastn(ji,jj)             !! fast N -> benthic N                       (mol/m2)
+                  endif
+                  fsedn(ji,jj)   = ffastn(ji,jj)                          !! record seafloor N                         (mol/m2)
+                  ffastn(ji,jj)  = 0.0
+                  !!
+                  !! === organic iron ===
+                  if (jfdfate.eq.0 .and. jorgben.eq.0) then
+                     freminfe = freminfe + (ffastfe(ji,jj) / fthk)  !! Fe remineralisation in this box           (mol/m3)
+                  elseif (jfdfate.eq.1 .and. jorgben.eq.0) then
+                     ffast2slowfe = ffastn(ji,jj) / fthk            !! fast Fe -> slow Fe                        (mol/m3)
+                  elseif (jfdfate.eq.0 .and. jorgben.eq.1) then
+                     f_fbenin_fe(ji,jj) = ffastfe(ji,jj)            !! fast Fe -> benthic Fe                     (mol/m2)
+                  endif
+                  fsedfe(ji,jj)  = ffastfe(ji,jj)                         !! record seafloor Fe                        (mol/m2)
+                  ffastfe(ji,jj) = 0.0
+                  !!
+                  !! === biogenic silicon ===
+                  if (jinorgben.eq.0) then
+                     freminsi = freminsi + (ffastsi(ji,jj) / fthk)  !! Si remineralisation in this box           (mol/m3)
+                  elseif (jinorgben.eq.1) then
+                     f_fbenin_si(ji,jj) = ffastsi(ji,jj)            !! fast Si -> benthic Si                     (mol/m2)
+                  endif
+                  fsedsi(ji,jj)   = ffastsi(ji,jj)                         !! record seafloor Si                        (mol/m2)
+                  ffastsi(ji,jj) = 0.0
+                  !!
+                  !! === biogenic calcium carbonate ===
+                  if (jinorgben.eq.0) then
+                     freminca = freminca + (ffastca(ji,jj) / fthk)  !! Ca remineralisation in this box           (mol/m3) 
+                  elseif (jinorgben.eq.1) then
+                     f_fbenin_ca(ji,jj) = ffastca(ji,jj)            !! fast Ca -> benthic Ca                     (mol/m2)
+                  endif
+                  fsedca(ji,jj)   = ffastca(ji,jj)                         !! record seafloor Ca                        (mol/m2)
+                  ffastca(ji,jj) = 0.0
+               endif
+
+# if defined key_debug_medusa
+               if (idf.eq.1) then
+                  !!----------------------------------------------------------------------
+                  !! Integrate total fast detritus remineralisation
+                  !!----------------------------------------------------------------------
+                  !!
+                  fofd_n(ji,jj)  = fofd_n(ji,jj)  + (freminn  * fthk)
+                  fofd_si(ji,jj) = fofd_si(ji,jj) + (freminsi * fthk)
+                  fofd_fe(ji,jj) = fofd_fe(ji,jj) + (freminfe * fthk)
+#  if defined key_roam
+                  fofd_c(ji,jj)  = fofd_c(ji,jj)  + (freminc  * fthk)
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Sort out remineralisation tally of fast-sinking detritus
+               !!----------------------------------------------------------------------
+               !!
+               !! update fast-sinking regeneration arrays
+               fregenfast(ji,jj)   = fregenfast(ji,jj)   + (freminn  * fthk)
+               fregenfastsi(ji,jj) = fregenfastsi(ji,jj) + (freminsi * fthk)
+# if defined key_roam
+               fregenfastc(ji,jj)  = fregenfastc(ji,jj)  + (freminc  * fthk)
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Benthic remineralisation fluxes
+               !!----------------------------------------------------------------------
+               !!
+               if (jk.eq.jmbathy) then
+                  !!
+                  !! organic components
+                  if (jorgben.eq.1) then
+                     f_benout_n(ji,jj)  = xsedn  * zn_sed_n(ji,jj)
+                     f_benout_fe(ji,jj) = xsedfe * zn_sed_fe(ji,jj)
+                     f_benout_c(ji,jj)  = xsedc  * zn_sed_c(ji,jj)
+                  endif
+                  !!
+                  !! inorganic components
+                  if (jinorgben.eq.1) then
+                     f_benout_si(ji,jj) = xsedsi * zn_sed_si(ji,jj)
+                     f_benout_ca(ji,jj) = xsedca * zn_sed_ca(ji,jj)
+                     !!
+                     !! account for CaCO3 that dissolves when it shouldn't
+                     if ( fdep .le. fccd_dep ) then
+                        f_benout_lyso_ca(ji,jj) = xsedca * zn_sed_ca(ji,jj)
+                     endif
+                  endif
+               endif
+               CALL flush(numout)
+
+               !!======================================================================
+               !! LOCAL GRID CELL TRENDS
+               !!======================================================================
+               !!
+               !!----------------------------------------------------------------------
+               !! Determination of trends
+               !!----------------------------------------------------------------------
+               !!
+               !!----------------------------------------------------------------------
+               !! chlorophyll
+               btra(jpchn) = b0 * ( &
+                 + ((frn * fprn * zphn) - fgmipn - fgmepn - fdpn - fdpn2) * (fthetan / xxi) )
+               btra(jpchd) = b0 * ( &
+                 + ((frd * fprd * zphd) - fgmepd - fdpd - fdpd2) * (fthetad / xxi) )
+               !!
+               !!----------------------------------------------------------------------
+               !! phytoplankton
+               btra(jpphn) = b0 * ( &
+                 + (fprn * zphn) - fgmipn - fgmepn - fdpn - fdpn2 )
+               btra(jpphd) = b0 * ( &
+                 + (fprd * zphd) - fgmepd - fdpd - fdpd2 )
+               btra(jppds) = b0 * ( &
+                 + (fprds * zpds) - fgmepds - fdpds - fsdiss - fdpds2 )
+               !!
+               !!----------------------------------------------------------------------
+               !! zooplankton
+               btra(jpzmi) = b0 * ( &
+                 + fmigrow - fgmezmi - fdzmi - fdzmi2 )
+               btra(jpzme) = b0 * ( &
+                 + fmegrow - fdzme - fdzme2 )
+               !!
+               !!----------------------------------------------------------------------
+               !! detritus
+               btra(jpdet) = b0 * ( &
+                 + fdpn + ((1.0 - xfdfrac1) * fdpd)              &  ! mort. losses
+                 + fdzmi + ((1.0 - xfdfrac2) * fdzme)            &  ! mort. losses
+                 + ((1.0 - xbetan) * (finmi + finme))            &  ! assim. inefficiency
+                 - fgmid - fgmed - fdd                           &  ! grazing and remin.
+                 + ffast2slown )                                    ! seafloor fast->slow
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved inorganic nitrogen nutrient
+               fn_cons = 0.0  &
+                 - (fprn * zphn) - (fprd * zphd)                    ! primary production
+               fn_prod = 0.0  &
+                 + (xphi * (fgmipn + fgmid))                     &  ! messy feeding remin.
+                 + (xphi * (fgmepn + fgmepd + fgmezmi + fgmed))  &  ! messy feeding remin.
+                 + fmiexcr + fmeexcr + fdd + freminn             &  ! excretion and remin.
+                 + fdpn2 + fdpd2 + fdzmi2 + fdzme2                  ! metab. losses
+               !! 
+               !! riverine flux
+               if ( jriver_n .gt. 0 ) then
+                  f_riv_loc_n = f_riv_n(ji,jj) * friver_dep(jk,jmbathy) / fthk
+                  fn_prod = fn_prod + f_riv_loc_n
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.jmbathy .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fn_prod = fn_prod + (f_benout_n(ji,jj) / fthk)
+               endif
+               !!
+               btra(jpdin) = b0 * ( &
+                 fn_prod + fn_cons )
+               !!
+               fnit_cons(ji,jj) = fnit_cons(ji,jj) + ( fthk * (  &  ! consumption of dissolved nitrogen
+                 fn_cons ) )
+               fnit_prod(ji,jj) = fnit_prod(ji,jj) + ( fthk * (  &  ! production of dissolved nitrogen
+                 fn_prod ) )
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved silicic acid nutrient
+               fs_cons = 0.0  &
+                 - (fprds * zpds)                                   ! opal production
+               fs_prod = 0.0  &
+                 + fsdiss                                        &  ! opal dissolution
+                 + ((1.0 - xfdfrac1) * fdpds)                    &  ! mort. loss
+                 + ((1.0 - xfdfrac3) * fgmepds)                  &  ! egestion of grazed Si
+                 + freminsi + fdpds2                                ! fast diss. and metab. losses
+               !! 
+               !! riverine flux
+               if ( jriver_si .gt. 0 ) then
+                  f_riv_loc_si = f_riv_si(ji,jj) * friver_dep(jk,jmbathy) / fthk
+                  fs_prod = fs_prod + f_riv_loc_si
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.jmbathy .and. jinorgben.eq.1 .and. ibenthic.eq.1) then
+                  fs_prod = fs_prod + (f_benout_si(ji,jj) / fthk)
+               endif
+               !!
+               btra(jpsil) = b0 * ( &
+                 fs_prod + fs_cons )
+               !!
+               fsil_cons(ji,jj) = fsil_cons(ji,jj) + ( fthk * (  &  ! consumption of dissolved silicon
+                 fs_cons ) )
+               fsil_prod(ji,jj) = fsil_prod(ji,jj) + ( fthk * (  &  ! production of dissolved silicon
+                 fs_prod ) )
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved "iron" nutrient
+               btra(jpfer) = b0 * ( &
+               + (xrfn * btra(jpdin)) + ffetop + ffebot - ffescav )
+
+# if defined key_roam
+               !!
+               !!----------------------------------------------------------------------
+               !! AXY (26/11/08): implicit detrital carbon change
+               btra(jpdtc) = b0 * ( &
+                 + (xthetapn * fdpn) + ((1.0 - xfdfrac1) * (xthetapd * fdpd))      &  ! mort. losses
+                 + (xthetazmi * fdzmi) + ((1.0 - xfdfrac2) * (xthetazme * fdzme))  &  ! mort. losses
+                 + ((1.0 - xbetac) * (ficmi + ficme))                              &  ! assim. inefficiency
+                 - fgmidc - fgmedc - fddc                                          &  ! grazing and remin.
+                 + ffast2slowc )                                                      ! seafloor fast->slow
+               !!
+               !!----------------------------------------------------------------------
+               !! dissolved inorganic carbon
+               fc_cons = 0.0  &
+                 - (xthetapn * fprn * zphn) - (xthetapd * fprd * zphd)                ! primary production
+               fc_prod = 0.0  &
+                 + (xthetapn * xphi * fgmipn) + (xphi * fgmidc)                    &  ! messy feeding remin
+                 + (xthetapn * xphi * fgmepn) + (xthetapd * xphi * fgmepd)         &  ! messy feeding remin
+                 + (xthetazmi * xphi * fgmezmi) + (xphi * fgmedc)                  &  ! messy feeding remin
+                 + fmiresp + fmeresp + fddc + freminc + (xthetapn * fdpn2)         &  ! resp., remin., losses
+                 + (xthetapd * fdpd2) + (xthetazmi * fdzmi2)                       &  ! losses
+                 + (xthetazme * fdzme2)                                               ! losses
+               !! 
+               !! riverine flux
+               if ( jriver_c .gt. 0 ) then
+                  f_riv_loc_c = f_riv_c(ji,jj) * friver_dep(jk,jmbathy) / fthk
+                  fc_prod = fc_prod + f_riv_loc_c
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.jmbathy .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fc_prod = fc_prod + (f_benout_c(ji,jj) / fthk)
+               endif
+               if (jk.eq.jmbathy .and. jinorgben.eq.1 .and. ibenthic.eq.1) then
+                  fc_prod = fc_prod + (f_benout_ca(ji,jj) / fthk)
+               endif
+               !!
+               !! community respiration (does not include CaCO3 terms - obviously!)
+               fcomm_resp(ji,jj) = fcomm_resp(ji,jj) + fc_prod
+               !!
+               !! CaCO3
+               fc_prod = fc_prod - ftempca + freminca
+               !! 
+               !! riverine flux
+               if ( jk .eq. 1 .and. jriver_c .gt. 0 ) then
+                  fc_prod = fc_prod + f_riv_c(ji,jj)
+               endif
+               !!
+               btra(jpdic) = b0 * ( &
+                 fc_prod + fc_cons )
+               !!
+               fcar_cons(ji,jj) = fcar_cons(ji,jj) + ( fthk * (  &  ! consumption of dissolved carbon
+                 fc_cons ) )
+               fcar_prod(ji,jj) = fcar_prod(ji,jj) + ( fthk * (  &  ! production of dissolved carbon
+                 fc_prod ) )
+               !!
+               !!----------------------------------------------------------------------
+               !! alkalinity
+               fa_prod = 0.0  &
+                 + (2.0 * freminca)                                                   ! CaCO3 dissolution
+               fa_cons = 0.0  &
+                 - (2.0 * ftempca)                                                    ! CaCO3 production
+               !! 
+               !! riverine flux
+               if ( jriver_alk .gt. 0 ) then
+                  f_riv_loc_alk = f_riv_alk(ji,jj) * friver_dep(jk,jmbathy) / fthk
+                  fa_prod = fa_prod + f_riv_loc_alk
+               endif
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.jmbathy .and. jinorgben.eq.1 .and. ibenthic.eq.1) then
+                  fa_prod = fa_prod + (2.0 * f_benout_ca(ji,jj) / fthk)
+               endif
+               !!
+               btra(jpalk) = b0 * ( &
+                 fa_prod + fa_cons )
+               !!
+               !!----------------------------------------------------------------------
+               !! oxygen (has protection at low O2 concentrations; OCMIP-2 style)
+               fo2_prod = 0.0 &
+                 + (xthetanit * fprn * zphn)                                      & ! Pn primary production, N
+                 + (xthetanit * fprd * zphd)                                      & ! Pd primary production, N
+                 + (xthetarem * xthetapn * fprn * zphn)                           & ! Pn primary production, C
+                 + (xthetarem * xthetapd * fprd * zphd)                             ! Pd primary production, C
+               fo2_ncons = 0.0 &
+                 - (xthetanit * xphi * fgmipn)                                    & ! Pn messy feeding remin., N
+                 - (xthetanit * xphi * fgmid)                                     & ! D  messy feeding remin., N
+                 - (xthetanit * xphi * fgmepn)                                    & ! Pn messy feeding remin., N
+                 - (xthetanit * xphi * fgmepd)                                    & ! Pd messy feeding remin., N
+                 - (xthetanit * xphi * fgmezmi)                                   & ! Zi messy feeding remin., N
+                 - (xthetanit * xphi * fgmed)                                     & ! D  messy feeding remin., N
+                 - (xthetanit * fmiexcr)                                          & ! microzoo excretion, N
+                 - (xthetanit * fmeexcr)                                          & ! mesozoo  excretion, N
+                 - (xthetanit * fdd)                                              & ! slow detritus remin., N 
+                 - (xthetanit * freminn)                                          & ! fast detritus remin., N
+                 - (xthetanit * fdpn2)                                            & ! Pn  losses, N
+                 - (xthetanit * fdpd2)                                            & ! Pd  losses, N
+                 - (xthetanit * fdzmi2)                                           & ! Zmi losses, N
+                 - (xthetanit * fdzme2)                                             ! Zme losses, N
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.jmbathy .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fo2_ncons = fo2_ncons - (xthetanit * f_benout_n(ji,jj) / fthk)
+               endif
+               fo2_ccons = 0.0 &
+                 - (xthetarem * xthetapn * xphi * fgmipn)                         & ! Pn messy feeding remin., C
+                 - (xthetarem * xphi * fgmidc)                                    & ! D  messy feeding remin., C
+                 - (xthetarem * xthetapn * xphi * fgmepn)                         & ! Pn messy feeding remin., C
+                 - (xthetarem * xthetapd * xphi * fgmepd)                         & ! Pd messy feeding remin., C
+                 - (xthetarem * xthetazmi * xphi * fgmezmi)                       & ! Zi messy feeding remin., C
+                 - (xthetarem * xphi * fgmedc)                                    & ! D  messy feeding remin., C
+                 - (xthetarem * fmiresp)                                          & ! microzoo respiration, C
+                 - (xthetarem * fmeresp)                                          & ! mesozoo  respiration, C
+                 - (xthetarem * fddc)                                             & ! slow detritus remin., C
+                 - (xthetarem * freminc)                                          & ! fast detritus remin., C
+                 - (xthetarem * xthetapn * fdpn2)                                 & ! Pn  losses, C
+                 - (xthetarem * xthetapd * fdpd2)                                 & ! Pd  losses, C
+                 - (xthetarem * xthetazmi * fdzmi2)                               & ! Zmi losses, C
+                 - (xthetarem * xthetazme * fdzme2)                                 ! Zme losses, C
+               !!  
+               !! benthic remineralisation
+               if (jk.eq.jmbathy .and. jorgben.eq.1 .and. ibenthic.eq.1) then
+                  fo2_ccons = fo2_ccons - (xthetarem * f_benout_c(ji,jj) / fthk)
+               endif
+               fo2_cons = fo2_ncons + fo2_ccons
+               !!
+               !! is this a suboxic zone?
+               if (zoxy.lt.xo2min) then  ! deficient O2; production fluxes only
+                  btra(jpoxy) = b0 * ( &
+                    fo2_prod )
+                  foxy_prod(ji,jj) = foxy_prod(ji,jj) + ( fthk * fo2_prod )
+                  foxy_anox(ji,jj) = foxy_anox(ji,jj) + ( fthk * fo2_cons )
+               else                      ! sufficient O2; production + consumption fluxes
+                  btra(jpoxy) = b0 * ( &
+                    fo2_prod + fo2_cons )
+                  foxy_prod(ji,jj) = foxy_prod(ji,jj) + ( fthk * fo2_prod )
+                  foxy_cons(ji,jj) = foxy_cons(ji,jj) + ( fthk * fo2_cons )
+               endif
+               !!
+               !! air-sea fluxes (if this is the surface box)
+               if (jk.eq.1) then
+                  !!
+                  !! CO2 flux
+                  btra(jpdic) = btra(jpdic) + (b0 * f_co2flux)
+                  !!
+                  !! O2 flux (mol/m3/s -> mmol/m3/d)
+                  btra(jpoxy) = btra(jpoxy) + (b0 * f_o2flux)
+               endif
+# endif
+
+# if defined key_debug_medusa
+               !! report state variable fluxes (not including fast-sinking detritus)
+               if (idf.eq.1.AND.idfval.eq.1) then
+                  IF (lwp) write (numout,*) '------------------------------'
+                  IF (lwp) write (numout,*) 'btra(jpchn)(',jk,')  = ', btra(jpchn)
+                  IF (lwp) write (numout,*) 'btra(jpchd)(',jk,')  = ', btra(jpchd)
+                  IF (lwp) write (numout,*) 'btra(jpphn)(',jk,')  = ', btra(jpphn)
+                  IF (lwp) write (numout,*) 'btra(jpphd)(',jk,')  = ', btra(jpphd)
+                  IF (lwp) write (numout,*) 'btra(jppds)(',jk,')  = ', btra(jppds)
+                  IF (lwp) write (numout,*) 'btra(jpzmi)(',jk,')  = ', btra(jpzmi)
+                  IF (lwp) write (numout,*) 'btra(jpzme)(',jk,')  = ', btra(jpzme)
+                  IF (lwp) write (numout,*) 'btra(jpdet)(',jk,')  = ', btra(jpdet)
+                  IF (lwp) write (numout,*) 'btra(jpdin)(',jk,')  = ', btra(jpdin)
+                  IF (lwp) write (numout,*) 'btra(jpsil)(',jk,')  = ', btra(jpsil)
+                  IF (lwp) write (numout,*) 'btra(jpfer)(',jk,')  = ', btra(jpfer)
+#  if defined key_roam
+                  IF (lwp) write (numout,*) 'btra(jpdtc)(',jk,')  = ', btra(jpdtc)
+                  IF (lwp) write (numout,*) 'btra(jpdic)(',jk,')  = ', btra(jpdic)
+                  IF (lwp) write (numout,*) 'btra(jpalk)(',jk,')  = ', btra(jpalk)
+                  IF (lwp) write (numout,*) 'btra(jpoxy)(',jk,')  = ', btra(jpoxy)
+#  endif
+               endif
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Integrate calculated fluxes for mass balance
+               !!----------------------------------------------------------------------
+               !!
+               !! === nitrogen ===
+               fflx_n(ji,jj)  = fflx_n(ji,jj)  + &
+                  fthk * ( btra(jpphn) + btra(jpphd) + btra(jpzmi) + btra(jpzme) + btra(jpdet) + btra(jpdin) )
+               !! === silicon ===
+               fflx_si(ji,jj) = fflx_si(ji,jj) + &
+                  fthk * ( btra(jppds) + btra(jpsil) )
+               !! === iron ===
+               fflx_fe(ji,jj) = fflx_fe(ji,jj) + &
+                  fthk * ( ( xrfn * ( btra(jpphn) + btra(jpphd) + btra(jpzmi) + btra(jpzme) + btra(jpdet)) ) + btra(jpfer) )
+# if defined key_roam
+               !! === carbon ===
+               fflx_c(ji,jj)  = fflx_c(ji,jj)  + &
+                  fthk * ( (xthetapn * btra(jpphn)) + (xthetapd * btra(jpphd)) + &
+                  (xthetazmi * btra(jpzmi)) + (xthetazme * btra(jpzme)) + btra(jpdtc) + btra(jpdic) )
+               !! === alkalinity ===
+               fflx_a(ji,jj)  = fflx_a(ji,jj)  + &
+                  fthk * ( btra(jpalk) )
+               !! === oxygen ===
+               fflx_o2(ji,jj) = fflx_o2(ji,jj) + &
+                  fthk * ( btra(jpoxy) )
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Apply calculated tracer fluxes
+               !!----------------------------------------------------------------------
+               !!
+               !! units: [unit of tracer] per second (fluxes are calculated above per day)
+               !!
+               ibio_switch = 1
+# if defined key_gulf_finland
+               !! AXY (17/05/13): fudge in a Gulf of Finland correction; uses longitude-
+               !!                 latitude range to establish if this is a Gulf of Finland 
+               !!                 grid cell; if so, then BGC fluxes are ignored (though 
+               !!                 still calculated); for reference, this is meant to be a 
+               !!                 temporary fix to see if all of my problems can be done 
+               !!                 away with if I switch off BGC fluxes in the Gulf of 
+               !!                 Finland, which currently appears the source of trouble
+               if ( flonx.gt.24.7 .and. flonx.lt.27.8 .and. &
+                  &   flatx.gt.59.2 .and. flatx.lt.60.2 ) then
+                  ibio_switch = 0
+               endif
+# endif               
+               if (ibio_switch.eq.1) then
+                  tra(ji,jj,jk,jpchn) = tra(ji,jj,jk,jpchn) + (btra(jpchn) / 86400.)
+                  tra(ji,jj,jk,jpchd) = tra(ji,jj,jk,jpchd) + (btra(jpchd) / 86400.)
+                  tra(ji,jj,jk,jpphn) = tra(ji,jj,jk,jpphn) + (btra(jpphn) / 86400.)
+                  tra(ji,jj,jk,jpphd) = tra(ji,jj,jk,jpphd) + (btra(jpphd) / 86400.)
+                  tra(ji,jj,jk,jppds) = tra(ji,jj,jk,jppds) + (btra(jppds) / 86400.)
+                  tra(ji,jj,jk,jpzmi) = tra(ji,jj,jk,jpzmi) + (btra(jpzmi) / 86400.)
+                  tra(ji,jj,jk,jpzme) = tra(ji,jj,jk,jpzme) + (btra(jpzme) / 86400.)
+                  tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + (btra(jpdet) / 86400.)
+                  tra(ji,jj,jk,jpdin) = tra(ji,jj,jk,jpdin) + (btra(jpdin) / 86400.)
+                  tra(ji,jj,jk,jpsil) = tra(ji,jj,jk,jpsil) + (btra(jpsil) / 86400.)
+                  tra(ji,jj,jk,jpfer) = tra(ji,jj,jk,jpfer) + (btra(jpfer) / 86400.)
+# if defined key_roam
+                  tra(ji,jj,jk,jpdtc) = tra(ji,jj,jk,jpdtc) + (btra(jpdtc) / 86400.)
+                  tra(ji,jj,jk,jpdic) = tra(ji,jj,jk,jpdic) + (btra(jpdic) / 86400.)
+                  tra(ji,jj,jk,jpalk) = tra(ji,jj,jk,jpalk) + (btra(jpalk) / 86400.)
+                  tra(ji,jj,jk,jpoxy) = tra(ji,jj,jk,jpoxy) + (btra(jpoxy) / 86400.)
+# endif
+               endif               
+
+               !! AXY (18/11/16): CMIP6 diagnostics
+               IF( med_diag%FBDDTALK%dgsave )  THEN
+                  fbddtalk(ji,jj)  =  fbddtalk(ji,jj)  + (btra(jpalk) * fthk)
+               ENDIF
+               IF( med_diag%FBDDTDIC%dgsave )  THEN
+                  fbddtdic(ji,jj)  =  fbddtdic(ji,jj)  + (btra(jpdic) * fthk)
+               ENDIF
+               IF( med_diag%FBDDTDIFE%dgsave ) THEN
+                  fbddtdife(ji,jj) =  fbddtdife(ji,jj) + (btra(jpfer) * fthk)
+               ENDIF
+               IF( med_diag%FBDDTDIN%dgsave )  THEN
+                  fbddtdin(ji,jj)  =  fbddtdin(ji,jj)  + (btra(jpdin) * fthk)
+               ENDIF
+               IF( med_diag%FBDDTDISI%dgsave ) THEN
+                  fbddtdisi(ji,jj) =  fbddtdisi(ji,jj) + (btra(jpsil) * fthk)
+               ENDIF
+	       !!
+               IF( med_diag%BDDTALK3%dgsave )  THEN
+                  bddtalk3(ji,jj,jk)  =  btra(jpalk)
+               ENDIF
+               IF( med_diag%BDDTDIC3%dgsave )  THEN
+                  bddtdic3(ji,jj,jk)  =  btra(jpdic)
+               ENDIF
+               IF( med_diag%BDDTDIFE3%dgsave ) THEN
+                  bddtdife3(ji,jj,jk) =  btra(jpfer)
+               ENDIF
+               IF( med_diag%BDDTDIN3%dgsave )  THEN
+                  bddtdin3(ji,jj,jk)  =  btra(jpdin)
+               ENDIF
+               IF( med_diag%BDDTDISI3%dgsave ) THEN
+                  bddtdisi3(ji,jj,jk) =  btra(jpsil)
+               ENDIF
+
+#   if defined key_debug_medusa
+               IF (lwp) write (numout,*) '------'
+               IF (lwp) write (numout,*) 'trc_bio_medusa: end all calculations'
+               IF (lwp) write (numout,*) 'trc_bio_medusa: now outputs'
+                     CALL flush(numout)
+#   endif
+
+# if defined key_axy_nancheck
+               !!----------------------------------------------------------------------
+               !! Check calculated tracer fluxes
+               !!----------------------------------------------------------------------
+               !!
+               DO jn = 1,jptra
+                  fq0 = btra(jn)
+                  !! AXY (30/01/14): "isnan" problem on HECTOR
+                  !! if (fq0 /= fq0 ) then
+                  if ( ieee_is_nan( fq0 ) ) then
+                     !! there's a NaN here
+                     if (lwp) write(numout,*) 'NAN detected in btra(', ji, ',', &
+                     & jj, ',', jk, ',', jn, ') at time', kt
+		     CALL ctl_stop( 'trcbio_medusa, NAN in btra field' )
+                  endif
+               ENDDO
+               DO jn = 1,jptra
+                  fq0 = tra(ji,jj,jk,jn)
+                  !! AXY (30/01/14): "isnan" problem on HECTOR
+                  !! if (fq0 /= fq0 ) then
+                  if ( ieee_is_nan( fq0 ) ) then
+                     !! there's a NaN here
+                     if (lwp) write(numout,*) 'NAN detected in tra(', ji, ',', &
+                     & jj, ',', jk, ',', jn, ') at time', kt
+   		     CALL ctl_stop( 'trcbio_medusa, NAN in tra field' )
+                  endif
+               ENDDO
+               CALL flush(numout)
+# endif
+
+               !!----------------------------------------------------------------------
+               !! Check model conservation
+               !! these terms merely sum up the tendency terms of the relevant
+               !! state variables, which should sum to zero; the iron cycle is
+               !! complicated by fluxes that add (aeolian deposition and seafloor
+               !! remineralisation) and remove (scavenging) dissolved iron from
+               !! the model (i.e. the sum of iron fluxes is unlikely to be zero)
+               !!----------------------------------------------------------------------
+               !!
+               !! fnit0 = btra(jpphn) + btra(jpphd) + btra(jpzmi) + btra(jpzme) + btra(jpdet) + btra(jpdin)  ! + ftempn
+               !! fsil0 = btra(jppds) + btra(jpsil)                              ! + ftempsi
+               !! ffer0 = (xrfn * fnit0) + btra(jpfer)
+# if defined key_roam
+               !! fcar0 = 0.
+               !! falk0 = 0.
+               !! foxy0 = 0.
+# endif
+               !!
+               !! if (kt/240*240.eq.kt) then
+               !!    if (ji.eq.2.and.jj.eq.2.and.jk.eq.1) then
+               !!       IF (lwp) write (*,*) '*******!MEDUSA Conservation!*******',kt
+# if defined key_roam
+               !!       IF (lwp) write (*,*) fnit0,fsil0,ffer0,fcar0,falk0,foxy0
+# else
+               !!       IF (lwp) write (*,*) fnit0,fsil0,ffer0
+# endif
+               !!    endif
+               !! endif     
+
+# if defined key_trc_diabio
+               !!======================================================================
+               !! LOCAL GRID CELL DIAGNOSTICS
+               !!======================================================================
+               !!
+               !!----------------------------------------------------------------------
+               !! Full diagnostics key_trc_diabio:
+               !! LOBSTER and PISCES support full diagnistics option key_trc_diabio    
+               !! which gives an option of FULL output of biological sourses and sinks.
+               !! I cannot see any reason for doing this. If needed, it can be done
+               !! as shown below.
+               !!----------------------------------------------------------------------
+               !!
+               IF(lwp) WRITE(numout,*) ' MEDUSA does not support key_trc_diabio'
+               !!               trbio(ji,jj,jk, 1) = fprn
+# endif
+
+               IF( lk_iomput  .AND.  .NOT.  ln_diatrc  ) THEN
+         !!----------------------------------------------------------------------
+         !! Add in XML diagnostics stuff
+         !!----------------------------------------------------------------------
+         !!
+         !! ** 2D diagnostics
+#   if defined key_debug_medusa
+                  IF (lwp) write (numout,*) 'trc_bio_medusa: diag in ij-jj-jk loop'
+                  CALL flush(numout)
+#   endif
+                  IF ( med_diag%PRN%dgsave ) THEN
+                      fprn2d(ji,jj) = fprn2d(ji,jj) + (fprn  * zphn * fthk) 
+                  ENDIF
+                  IF ( med_diag%MPN%dgsave ) THEN
+                      fdpn2d(ji,jj) = fdpn2d(ji,jj) + (fdpn         * fthk)
+                  ENDIF
+                  IF ( med_diag%PRD%dgsave ) THEN
+                      fprd2d(ji,jj) = fprd2d(ji,jj) + (fprd  * zphd * fthk)
+                  ENDIF
+                  IF( med_diag%MPD%dgsave ) THEN
+                      fdpd2d(ji,jj) = fdpd2d(ji,jj) + (fdpd         * fthk) 
+                  ENDIF
+                  !  IF( med_diag%DSED%dgsave ) THEN
+                  !      CALL iom_put( "DSED"  , ftot_n )
+                  !  ENDIF
+                  IF( med_diag%OPAL%dgsave ) THEN
+                      fprds2d(ji,jj) = fprds2d(ji,jj) + (fprds * zpds * fthk) 
+                  ENDIF
+                  IF( med_diag%OPALDISS%dgsave ) THEN
+                      fsdiss2d(ji,jj) = fsdiss2d(ji,jj) + (fsdiss  * fthk)  
+                  ENDIF
+                  IF( med_diag%GMIPn%dgsave ) THEN
+                      fgmipn2d(ji,jj) = fgmipn2d(ji,jj) + (fgmipn  * fthk) 
+                  ENDIF
+                  IF( med_diag%GMID%dgsave ) THEN
+                      fgmid2d(ji,jj) = fgmid2d(ji,jj) + (fgmid   * fthk) 
+                  ENDIF
+                  IF( med_diag%MZMI%dgsave ) THEN
+                      fdzmi2d(ji,jj) = fdzmi2d(ji,jj) + (fdzmi   * fthk) 
+                  ENDIF
+                  IF( med_diag%GMEPN%dgsave ) THEN
+                      fgmepn2d(ji,jj) = fgmepn2d(ji,jj) + (fgmepn  * fthk)
+                  ENDIF
+                  IF( med_diag%GMEPD%dgsave ) THEN
+                      fgmepd2d(ji,jj) = fgmepd2d(ji,jj) + (fgmepd  * fthk) 
+                  ENDIF
+                  IF( med_diag%GMEZMI%dgsave ) THEN
+                      fgmezmi2d(ji,jj) = fgmezmi2d(ji,jj) + (fgmezmi * fthk) 
+                  ENDIF
+                  IF( med_diag%GMED%dgsave ) THEN
+                      fgmed2d(ji,jj) = fgmed2d(ji,jj) + (fgmed   * fthk) 
+                  ENDIF
+                  IF( med_diag%MZME%dgsave ) THEN
+                      fdzme2d(ji,jj) = fdzme2d(ji,jj) + (fdzme   * fthk) 
+                  ENDIF
+                  !  IF( med_diag%DEXP%dgsave ) THEN
+                  !      CALL iom_put( "DEXP"  , ftot_n )
+                  !  ENDIF
+                  IF( med_diag%DETN%dgsave ) THEN
+                      fslown2d(ji,jj) = fslown2d(ji,jj) + (fslown  * fthk)  
+                  ENDIF
+                  IF( med_diag%MDET%dgsave ) THEN
+                      fdd2d(ji,jj) = fdd2d(ji,jj) + (fdd     * fthk) 
+                  ENDIF
+                  IF( med_diag%AEOLIAN%dgsave ) THEN
+                      ffetop2d(ji,jj) = ffetop2d(ji,jj) + (ffetop  * fthk) 
+                  ENDIF
+                  IF( med_diag%BENTHIC%dgsave ) THEN
+                      ffebot2d(ji,jj) = ffebot2d(ji,jj) + (ffebot  * fthk) 
+                  ENDIF
+                  IF( med_diag%SCAVENGE%dgsave ) THEN
+                      ffescav2d(ji,jj) = ffescav2d(ji,jj) + (ffescav * fthk)  
+                  ENDIF
+                  IF( med_diag%PN_JLIM%dgsave ) THEN
+                      ! fjln2d(ji,jj) = fjln2d(ji,jj) + (fjln  * zphn * fthk) 
+                      fjln2d(ji,jj) = fjln2d(ji,jj) + (fjlim_pn * zphn * fthk) 
+                  ENDIF
+                  IF( med_diag%PN_NLIM%dgsave ) THEN
+                      fnln2d(ji,jj) = fnln2d(ji,jj) + (fnln  * zphn * fthk) 
+                  ENDIF
+                  IF( med_diag%PN_FELIM%dgsave ) THEN
+                      ffln2d(ji,jj) = ffln2d(ji,jj) + (ffln  * zphn * fthk) 
+                  ENDIF
+                  IF( med_diag%PD_JLIM%dgsave ) THEN
+                      ! fjld2d(ji,jj) = fjld2d(ji,jj) + (fjld  * zphd * fthk) 
+                      fjld2d(ji,jj) = fjld2d(ji,jj) + (fjlim_pd * zphd * fthk) 
+                  ENDIF
+                  IF( med_diag%PD_NLIM%dgsave ) THEN
+                      fnld2d(ji,jj) = fnld2d(ji,jj) + (fnld  * zphd * fthk) 
+                  ENDIF
+                  IF( med_diag%PD_FELIM%dgsave ) THEN
+                      ffld2d(ji,jj) = ffld2d(ji,jj) + (ffld  * zphd * fthk) 
+                  ENDIF
+                  IF( med_diag%PD_SILIM%dgsave ) THEN
+                      fsld2d2(ji,jj) = fsld2d2(ji,jj) + (fsld2 * zphd * fthk) 
+                  ENDIF
+                  IF( med_diag%PDSILIM2%dgsave ) THEN
+                      fsld2d(ji,jj) = fsld2d(ji,jj) + (fsld  * zphd * fthk)
+                  ENDIF
+                  !! 
+                  IF( med_diag%TOTREG_N%dgsave ) THEN
+                      fregen2d(ji,jj) = fregen2d(ji,jj) + fregen
+                  ENDIF
+                  IF( med_diag%TOTRG_SI%dgsave ) THEN
+                      fregensi2d(ji,jj) = fregensi2d(ji,jj) + fregensi
+                  ENDIF
+                  !! 
+                  IF( med_diag%FASTN%dgsave ) THEN
+                      ftempn2d(ji,jj) = ftempn2d(ji,jj) + (ftempn  * fthk)
+                  ENDIF
+                  IF( med_diag%FASTSI%dgsave ) THEN
+                      ftempsi2d(ji,jj) = ftempsi2d(ji,jj) + (ftempsi * fthk)
+                  ENDIF
+                  IF( med_diag%FASTFE%dgsave ) THEN
+                      ftempfe2d(ji,jj) =ftempfe2d(ji,jj)  + (ftempfe * fthk)  
+                  ENDIF
+                  IF( med_diag%FASTC%dgsave ) THEN
+                      ftempc2d(ji,jj) = ftempc2d(ji,jj) + (ftempc  * fthk)
+                  ENDIF
+                  IF( med_diag%FASTCA%dgsave ) THEN
+                      ftempca2d(ji,jj) = ftempca2d(ji,jj) + (ftempca * fthk)
+                  ENDIF
+                  !! 
+                  IF( med_diag%REMINN%dgsave ) THEN
+                      freminn2d(ji,jj) = freminn2d(ji,jj) + (freminn  * fthk)
+                  ENDIF
+                  IF( med_diag%REMINSI%dgsave ) THEN
+                      freminsi2d(ji,jj) = freminsi2d(ji,jj) + (freminsi * fthk)
+                  ENDIF
+                  IF( med_diag%REMINFE%dgsave ) THEN
+                      freminfe2d(ji,jj)= freminfe2d(ji,jj) + (freminfe * fthk) 
+                  ENDIF
+                  IF( med_diag%REMINC%dgsave ) THEN
+                      freminc2d(ji,jj) = freminc2d(ji,jj) + (freminc  * fthk) 
+                  ENDIF
+                  IF( med_diag%REMINCA%dgsave ) THEN
+                      freminca2d(ji,jj) = freminca2d(ji,jj) + (freminca * fthk) 
+                  ENDIF
+                  !!
+# if defined key_roam
+                  !!
+                  !! AXY (09/11/16): CMIP6 diagnostics
+                  IF( med_diag%FD_NIT3%dgsave ) THEN
+                     fd_nit3(ji,jj,jk) = ffastn(ji,jj)
+                  ENDIF
+                  IF( med_diag%FD_SIL3%dgsave ) THEN
+                     fd_sil3(ji,jj,jk) = ffastsi(ji,jj)
+                  ENDIF
+                  IF( med_diag%FD_CAR3%dgsave ) THEN
+                     fd_car3(ji,jj,jk) = ffastc(ji,jj)
+                  ENDIF
+                  IF( med_diag%FD_CAL3%dgsave ) THEN
+                     fd_cal3(ji,jj,jk) = ffastca(ji,jj)
+                  ENDIF
+                  !!
+                  IF (jk.eq.i0100) THEN
+                     IF( med_diag%RR_0100%dgsave ) THEN
+                        ffastca2d(ji,jj) =   &
+                        ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)
+                     ENDIF                     
+                  ELSE IF (jk.eq.i0500) THEN 
+                     IF( med_diag%RR_0500%dgsave ) THEN
+                        ffastca2d(ji,jj) =   &
+                        ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)
+                     ENDIF                        
+                  ELSE IF (jk.eq.i1000) THEN
+                     IF( med_diag%RR_1000%dgsave ) THEN
+                        ffastca2d(ji,jj) =   &
+                        ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)
+                     ENDIF
+                  ELSE IF (jk.eq.jmbathy) THEN
+                     IF( med_diag%IBEN_N%dgsave ) THEN
+                        iben_n2d(ji,jj) = f_sbenin_n(ji,jj)  + f_fbenin_n(ji,jj)
+                     ENDIF
+                     IF( med_diag%IBEN_FE%dgsave ) THEN
+                        iben_fe2d(ji,jj) = f_sbenin_fe(ji,jj) + f_fbenin_fe(ji,jj)
+                     ENDIF
+                     IF( med_diag%IBEN_C%dgsave ) THEN
+                        iben_c2d(ji,jj) = f_sbenin_c(ji,jj)  + f_fbenin_c(ji,jj)
+                     ENDIF
+                     IF( med_diag%IBEN_SI%dgsave ) THEN
+                        iben_si2d(ji,jj) = f_fbenin_si(ji,jj)
+                     ENDIF
+                     IF( med_diag%IBEN_CA%dgsave ) THEN
+                        iben_ca2d(ji,jj) = f_fbenin_ca(ji,jj)
+                     ENDIF
+                     IF( med_diag%OBEN_N%dgsave ) THEN
+                        oben_n2d(ji,jj) = f_benout_n(ji,jj)
+                     ENDIF
+                     IF( med_diag%OBEN_FE%dgsave ) THEN
+                        oben_fe2d(ji,jj) = f_benout_fe(ji,jj)
+                     ENDIF
+                     IF( med_diag%OBEN_C%dgsave ) THEN
+                        oben_c2d(ji,jj) = f_benout_c(ji,jj)
+                     ENDIF
+                     IF( med_diag%OBEN_SI%dgsave ) THEN
+                        oben_si2d(ji,jj) = f_benout_si(ji,jj)
+                     ENDIF
+                     IF( med_diag%OBEN_CA%dgsave ) THEN
+                        oben_ca2d(ji,jj) = f_benout_ca(ji,jj)
+                     ENDIF
+                     IF( med_diag%SFR_OCAL%dgsave ) THEN
+                        sfr_ocal2d(ji,jj) = f3_omcal(ji,jj,jk)
+                     ENDIF
+                     IF( med_diag%SFR_OARG%dgsave ) THEN
+                        sfr_oarg2d(ji,jj) =  f3_omarg(ji,jj,jk)
+                     ENDIF
+                     IF( med_diag%LYSO_CA%dgsave ) THEN
+                        lyso_ca2d(ji,jj) = f_benout_lyso_ca(ji,jj)
+                     ENDIF
+                  ENDIF
+                  !! end bathy-1 diags
+                  !!
+                  IF( med_diag%RIV_N%dgsave ) THEN
+                     rivn2d(ji,jj) = rivn2d(ji,jj) +  (f_riv_loc_n * fthk)
+                  ENDIF
+                  IF( med_diag%RIV_SI%dgsave ) THEN
+                     rivsi2d(ji,jj) = rivsi2d(ji,jj) +  (f_riv_loc_si * fthk)
+                  ENDIF
+                  IF( med_diag%RIV_C%dgsave ) THEN
+                     rivc2d(ji,jj) = rivc2d(ji,jj) +  (f_riv_loc_c * fthk)
+                  ENDIF
+                  IF( med_diag%RIV_ALK%dgsave ) THEN
+                     rivalk2d(ji,jj) = rivalk2d(ji,jj) +  (f_riv_loc_alk * fthk)
+                  ENDIF
+                  IF( med_diag%DETC%dgsave ) THEN
+                     fslowc2d(ji,jj) = fslowc2d(ji,jj) + (fslowc  * fthk)   
+                  ENDIF
+                  !! 
+                  !!              
+                  !!
+                  IF( med_diag%PN_LLOSS%dgsave ) THEN
+                     fdpn22d(ji,jj) = fdpn22d(ji,jj) + (fdpn2  * fthk)
+                  ENDIF
+                  IF( med_diag%PD_LLOSS%dgsave ) THEN
+                     fdpd22d(ji,jj) = fdpd22d(ji,jj) + (fdpd2  * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_LLOSS%dgsave ) THEN
+                     fdzmi22d(ji,jj) = fdzmi22d(ji,jj) + (fdzmi2 * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_LLOSS%dgsave ) THEN
+                     fdzme22d(ji,jj) = fdzme22d(ji,jj) + (fdzme2 * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_MES_N%dgsave ) THEN
+                     zimesn2d(ji,jj) = zimesn2d(ji,jj) +  &
+                     (xphi * (fgmipn + fgmid) * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_MES_D%dgsave ) THEN
+                     zimesd2d(ji,jj) = zimesd2d(ji,jj) + & 
+                     ((1. - xbetan) * finmi * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_MES_C%dgsave ) THEN
+                     zimesc2d(ji,jj) = zimesc2d(ji,jj) + &
+                     (xphi * ((xthetapn * fgmipn) + fgmidc) * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_MESDC%dgsave ) THEN
+                     zimesdc2d(ji,jj) = zimesdc2d(ji,jj) + &
+                     ((1. - xbetac) * ficmi * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_EXCR%dgsave ) THEN
+                     ziexcr2d(ji,jj) = ziexcr2d(ji,jj) +  (fmiexcr * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_RESP%dgsave ) THEN
+                     ziresp2d(ji,jj) = ziresp2d(ji,jj) +  (fmiresp * fthk)
+                  ENDIF
+                  IF( med_diag%ZI_GROW%dgsave ) THEN
+                     zigrow2d(ji,jj) = zigrow2d(ji,jj) + (fmigrow * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_MES_N%dgsave ) THEN
+                     zemesn2d(ji,jj) = zemesn2d(ji,jj) + &
+                     (xphi * (fgmepn + fgmepd + fgmezmi + fgmed) * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_MES_D%dgsave ) THEN
+                     zemesd2d(ji,jj) = zemesd2d(ji,jj) + &
+                     ((1. - xbetan) * finme * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_MES_C%dgsave ) THEN
+                     zemesc2d(ji,jj) = zemesc2d(ji,jj) +                         & 
+                     (xphi * ((xthetapn * fgmepn) + (xthetapd * fgmepd) +  &
+                     (xthetazmi * fgmezmi) + fgmedc) * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_MESDC%dgsave ) THEN
+                     zemesdc2d(ji,jj) = zemesdc2d(ji,jj) +  &
+                     ((1. - xbetac) * ficme * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_EXCR%dgsave ) THEN
+                     zeexcr2d(ji,jj) = zeexcr2d(ji,jj) + (fmeexcr * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_RESP%dgsave ) THEN
+                     zeresp2d(ji,jj) = zeresp2d(ji,jj) + (fmeresp * fthk)
+                  ENDIF
+                  IF( med_diag%ZE_GROW%dgsave ) THEN
+                     zegrow2d(ji,jj) = zegrow2d(ji,jj) + (fmegrow * fthk)
+                  ENDIF
+                  IF( med_diag%MDETC%dgsave ) THEN
+                     mdetc2d(ji,jj) = mdetc2d(ji,jj) + (fddc * fthk)
+                  ENDIF
+                  IF( med_diag%GMIDC%dgsave ) THEN
+                     gmidc2d(ji,jj) = gmidc2d(ji,jj) + (fgmidc * fthk)
+                  ENDIF
+                  IF( med_diag%GMEDC%dgsave ) THEN
+                     gmedc2d(ji,jj) = gmedc2d(ji,jj) + (fgmedc  * fthk)
+                  ENDIF
+                  !!
+# endif                   
+                  !!
+                  !! ** 3D diagnostics
+                  IF( med_diag%TPP3%dgsave ) THEN
+                     tpp3d(ji,jj,jk) =  (fprn * zphn) + (fprd * zphd)
+                     !CALL iom_put( "TPP3"  , tpp3d )
+                  ENDIF
+                  IF( med_diag%TPPD3%dgsave ) THEN
+                     tppd3(ji,jj,jk) =  (fprd * zphd)
+                  ENDIF
+                  
+                  IF( med_diag%REMIN3N%dgsave ) THEN
+                     remin3dn(ji,jj,jk) = fregen + (freminn * fthk) !! remineralisation
+                     !CALL iom_put( "REMIN3N"  , remin3dn )
+                  ENDIF
+                  !! IF( med_diag%PH3%dgsave ) THEN
+                  !!     CALL iom_put( "PH3"  , f3_pH )
+                  !! ENDIF
+                  !! IF( med_diag%OM_CAL3%dgsave ) THEN
+                  !!     CALL iom_put( "OM_CAL3"  , f3_omcal )
+                  !! ENDIF
+		  !! 
+		  !! AXY (09/11/16): CMIP6 diagnostics
+		  IF ( med_diag%DCALC3%dgsave   ) THEN
+                     dcalc3(ji,jj,jk) = freminca
+                  ENDIF
+		  IF ( med_diag%FEDISS3%dgsave  ) THEN
+                     fediss3(ji,jj,jk) = ffetop
+                  ENDIF
+		  IF ( med_diag%FESCAV3%dgsave  ) THEN
+                     fescav3(ji,jj,jk) = ffescav
+                  ENDIF
+		  IF ( med_diag%MIGRAZP3%dgsave ) THEN
+                     migrazp3(ji,jj,jk) = fgmipn * xthetapn
+                  ENDIF
+		  IF ( med_diag%MIGRAZD3%dgsave ) THEN
+                     migrazd3(ji,jj,jk) = fgmidc
+                  ENDIF
+		  IF ( med_diag%MEGRAZP3%dgsave ) THEN
+                     megrazp3(ji,jj,jk) = (fgmepn * xthetapn) + (fgmepd * xthetapd)
+                  ENDIF
+		  IF ( med_diag%MEGRAZD3%dgsave ) THEN
+                     megrazd3(ji,jj,jk) = fgmedc
+                  ENDIF
+		  IF ( med_diag%MEGRAZZ3%dgsave ) THEN
+                     megrazz3(ji,jj,jk) = (fgmezmi * xthetazmi)
+                  ENDIF
+		  IF ( med_diag%PBSI3%dgsave    ) THEN
+                     pbsi3(ji,jj,jk)    = (fprds * zpds)
+                  ENDIF
+		  IF ( med_diag%PCAL3%dgsave    ) THEN
+                     pcal3(ji,jj,jk)    = ftempca
+                  ENDIF
+		  IF ( med_diag%REMOC3%dgsave   ) THEN
+                     remoc3(ji,jj,jk)   = freminc
+                  ENDIF
+		  IF ( med_diag%PNLIMJ3%dgsave  ) THEN
+                     ! pnlimj3(ji,jj,jk)  = fjln
+                     pnlimj3(ji,jj,jk)  = fjlim_pn
+                  ENDIF
+		  IF ( med_diag%PNLIMN3%dgsave  ) THEN
+                     pnlimn3(ji,jj,jk)  = fnln
+                  ENDIF
+		  IF ( med_diag%PNLIMFE3%dgsave ) THEN
+                     pnlimfe3(ji,jj,jk) = ffln
+                  ENDIF
+		  IF ( med_diag%PDLIMJ3%dgsave  ) THEN
+                     ! pdlimj3(ji,jj,jk)  = fjld
+                     pdlimj3(ji,jj,jk)  = fjlim_pd
+                  ENDIF
+		  IF ( med_diag%PDLIMN3%dgsave  ) THEN
+                     pdlimn3(ji,jj,jk)  = fnld
+                  ENDIF
+		  IF ( med_diag%PDLIMFE3%dgsave ) THEN
+                     pdlimfe3(ji,jj,jk) = ffld
+                  ENDIF
+		  IF ( med_diag%PDLIMSI3%dgsave ) THEN
+                     pdlimsi3(ji,jj,jk) = fsld2
+                  ENDIF
+                  !!
+                  !! ** Without using iom_use
+               ELSE IF( ln_diatrc ) THEN
+#   if defined key_debug_medusa
+                  IF (lwp) write (numout,*) 'trc_bio_medusa: diag in ij-jj-jk ln_diatrc'
+                  CALL flush(numout)
+#   endif
+                  !!----------------------------------------------------------------------
+                  !! Prepare 2D diagnostics
+                  !!----------------------------------------------------------------------
+                  !!
+                  !! if ((kt / 240*240).eq.kt) then
+                  !!    IF (lwp) write (*,*) '*******!MEDUSA DIAADD!*******',kt
+                  !! endif     
+                  trc2d(ji,jj,1)  =  ftot_n(ji,jj)                             !! nitrogen inventory
+                  trc2d(ji,jj,2)  =  ftot_si(ji,jj)                            !! silicon  inventory
+                  trc2d(ji,jj,3)  =  ftot_fe(ji,jj)                            !! iron     inventory
+                  trc2d(ji,jj,4)  = trc2d(ji,jj,4)  + (fprn  * zphn * fthk)    !! non-diatom production
+                  trc2d(ji,jj,5)  = trc2d(ji,jj,5)  + (fdpn         * fthk)    !! non-diatom non-grazing losses
+                  trc2d(ji,jj,6)  = trc2d(ji,jj,6)  + (fprd  * zphd * fthk)    !! diatom production
+                  trc2d(ji,jj,7)  = trc2d(ji,jj,7)  + (fdpd         * fthk)    !! diatom non-grazing losses
+                  !! diagnostic field  8 is (ostensibly) supplied by trcsed.F            
+                  trc2d(ji,jj,9)  = trc2d(ji,jj,9)  + (fprds * zpds * fthk)    !! diatom silicon production
+                  trc2d(ji,jj,10) = trc2d(ji,jj,10) + (fsdiss  * fthk)         !! diatom silicon dissolution
+                  trc2d(ji,jj,11) = trc2d(ji,jj,11) + (fgmipn  * fthk)         !! microzoo grazing on non-diatoms
+                  trc2d(ji,jj,12) = trc2d(ji,jj,12) + (fgmid   * fthk)         !! microzoo grazing on detrital nitrogen
+                  trc2d(ji,jj,13) = trc2d(ji,jj,13) + (fdzmi   * fthk)         !! microzoo non-grazing losses
+                  trc2d(ji,jj,14) = trc2d(ji,jj,14) + (fgmepn  * fthk)         !! mesozoo  grazing on non-diatoms
+                  trc2d(ji,jj,15) = trc2d(ji,jj,15) + (fgmepd  * fthk)         !! mesozoo  grazing on diatoms
+                  trc2d(ji,jj,16) = trc2d(ji,jj,16) + (fgmezmi * fthk)         !! mesozoo  grazing on microzoo
+                  trc2d(ji,jj,17) = trc2d(ji,jj,17) + (fgmed   * fthk)         !! mesozoo  grazing on detrital nitrogen
+                  trc2d(ji,jj,18) = trc2d(ji,jj,18) + (fdzme   * fthk)         !! mesozoo  non-grazing losses
+                  !! diagnostic field 19 is (ostensibly) supplied by trcexp.F
+                  trc2d(ji,jj,20) = trc2d(ji,jj,20) + (fslown  * fthk)         !! slow sinking detritus N production
+                  trc2d(ji,jj,21) = trc2d(ji,jj,21) + (fdd     * fthk)         !! detrital remineralisation
+                  trc2d(ji,jj,22) = trc2d(ji,jj,22) + (ffetop  * fthk)         !! aeolian  iron addition
+                  trc2d(ji,jj,23) = trc2d(ji,jj,23) + (ffebot  * fthk)         !! seafloor iron addition
+                  trc2d(ji,jj,24) = trc2d(ji,jj,24) + (ffescav * fthk)         !! "free" iron scavenging
+                  trc2d(ji,jj,25) = trc2d(ji,jj,25) + (fjlim_pn * zphn * fthk) !! non-diatom J  limitation term 
+                  trc2d(ji,jj,26) = trc2d(ji,jj,26) + (fnln  * zphn * fthk)    !! non-diatom N  limitation term 
+                  trc2d(ji,jj,27) = trc2d(ji,jj,27) + (ffln  * zphn * fthk)    !! non-diatom Fe limitation term 
+                  trc2d(ji,jj,28) = trc2d(ji,jj,28) + (fjlim_pd * zphd * fthk) !! diatom     J  limitation term 
+                  trc2d(ji,jj,29) = trc2d(ji,jj,29) + (fnld  * zphd * fthk)    !! diatom     N  limitation term 
+                  trc2d(ji,jj,30) = trc2d(ji,jj,30) + (ffld  * zphd * fthk)    !! diatom     Fe limitation term 
+                  trc2d(ji,jj,31) = trc2d(ji,jj,31) + (fsld2 * zphd * fthk)    !! diatom     Si limitation term 
+                  trc2d(ji,jj,32) = trc2d(ji,jj,32) + (fsld  * zphd * fthk)    !! diatom     Si uptake limitation term
+                  if (jk.eq.i0100) trc2d(ji,jj,33) = fslownflux(ji,jj)         !! slow detritus flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,34) = fslownflux(ji,jj)         !! slow detritus flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,35) = fslownflux(ji,jj)         !! slow detritus flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,36) = fslownflux(ji,jj)         !! slow detritus flux at 1000 m
+                  trc2d(ji,jj,37) = trc2d(ji,jj,37) + fregen                   !! non-fast N  full column regeneration
+                  trc2d(ji,jj,38) = trc2d(ji,jj,38) + fregensi                 !! non-fast Si full column regeneration
+                  if (jk.eq.i0100) trc2d(ji,jj,39) = trc2d(ji,jj,37)           !! non-fast N  regeneration to  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,40) = trc2d(ji,jj,37)           !! non-fast N  regeneration to  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,41) = trc2d(ji,jj,37)           !! non-fast N  regeneration to  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,42) = trc2d(ji,jj,37)           !! non-fast N  regeneration to 1000 m
+                  trc2d(ji,jj,43) = trc2d(ji,jj,43) + (ftempn  * fthk)         !! fast sinking detritus N production
+                  trc2d(ji,jj,44) = trc2d(ji,jj,44) + (ftempsi * fthk)         !! fast sinking detritus Si production
+                  trc2d(ji,jj,45) = trc2d(ji,jj,45) + (ftempfe * fthk)         !! fast sinking detritus Fe production
+                  trc2d(ji,jj,46) = trc2d(ji,jj,46) + (ftempc  * fthk)         !! fast sinking detritus C production
+                  trc2d(ji,jj,47) = trc2d(ji,jj,47) + (ftempca * fthk)         !! fast sinking detritus CaCO3 production
+                  if (jk.eq.i0100) trc2d(ji,jj,48) = ffastn(ji,jj)             !! fast detritus N  flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,49) = ffastn(ji,jj)             !! fast detritus N  flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,50) = ffastn(ji,jj)             !! fast detritus N  flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,51) = ffastn(ji,jj)             !! fast detritus N  flux at 1000 m
+                  if (jk.eq.i0100) trc2d(ji,jj,52) = fregenfast(ji,jj)         !! N  regeneration to  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,53) = fregenfast(ji,jj)         !! N  regeneration to  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,54) = fregenfast(ji,jj)         !! N  regeneration to  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,55) = fregenfast(ji,jj)         !! N  regeneration to 1000 m
+                  if (jk.eq.i0100) trc2d(ji,jj,56) = ffastsi(ji,jj)            !! fast detritus Si flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,57) = ffastsi(ji,jj)            !! fast detritus Si flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,58) = ffastsi(ji,jj)            !! fast detritus Si flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,59) = ffastsi(ji,jj)            !! fast detritus Si flux at 1000 m
+                  if (jk.eq.i0100) trc2d(ji,jj,60) = fregenfastsi(ji,jj)       !! Si regeneration to  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,61) = fregenfastsi(ji,jj)       !! Si regeneration to  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,62) = fregenfastsi(ji,jj)       !! Si regeneration to  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,63) = fregenfastsi(ji,jj)       !! Si regeneration to 1000 m
+                  trc2d(ji,jj,64) = trc2d(ji,jj,64) + (freminn  * fthk)        !! sum of fast-sinking N  fluxes
+                  trc2d(ji,jj,65) = trc2d(ji,jj,65) + (freminsi * fthk)        !! sum of fast-sinking Si fluxes
+                  trc2d(ji,jj,66) = trc2d(ji,jj,66) + (freminfe * fthk)        !! sum of fast-sinking Fe fluxes
+                  trc2d(ji,jj,67) = trc2d(ji,jj,67) + (freminc  * fthk)        !! sum of fast-sinking C  fluxes
+                  trc2d(ji,jj,68) = trc2d(ji,jj,68) + (freminca * fthk)        !! sum of fast-sinking Ca fluxes
+                  if (jk.eq.jmbathy) then
+                     trc2d(ji,jj,69) = fsedn(ji,jj)                                   !! N  sedimentation flux                                  
+                     trc2d(ji,jj,70) = fsedsi(ji,jj)                                  !! Si sedimentation flux
+                     trc2d(ji,jj,71) = fsedfe(ji,jj)                                  !! Fe sedimentation flux
+                     trc2d(ji,jj,72) = fsedc(ji,jj)                                   !! C  sedimentation flux
+                     trc2d(ji,jj,73) = fsedca(ji,jj)                                  !! Ca sedimentation flux
+                  endif
+                  if (jk.eq.1)  trc2d(ji,jj,74) = qsr(ji,jj)
+                  if (jk.eq.1)  trc2d(ji,jj,75) = xpar(ji,jj,jk)
+                  !! if (jk.eq.1)  trc2d(ji,jj,75) = real(iters)
+                  !! diagnostic fields 76 to 80 calculated below
+                  trc2d(ji,jj,81) = trc2d(ji,jj,81) + fprn_ml(ji,jj)           !! mixed layer non-diatom production
+                  trc2d(ji,jj,82) = trc2d(ji,jj,82) + fprd_ml(ji,jj)           !! mixed layer     diatom production
+# if defined key_gulf_finland
+                  if (jk.eq.1)  trc2d(ji,jj,83) = real(ibio_switch)            !! Gulf of Finland check
+# else
+                  trc2d(ji,jj,83) = ocal_ccd(ji,jj)                            !! calcite CCD depth
+# endif
+                  trc2d(ji,jj,84) = fccd(ji,jj)                                !! last model level above calcite CCD depth
+                  if (jk.eq.1)     trc2d(ji,jj,85) = xFree(ji,jj)              !! surface "free" iron
+                  if (jk.eq.i0200) trc2d(ji,jj,86) = xFree(ji,jj)              !! "free" iron at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,87) = xFree(ji,jj)              !! "free" iron at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,88) = xFree(ji,jj)              !! "free" iron at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,89) = xFree(ji,jj)              !! "free" iron at 1000 m
+                  !! AXY (27/06/12): extract "euphotic depth"
+                  if (jk.eq.1)     trc2d(ji,jj,90) = xze(ji,jj)
+                  !! 
+# if defined key_roam
+                  !! ROAM provisionally has access to a further 20 2D diagnostics
+                  if (jk .eq. 1) then
+                     trc2d(ji,jj,91)  = trc2d(ji,jj,91)  + f_wind              !! surface wind
+                     trc2d(ji,jj,92)  = trc2d(ji,jj,92)  + f_pco2atm           !! atmospheric pCO2
+                     trc2d(ji,jj,93)  = trc2d(ji,jj,93)  + f_ph                !! ocean pH
+                     trc2d(ji,jj,94)  = trc2d(ji,jj,94)  + f_pco2w             !! ocean pCO2
+                     trc2d(ji,jj,95)  = trc2d(ji,jj,95)  + f_h2co3             !! ocean H2CO3 conc.
+                     trc2d(ji,jj,96)  = trc2d(ji,jj,96)  + f_hco3              !! ocean HCO3 conc.
+                     trc2d(ji,jj,97)  = trc2d(ji,jj,97)  + f_co3               !! ocean CO3 conc.
+                     trc2d(ji,jj,98)  = trc2d(ji,jj,98)  + f_co2flux           !! air-sea CO2 flux
+                     trc2d(ji,jj,99)  = trc2d(ji,jj,99)  + f_omcal(ji,jj)      !! ocean omega calcite 
+                     trc2d(ji,jj,100) = trc2d(ji,jj,100) + f_omarg(ji,jj)      !! ocean omega aragonite
+                     trc2d(ji,jj,101) = trc2d(ji,jj,101) + f_TDIC              !! ocean TDIC
+                     trc2d(ji,jj,102) = trc2d(ji,jj,102) + f_TALK              !! ocean TALK
+                     trc2d(ji,jj,103) = trc2d(ji,jj,103) + f_kw660             !! surface kw660
+                     trc2d(ji,jj,104) = trc2d(ji,jj,104) + f_pp0               !! surface pressure
+                     trc2d(ji,jj,105) = trc2d(ji,jj,105) + f_o2flux            !! air-sea O2 flux
+                     trc2d(ji,jj,106) = trc2d(ji,jj,106) + f_o2sat             !! ocean O2 saturation
+                     trc2d(ji,jj,107) = f2_ccd_cal(ji,jj)                      !! depth calcite CCD
+                     trc2d(ji,jj,108) = f2_ccd_arg(ji,jj)                      !! depth aragonite CCD
+                  endif
+                  if (jk .eq. jmbathy) then
+                     trc2d(ji,jj,109) = f3_omcal(ji,jj,jk)                     !! seafloor omega calcite
+                     trc2d(ji,jj,110) = f3_omarg(ji,jj,jk)                     !! seafloor omega aragonite
+                  endif
+                  !! diagnostic fields 111 to 117 calculated below
+                  if (jk.eq.i0100) trc2d(ji,jj,118) = ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)  !! rain ratio at  100 m
+                  if (jk.eq.i0500) trc2d(ji,jj,119) = ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)  !! rain ratio at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,120) = ffastca(ji,jj)/MAX(ffastc(ji,jj), rsmall)  !! rain ratio at 1000 m
+                  !! AXY (18/01/12): benthic flux diagnostics
+                  if (jk.eq.jmbathy) then
+                     trc2d(ji,jj,121) = f_sbenin_n(ji,jj)  + f_fbenin_n(ji,jj)
+                     trc2d(ji,jj,122) = f_sbenin_fe(ji,jj) + f_fbenin_fe(ji,jj)
+                     trc2d(ji,jj,123) = f_sbenin_c(ji,jj)  + f_fbenin_c(ji,jj)
+                     trc2d(ji,jj,124) = f_fbenin_si(ji,jj)
+                     trc2d(ji,jj,125) = f_fbenin_ca(ji,jj)
+                     trc2d(ji,jj,126) = f_benout_n(ji,jj)
+                     trc2d(ji,jj,127) = f_benout_fe(ji,jj)
+                     trc2d(ji,jj,128) = f_benout_c(ji,jj)
+                     trc2d(ji,jj,129) = f_benout_si(ji,jj)
+                     trc2d(ji,jj,130) = f_benout_ca(ji,jj)
+                  endif
+                  !! diagnostics fields 131 to 135 calculated below
+                  trc2d(ji,jj,136) = f_runoff(ji,jj)
+                  !! AXY (19/07/12): amended to allow for riverine nutrient addition below surface
+                  trc2d(ji,jj,137) = trc2d(ji,jj,137) + (f_riv_loc_n * fthk)
+                  trc2d(ji,jj,138) = trc2d(ji,jj,138) + (f_riv_loc_si * fthk)
+                  trc2d(ji,jj,139) = trc2d(ji,jj,139) + (f_riv_loc_c * fthk)
+                  trc2d(ji,jj,140) = trc2d(ji,jj,140) + (f_riv_loc_alk * fthk)
+                  trc2d(ji,jj,141) = trc2d(ji,jj,141) + (fslowc  * fthk)       !! slow sinking detritus C production
+                  if (jk.eq.i0100) trc2d(ji,jj,142) = fslowcflux(ji,jj)        !! slow detritus flux at  100 m
+                  if (jk.eq.i0200) trc2d(ji,jj,143) = fslowcflux(ji,jj)        !! slow detritus flux at  200 m
+                  if (jk.eq.i0500) trc2d(ji,jj,144) = fslowcflux(ji,jj)        !! slow detritus flux at  500 m
+                  if (jk.eq.i1000) trc2d(ji,jj,145) = fslowcflux(ji,jj)        !! slow detritus flux at 1000 m
+                  trc2d(ji,jj,146)  = trc2d(ji,jj,146)  + ftot_c(ji,jj)        !! carbon     inventory
+                  trc2d(ji,jj,147)  = trc2d(ji,jj,147)  + ftot_a(ji,jj)        !! alkalinity inventory
+                  trc2d(ji,jj,148)  = trc2d(ji,jj,148)  + ftot_o2(ji,jj)       !! oxygen     inventory
+                  if (jk.eq.jmbathy) then
+                     trc2d(ji,jj,149) = f_benout_lyso_ca(ji,jj)
+                  endif
+                  trc2d(ji,jj,150) = fcomm_resp(ji,jj) * fthk                  !! community respiration
+		  !!
+		  !! AXY (14/02/14): a Valentines Day gift to BASIN - a shedload of new
+                  !!                 diagnostics that they'll most likely never need!
+                  !!                 (actually, as with all such gifts, I'm giving them
+                  !!                 some things I'd like myself!)
+                  !! 
+                  !! ----------------------------------------------------------------------
+                  !! linear losses
+                  !! non-diatom
+                  trc2d(ji,jj,151) = trc2d(ji,jj,151) + (fdpn2  * fthk)
+                  !! diatom
+                  trc2d(ji,jj,152) = trc2d(ji,jj,152) + (fdpd2  * fthk)
+                  !! microzooplankton
+                  trc2d(ji,jj,153) = trc2d(ji,jj,153) + (fdzmi2 * fthk)
+                  !! mesozooplankton
+                  trc2d(ji,jj,154) = trc2d(ji,jj,154) + (fdzme2 * fthk)
+                  !! ----------------------------------------------------------------------
+                  !! microzooplankton grazing
+                  !! microzooplankton messy -> N
+                  trc2d(ji,jj,155) = trc2d(ji,jj,155) + (xphi * (fgmipn + fgmid) * fthk)
+                  !! microzooplankton messy -> D
+                  trc2d(ji,jj,156) = trc2d(ji,jj,156) + ((1. - xbetan) * finmi * fthk)
+                  !! microzooplankton messy -> DIC
+                  trc2d(ji,jj,157) = trc2d(ji,jj,157) + (xphi * ((xthetapn * fgmipn) + fgmidc) * fthk)
+                  !! microzooplankton messy -> Dc
+                  trc2d(ji,jj,158) = trc2d(ji,jj,158) + ((1. - xbetac) * ficmi * fthk)
+                  !! microzooplankton excretion
+                  trc2d(ji,jj,159) = trc2d(ji,jj,159) + (fmiexcr * fthk)
+                  !! microzooplankton respiration
+                  trc2d(ji,jj,160) = trc2d(ji,jj,160) + (fmiresp * fthk)
+                  !! microzooplankton growth
+                  trc2d(ji,jj,161) = trc2d(ji,jj,161) + (fmigrow * fthk)
+                  !! ----------------------------------------------------------------------
+                  !! mesozooplankton grazing
+                  !! mesozooplankton messy -> N
+                  trc2d(ji,jj,162) = trc2d(ji,jj,162) + (xphi * (fgmepn + fgmepd + fgmezmi + fgmed) * fthk)
+                  !! mesozooplankton messy -> D
+                  trc2d(ji,jj,163) = trc2d(ji,jj,163) + ((1. - xbetan) * finme * fthk)
+                  !! mesozooplankton messy -> DIC
+                  trc2d(ji,jj,164) = trc2d(ji,jj,164) + (xphi * ((xthetapn * fgmepn) + (xthetapd * fgmepd) + &
+                  &                  (xthetazmi * fgmezmi) + fgmedc) * fthk)
+                  !! mesozooplankton messy -> Dc
+                  trc2d(ji,jj,165) = trc2d(ji,jj,165) + ((1. - xbetac) * ficme * fthk)
+                  !! mesozooplankton excretion
+                  trc2d(ji,jj,166) = trc2d(ji,jj,166) + (fmeexcr * fthk)
+                  !! mesozooplankton respiration
+                  trc2d(ji,jj,167) = trc2d(ji,jj,167) + (fmeresp * fthk)
+                  !! mesozooplankton growth
+                  trc2d(ji,jj,168) = trc2d(ji,jj,168) + (fmegrow * fthk)
+                  !! ----------------------------------------------------------------------
+                  !! miscellaneous
+                  trc2d(ji,jj,169) = trc2d(ji,jj,169) + (fddc    * fthk) !! detrital C remineralisation
+                  trc2d(ji,jj,170) = trc2d(ji,jj,170) + (fgmidc  * fthk) !! microzoo grazing on detrital carbon
+                  trc2d(ji,jj,171) = trc2d(ji,jj,171) + (fgmedc  * fthk) !! mesozoo  grazing on detrital carbon
+                  !!
+                  !! ----------------------------------------------------------------------
+		  !!
+		  !! AXY (23/10/14): extract primary production related surface fields to
+		  !!                 deal with diel cycle issues; hijacking BASIN 150m
+		  !!                 diagnostics to do so (see commented out diagnostics
+		  !!                 below this section)
+		  !!
+		  !! extract fields at surface
+		 !! if (jk .eq. 1) then
+                 !!    trc2d(ji,jj,172) = zchn              !! Pn chlorophyll
+                 !!    trc2d(ji,jj,173) = zphn              !! Pn biomass
+                 !!    trc2d(ji,jj,174) = fjln              !! Pn J-term
+                 !!    trc2d(ji,jj,175) = (fprn * zphn)     !! Pn PP
+                 !!    trc2d(ji,jj,176) = zchd              !! Pd chlorophyll
+                 !!    trc2d(ji,jj,177) = zphd              !! Pd biomass
+                 !!    trc2d(ji,jj,178) = fjld              !! Pd J-term
+                 !!    trc2d(ji,jj,179) = xpar(ji,jj,jk)    !! Pd PP
+                 !!    trc2d(ji,jj,180) = loc_T             !! local temperature
+                 !! endif
+		 !! !!
+		 !! !! extract fields at 50m (actually 44-50m)
+		 !! if (jk .eq. 18) then
+                 !!    trc2d(ji,jj,181) = zchn              !! Pn chlorophyll
+                 !!    trc2d(ji,jj,182) = zphn              !! Pn biomass
+                 !!    trc2d(ji,jj,183) = fjln              !! Pn J-term
+                 !!    trc2d(ji,jj,184) = (fprn * zphn)     !! Pn PP
+                 !!    trc2d(ji,jj,185) = zchd              !! Pd chlorophyll
+                 !!    trc2d(ji,jj,186) = zphd              !! Pd biomass
+                 !!    trc2d(ji,jj,187) = fjld              !! Pd J-term
+                 !!    trc2d(ji,jj,188) = xpar(ji,jj,jk)    !! Pd PP
+                 !!    trc2d(ji,jj,189) = loc_T             !! local temperature
+                 !! endif
+		 !! !!
+		 !! !! extract fields at 100m
+		 !! if (jk .eq. i0100) then
+                 !!    trc2d(ji,jj,190) = zchn              !! Pn chlorophyll
+                 !!    trc2d(ji,jj,191) = zphn              !! Pn biomass
+                 !!    trc2d(ji,jj,192) = fjln              !! Pn J-term
+                 !!    trc2d(ji,jj,193) = (fprn * zphn)     !! Pn PP
+                 !!    trc2d(ji,jj,194) = zchd              !! Pd chlorophyll
+                 !!    trc2d(ji,jj,195) = zphd              !! Pd biomass
+                 !!    trc2d(ji,jj,196) = fjld              !! Pd J-term
+                 !!    trc2d(ji,jj,197) = xpar(ji,jj,jk)    !! Pd PP
+                 !!    trc2d(ji,jj,198) = loc_T             !! local temperature
+                 !! endif
+                 !!
+                  !! extract relevant BASIN fields at 150m
+                  if (jk .eq. i0150) then
+                     trc2d(ji,jj,172) = trc2d(ji,jj,4)    !! Pn PP
+                     trc2d(ji,jj,173) = trc2d(ji,jj,151)  !! Pn linear loss
+                     trc2d(ji,jj,174) = trc2d(ji,jj,5)    !! Pn non-linear loss
+                     trc2d(ji,jj,175) = trc2d(ji,jj,11)   !! Pn grazing to Zmi
+                     trc2d(ji,jj,176) = trc2d(ji,jj,14)   !! Pn grazing to Zme
+                     trc2d(ji,jj,177) = trc2d(ji,jj,6)    !! Pd PP
+                     trc2d(ji,jj,178) = trc2d(ji,jj,152)  !! Pd linear loss
+                     trc2d(ji,jj,179) = trc2d(ji,jj,7)    !! Pd non-linear loss
+                     trc2d(ji,jj,180) = trc2d(ji,jj,15)   !! Pd grazing to Zme
+                     trc2d(ji,jj,181) = trc2d(ji,jj,12)   !! Zmi grazing on D
+                     trc2d(ji,jj,182) = trc2d(ji,jj,170)  !! Zmi grazing on Dc
+                     trc2d(ji,jj,183) = trc2d(ji,jj,155)  !! Zmi messy feeding loss to N
+                     trc2d(ji,jj,184) = trc2d(ji,jj,156)  !! Zmi messy feeding loss to D
+                     trc2d(ji,jj,185) = trc2d(ji,jj,157)  !! Zmi messy feeding loss to DIC
+                     trc2d(ji,jj,186) = trc2d(ji,jj,158)  !! Zmi messy feeding loss to Dc
+                     trc2d(ji,jj,187) = trc2d(ji,jj,159)  !! Zmi excretion
+                     trc2d(ji,jj,188) = trc2d(ji,jj,160)  !! Zmi respiration
+                     trc2d(ji,jj,189) = trc2d(ji,jj,161)  !! Zmi growth
+                     trc2d(ji,jj,190) = trc2d(ji,jj,153)  !! Zmi linear loss
+                     trc2d(ji,jj,191) = trc2d(ji,jj,13)   !! Zmi non-linear loss
+                     trc2d(ji,jj,192) = trc2d(ji,jj,16)   !! Zmi grazing to Zme
+                     trc2d(ji,jj,193) = trc2d(ji,jj,17)   !! Zme grazing on D
+                     trc2d(ji,jj,194) = trc2d(ji,jj,171)  !! Zme grazing on Dc
+                     trc2d(ji,jj,195) = trc2d(ji,jj,162)  !! Zme messy feeding loss to N
+                     trc2d(ji,jj,196) = trc2d(ji,jj,163)  !! Zme messy feeding loss to D
+                     trc2d(ji,jj,197) = trc2d(ji,jj,164)  !! Zme messy feeding loss to DIC
+                     trc2d(ji,jj,198) = trc2d(ji,jj,165)  !! Zme messy feeding loss to Dc
+                     trc2d(ji,jj,199) = trc2d(ji,jj,166)  !! Zme excretion
+                     trc2d(ji,jj,200) = trc2d(ji,jj,167)  !! Zme respiration
+                     trc2d(ji,jj,201) = trc2d(ji,jj,168)  !! Zme growth
+                     trc2d(ji,jj,202) = trc2d(ji,jj,154)  !! Zme linear loss
+                     trc2d(ji,jj,203) = trc2d(ji,jj,18)   !! Zme non-linear loss
+                     trc2d(ji,jj,204) = trc2d(ji,jj,20)   !! Slow detritus production, N
+                     trc2d(ji,jj,205) = trc2d(ji,jj,21)   !! Slow detritus remineralisation, N
+                     trc2d(ji,jj,206) = trc2d(ji,jj,141)  !! Slow detritus production, C
+                     trc2d(ji,jj,207) = trc2d(ji,jj,169)  !! Slow detritus remineralisation, C
+                     trc2d(ji,jj,208) = trc2d(ji,jj,43)   !! Fast detritus production, N
+                     trc2d(ji,jj,209) = trc2d(ji,jj,21)   !! Fast detritus remineralisation, N
+                     trc2d(ji,jj,210) = trc2d(ji,jj,64)   !! Fast detritus production, C
+                     trc2d(ji,jj,211) = trc2d(ji,jj,67)   !! Fast detritus remineralisation, C
+                     trc2d(ji,jj,212) = trc2d(ji,jj,150)  !! Community respiration
+                     trc2d(ji,jj,213) = fslownflux(ji,jj) !! Slow detritus N flux at 150 m
+                     trc2d(ji,jj,214) = fslowcflux(ji,jj) !! Slow detritus C flux at 150 m
+                     trc2d(ji,jj,215) = ffastn(ji,jj)     !! Fast detritus N flux at 150 m
+                     trc2d(ji,jj,216) = ffastc(ji,jj)     !! Fast detritus C flux at 150 m
+                  endif
+                  !! 
+                  !! Jpalm (11-08-2014)
+                  !! Add UKESM1 diagnoatics 
+                  !!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+                  if ((jk .eq. 1) .and.( jdms.eq.1)) then
+                     trc2d(ji,jj,221) = dms_surf          !! DMS surface concentration 
+                     !! AXY (13/03/15): add in other DMS estimates
+                     trc2d(ji,jj,222) = dms_andr          !! DMS surface concentration 
+                     trc2d(ji,jj,223) = dms_simo          !! DMS surface concentration 
+                     trc2d(ji,jj,224) = dms_aran          !! DMS surface concentration 
+                     trc2d(ji,jj,225) = dms_hall          !! DMS surface concentration 
+                  endif
+# endif
+                  !! other possible future diagnostics include:
+                  !!   - integrated tracer values (esp. biological)
+                  !!   - mixed layer tracer values
+                  !!   - sub-surface chlorophyll maxima (plus depth)
+                  !!   - different mixed layer depth criteria (T, sigma, var. sigma)
+
+                  !!----------------------------------------------------------------------
+                  !! Prepare 3D diagnostics
+                  !!----------------------------------------------------------------------
+                  !!
+                  trc3d(ji,jj,jk,1)  = ((fprn + fprd) * zphn)     !! primary production  
+                  trc3d(ji,jj,jk,2)  = fslownflux(ji,jj) + ffastn(ji,jj) !! detrital flux
+                  trc3d(ji,jj,jk,3)  = fregen + (freminn * fthk)  !! remineralisation
+# if defined key_roam
+                  trc3d(ji,jj,jk,4)  = f3_pH(ji,jj,jk)            !! pH
+                  trc3d(ji,jj,jk,5)  = f3_omcal(ji,jj,jk)         !! omega calcite
+# else
+                  trc3d(ji,jj,jk,4)  = ffastsi(ji,jj)             !! fast Si flux
+# endif
+             ENDIF   ! end of ln_diatrc option
+             !! CLOSE wet point IF..THEN loop
+            endif
+         !! CLOSE horizontal loops
+         ENDDO
+         ENDDO
+         !!
+             IF( lk_iomput  .AND.  .NOT.  ln_diatrc  ) THEN
+                 !! first - 2D diag implemented 
+                 !!         on every K level
+                 !!-----------------------------------------
+                 !!  --
+                 !!second - 2d specific k level diags
+                 !!
+                 !!-----------------------------------------
+                 IF (jk.eq.1) THEN
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: diag jk = 1'
+                     CALL flush(numout)
+#   endif
+                     IF( med_diag%MED_QSR%dgsave ) THEN
+                         CALL iom_put( "MED_QSR"  , qsr ) !
+                     ENDIF
+                     IF( med_diag%MED_XPAR%dgsave ) THEN
+                         CALL iom_put( "MED_XPAR"  , xpar(:,:,jk) ) !
+                     ENDIF       
+                     IF( med_diag%OCAL_CCD%dgsave ) THEN
+                         CALL iom_put( "OCAL_CCD"  , ocal_ccd ) !
+                     ENDIF
+                     IF( med_diag%FE_0000%dgsave ) THEN
+                         CALL iom_put( "FE_0000"  , xFree ) !
+                     ENDIF                     
+                     IF( med_diag%MED_XZE%dgsave ) THEN
+                         CALL iom_put( "MED_XZE"  , xze ) !
+                     ENDIF 
+# if defined key_roam                     
+                     IF( med_diag%WIND%dgsave ) THEN
+                         CALL iom_put( "WIND"  , wndm )
+                     ENDIF
+                     IF( med_diag%ATM_PCO2%dgsave ) THEN
+                         CALL iom_put( "ATM_PCO2"  , f_pco2a2d )
+                         CALL wrk_dealloc( jpi, jpj,    f_pco2a2d  )
+                     ENDIF
+                     IF( med_diag%OCN_PH%dgsave ) THEN
+                         zw2d(:,:) = f3_pH(:,:,jk)
+                         CALL iom_put( "OCN_PH"  , zw2d )
+                     ENDIF
+                     IF( med_diag%OCN_PCO2%dgsave ) THEN
+                        CALL iom_put( "OCN_PCO2"  , f_pco2w2d )
+                        CALL wrk_dealloc( jpi, jpj,   f_pco2w2d   )
+                     ENDIF
+                     IF( med_diag%OCNH2CO3%dgsave ) THEN
+                         zw2d(:,:) = f3_h2co3(:,:,jk)
+                         CALL iom_put( "OCNH2CO3"  , zw2d )
+                     ENDIF
+                     IF( med_diag%OCN_HCO3%dgsave ) THEN
+                         zw2d(:,:) = f3_hco3(:,:,jk)
+                         CALL iom_put( "OCN_HCO3"  , zw2d )
+                     ENDIF
+                     IF( med_diag%OCN_CO3%dgsave ) THEN
+                         zw2d(:,:) = f3_co3(:,:,jk)
+                         CALL iom_put( "OCN_CO3"  , zw2d )
+                     ENDIF
+                     IF( med_diag%CO2FLUX%dgsave ) THEN
+                        CALL iom_put( "CO2FLUX"  , f_co2flux2d )
+                        CALL wrk_dealloc( jpi, jpj,   f_co2flux2d   )
+                     ENDIF
+                     !! 
+                     !! AXY (10/11/16): repeat CO2 flux diagnostic in UKMO/CMIP6 units; this
+                     !!                 both outputs the CO2 flux in specified units and
+                     !!                 sends the resulting field to the coupler
+                     !! JPALM (17/11/16): put CO2 flux (fgco2) alloc/unalloc/pass to zn 
+                     !!                 out of diag list request 
+                     CALL lbc_lnk( fgco2(:,:),'T',1. )
+                     IF( med_diag%FGCO2%dgsave ) THEN
+                         CALL iom_put( "FGCO2"  , fgco2 )
+                     ENDIF
+                     !! JPALM (17/11/16): should mv this fgco2 part 
+                     !!                   out of lk_iomput loop
+                     zb_co2_flx = zn_co2_flx
+                     zn_co2_flx = fgco2
+                     IF (lk_oasis) THEN
+                        CO2Flux_out_cpl = zn_co2_flx
+                     ENDIF
+                     CALL wrk_dealloc( jpi, jpj,   fgco2   )
+                     !! ---
+                     IF( med_diag%OM_CAL%dgsave ) THEN
+                         CALL iom_put( "OM_CAL"  , f_omcal )
+                     ENDIF
+                     IF( med_diag%OM_ARG%dgsave ) THEN
+                         CALL iom_put( "OM_ARG"  , f_omarg )
+                     ENDIF
+                     IF( med_diag%TCO2%dgsave ) THEN
+                         CALL iom_put( "TCO2"  , f_TDIC2d )
+                         CALL wrk_dealloc( jpi, jpj,   f_TDIC2d   )
+                     ENDIF
+                     IF( med_diag%TALK%dgsave ) THEN
+                         CALL iom_put( "TALK"  , f_TALK2d )
+                         CALL wrk_dealloc( jpi, jpj,    f_TALK2d  )
+                     ENDIF
+                     IF( med_diag%KW660%dgsave ) THEN
+                         CALL iom_put( "KW660"  , f_kw6602d )
+                         CALL wrk_dealloc( jpi, jpj,   f_kw6602d   )
+                     ENDIF
+                     IF( med_diag%ATM_PP0%dgsave ) THEN
+                         CALL iom_put( "ATM_PP0"  , f_pp02d )
+                         CALL wrk_dealloc( jpi, jpj,    f_pp02d  )
+                     ENDIF
+                     IF( med_diag%O2FLUX%dgsave ) THEN
+                         CALL iom_put( "O2FLUX"  , f_o2flux2d )
+                         CALL wrk_dealloc( jpi, jpj,   f_o2flux2d   )
+                     ENDIF
+                     IF( med_diag%O2SAT%dgsave ) THEN
+                         CALL iom_put( "O2SAT"  , f_o2sat2d )
+                         CALL wrk_dealloc( jpi, jpj,  f_o2sat2d    )
+                     ENDIF
+                     IF( med_diag%CAL_CCD%dgsave ) THEN
+                         CALL iom_put( "CAL_CCD"  , f2_ccd_cal )
+                     ENDIF
+                     IF( med_diag%ARG_CCD%dgsave ) THEN
+                         CALL iom_put( "ARG_CCD"  , f2_ccd_arg )
+                     ENDIF
+                     IF (jdms .eq. 1) THEN
+                       IF( med_diag%DMS_SURF%dgsave ) THEN
+                         CALL lbc_lnk(dms_surf2d(:,:),'T',1. )
+                         CALL iom_put( "DMS_SURF"  , dms_surf2d )
+                         zb_dms_srf = zn_dms_srf
+                         zn_dms_srf = dms_surf2d
+                         IF (lk_oasis) THEN
+                            DMS_out_cpl = zn_dms_srf
+                         ENDIF
+                         CALL wrk_dealloc( jpi, jpj,   dms_surf2d   ) 
+                       ENDIF
+                       IF( med_diag%DMS_ANDR%dgsave ) THEN
+                         CALL iom_put( "DMS_ANDR"  , dms_andr2d )
+                         CALL wrk_dealloc( jpi, jpj,   dms_andr2d   )
+                       ENDIF
+                       IF( med_diag%DMS_SIMO%dgsave ) THEN
+                         CALL iom_put( "DMS_SIMO"  , dms_simo2d )
+                         CALL wrk_dealloc( jpi, jpj,    dms_simo2d  )
+                       ENDIF
+                       IF( med_diag%DMS_ARAN%dgsave ) THEN
+                         CALL iom_put( "DMS_ARAN"  , dms_aran2d )
+                         CALL wrk_dealloc( jpi, jpj,   dms_aran2d   )
+                       ENDIF
+                       IF( med_diag%DMS_HALL%dgsave ) THEN
+                         CALL iom_put( "DMS_HALL"  , dms_hall2d )
+                         CALL wrk_dealloc( jpi, jpj,   dms_hall2d   )
+                       ENDIF
+                     ENDIF
+                     !! AXY (24/11/16): extra MOCSY diagnostics
+                     IF( med_diag%ATM_XCO2%dgsave ) THEN
+                        CALL iom_put( "ATM_XCO2"  ,   f_xco2a_2d      )
+                        CALL wrk_dealloc( jpi, jpj,   f_xco2a_2d      )
+                     ENDIF
+                     IF( med_diag%OCN_FCO2%dgsave ) THEN
+                        CALL iom_put( "OCN_FCO2"  ,   f_fco2w_2d      )
+                        CALL wrk_dealloc( jpi, jpj,   f_fco2w_2d      )
+                     ENDIF
+                     IF( med_diag%ATM_FCO2%dgsave ) THEN
+                        CALL iom_put( "ATM_FCO2"  ,   f_fco2a_2d      )
+                        CALL wrk_dealloc( jpi, jpj,   f_fco2a_2d      )
+                     ENDIF
+                     IF( med_diag%OCN_RHOSW%dgsave ) THEN
+                        CALL iom_put( "OCN_RHOSW"  ,  f_ocnrhosw_2d   )
+                        CALL wrk_dealloc( jpi, jpj,   f_ocnrhosw_2d   )
+                     ENDIF
+                     IF( med_diag%OCN_SCHCO2%dgsave ) THEN
+                        CALL iom_put( "OCN_SCHCO2"  , f_ocnschco2_2d  )
+                        CALL wrk_dealloc( jpi, jpj,   f_ocnschco2_2d  )
+                     ENDIF
+                     IF( med_diag%OCN_KWCO2%dgsave ) THEN
+                        CALL iom_put( "OCN_KWCO2"  ,  f_ocnkwco2_2d   )
+                        CALL wrk_dealloc( jpi, jpj,   f_ocnkwco2_2d   )
+                     ENDIF
+                     IF( med_diag%OCN_K0%dgsave ) THEN
+                        CALL iom_put( "OCN_K0"  ,     f_ocnk0_2d      )
+                        CALL wrk_dealloc( jpi, jpj,   f_ocnk0_2d      )
+                     ENDIF
+                     IF( med_diag%CO2STARAIR%dgsave ) THEN
+                        CALL iom_put( "CO2STARAIR"  , f_co2starair_2d )
+                        CALL wrk_dealloc( jpi, jpj,   f_co2starair_2d )
+                     ENDIF
+                     IF( med_diag%OCN_DPCO2%dgsave ) THEN
+                        CALL iom_put( "OCN_DPCO2"  ,  f_ocndpco2_2d   )
+                        CALL wrk_dealloc( jpi, jpj,   f_ocndpco2_2d   )
+                     ENDIF
+# endif                     
+                 ELSE IF (jk.eq.i0100) THEN 
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: diag jk = 100'
+                     CALL flush(numout)
+#   endif
+                     IF( med_diag%SDT__100%dgsave ) THEN
+                        zw2d(:,:) = fslownflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDT__100"  , zw2d )
+                     ENDIF
+                     IF( med_diag%REG__100%dgsave ) THEN
+                        CALL iom_put( "REG__100"  , fregen2d )
+                     ENDIF
+                     IF( med_diag%FDT__100%dgsave ) THEN
+                        CALL iom_put( "FDT__100"  , ffastn )
+                     ENDIF           
+                     IF( med_diag%RG__100F%dgsave ) THEN
+                        CALL iom_put( "RG__100F"  , fregenfast )
+                     ENDIF
+                     IF( med_diag%FDS__100%dgsave ) THEN
+                        CALL iom_put( "FDS__100"  , ffastsi )
+                     ENDIF         
+                     IF( med_diag%RGS_100F%dgsave ) THEN
+                        CALL iom_put( "RGS_100F"  , fregenfastsi )
+                     ENDIF
+                     IF( med_diag%FE_0100%dgsave ) THEN
+                        CALL iom_put( "FE_0100"  , xFree )
+                     ENDIF
+# if defined key_roam                     
+                     IF( med_diag%RR_0100%dgsave ) THEN
+                        CALL iom_put( "RR_0100"  , ffastca2d )
+                     ENDIF                     
+                     IF( med_diag%SDC__100%dgsave ) THEN
+                        zw2d(:,:) = fslowcflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDC__100"  , zw2d )
+                     ENDIF                  
+                     IF( med_diag%epC100%dgsave    ) THEN
+                        zw2d(:,:) = (fslowcflux + ffastc) * tmask(:,:,jk)
+                        CALL iom_put( "epC100"    , zw2d )
+                     ENDIF		     
+                     IF( med_diag%epCALC100%dgsave ) THEN
+                        CALL iom_put( "epCALC100" , ffastca )
+                     ENDIF		     
+                     IF( med_diag%epN100%dgsave    ) THEN
+                        zw2d(:,:) = (fslownflux + ffastn) * tmask(:,:,jk)
+                        CALL iom_put( "epN100"    , zw2d )
+                     ENDIF		     
+                     IF( med_diag%epSI100%dgsave   ) THEN
+                        CALL iom_put( "epSI100"   , ffastsi )
+                     ENDIF		     
+                 ELSE IF (jk.eq.i0150) THEN
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: diag jk = 150'
+                     CALL flush(numout)
+#   endif
+# endif                     
+                 ELSE IF (jk.eq.i0200) THEN
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: diag jk = 200'
+                     CALL flush(numout)
+#   endif
+                     IF( med_diag%SDT__200%dgsave ) THEN
+                        zw2d(:,:) = fslownflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDT__200"  , zw2d )
+                     ENDIF
+                     IF( med_diag%REG__200%dgsave ) THEN
+                        CALL iom_put( "REG__200"  , fregen2d )
+                     ENDIF
+                     IF( med_diag%FDT__200%dgsave ) THEN
+                        CALL iom_put( "FDT__200"  , ffastn )
+                     ENDIF
+                     IF( med_diag%RG__200F%dgsave ) THEN
+                        CALL iom_put( "RG__200F"  , fregenfast )
+                     ENDIF
+                     IF( med_diag%FDS__200%dgsave ) THEN
+                        CALL iom_put( "FDS__200"  , ffastsi )
+                     ENDIF
+                     IF( med_diag%RGS_200F%dgsave ) THEN
+                        CALL iom_put( "RGS_200F"  , fregenfastsi )
+                     ENDIF
+                     IF( med_diag%FE_0200%dgsave ) THEN
+                        CALL iom_put( "FE_0200"   , xFree )
+                     ENDIF
+# if defined key_roam                     
+                     IF( med_diag%SDC__200%dgsave ) THEN
+                        zw2d(:,:) = fslowcflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDC__200"  , zw2d )
+                     ENDIF
+# endif                     
+                 ELSE IF (jk.eq.i0500) THEN
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: diag jk = 500'
+                     CALL flush(numout)
+#   endif
+                     IF( med_diag%SDT__500%dgsave ) THEN
+                        zw2d(:,:) = fslownflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDT__500"  , zw2d )
+                     ENDIF
+                     IF( med_diag%REG__500%dgsave ) THEN
+                        CALL iom_put( "REG__500"  , fregen2d )
+                     ENDIF      
+                     IF( med_diag%FDT__500%dgsave ) THEN
+                        CALL iom_put( "FDT__500"  , ffastn )
+                     ENDIF
+                     IF( med_diag%RG__500F%dgsave ) THEN
+                        CALL iom_put( "RG__500F"  , fregenfast )
+                     ENDIF
+                     IF( med_diag%FDS__500%dgsave ) THEN
+                        CALL iom_put( "FDS__500"  , ffastsi )
+                     ENDIF
+                     IF( med_diag%RGS_500F%dgsave ) THEN
+                        CALL iom_put( "RGS_500F"  , fregenfastsi )
+                     ENDIF
+                     IF( med_diag%FE_0500%dgsave ) THEN
+                        CALL iom_put( "FE_0500"  , xFree )
+                     ENDIF
+# if defined key_roam                     
+                     IF( med_diag%RR_0500%dgsave ) THEN
+                        CALL iom_put( "RR_0500"  , ffastca2d )
+                     ENDIF
+                     IF( med_diag%SDC__500%dgsave ) THEN
+                        zw2d(:,:) = fslowcflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDC__500"  , zw2d )
+                     ENDIF  
+# endif                      
+                 ELSE IF (jk.eq.i1000) THEN
+#   if defined key_debug_medusa
+                     IF (lwp) write (numout,*) 'trc_bio_medusa: diag jk = 1000'
+                     CALL flush(numout)
+#   endif
+                     IF( med_diag%SDT_1000%dgsave ) THEN
+                        zw2d(:,:) = fslownflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDT_1000"  , zw2d )
+                     ENDIF
+                     IF( med_diag%REG_1000%dgsave ) THEN
+                        CALL iom_put( "REG_1000"  , fregen2d )
+                     ENDIF  
+                     IF( med_diag%FDT_1000%dgsave ) THEN
+                        CALL iom_put( "FDT_1000"  , ffastn )
+                     ENDIF
+                     IF( med_diag%RG_1000F%dgsave ) THEN
+                        CALL iom_put( "RG_1000F"  , fregenfast )
+                     ENDIF
+                     IF( med_diag%FDS_1000%dgsave ) THEN
+                        CALL iom_put( "FDS_1000"  , ffastsi )
+                     ENDIF
+                     IF( med_diag%RGS1000F%dgsave ) THEN
+                        CALL iom_put( "RGS1000F"  , fregenfastsi )
+                     ENDIF
+                     IF( med_diag%FE_1000%dgsave ) THEN
+                        CALL iom_put( "FE_1000"  , xFree )
+                     ENDIF
+# if defined key_roam                     
+                     IF( med_diag%RR_1000%dgsave ) THEN
+                        CALL iom_put( "RR_1000"  , ffastca2d )
+                        CALL wrk_dealloc( jpi, jpj,  ffastca2d    )
+                     ENDIF
+                     IF( med_diag%SDC_1000%dgsave ) THEN
+                        zw2d(:,:) = fslowcflux(:,:) * tmask(:,:,jk)
+                        CALL iom_put( "SDC_1000"  , zw2d )
+                     ENDIF 
+# endif                      
+                 ENDIF
+                 !! to do on every k loop :
+                 IF( med_diag%DETFLUX3%dgsave ) THEN
+                      detflux3d(:,:,jk) = (fslownflux(:,:) + ffastn(:,:)) * tmask(:,:,jk) !! detrital flux
+                      !CALL iom_put( "DETFLUX3"  , ftot_n )
+                 ENDIF
+# if defined key_roam                     
+                 IF( med_diag%EXPC3%dgsave ) THEN
+                    expc3(:,:,jk) = (fslowcflux(:,:) + ffastc(:,:)) * tmask(:,:,jk)
+                 ENDIF		     
+                 IF( med_diag%EXPN3%dgsave ) THEN
+                    expn3(:,:,jk) = (fslownflux(:,:) + ffastn(:,:)) * tmask(:,:,jk)
+                 ENDIF		     
+# endif		     
+              ENDIF
+      !! CLOSE vertical loop
+      ENDDO
+
+      !!----------------------------------------------------------------------
+      !! Process benthic in/out fluxes
+      !! These can be handled outside of the 3D calculations since the
+      !! benthic pools (and fluxes) are 2D in nature; this code is
+      !! (shamelessly) borrowed from corresponding code in the LOBSTER
+      !! model
+      !!----------------------------------------------------------------------
+      !!
+      !! IF(lwp) WRITE(numout,*) 'AXY: rdt = ', rdt
+      if (jorgben.eq.1) then
+         za_sed_n(:,:)  = zn_sed_n(:,:)  + & 
+         &                ( f_sbenin_n(:,:)  + f_fbenin_n(:,:)  - f_benout_n(:,:)  ) * (rdt / 86400.)
+         zn_sed_n(:,:)  = za_sed_n(:,:)
+         !!
+         za_sed_fe(:,:) = zn_sed_fe(:,:) + &
+         &                ( f_sbenin_fe(:,:) + f_fbenin_fe(:,:) - f_benout_fe(:,:) ) * (rdt / 86400.)
+         zn_sed_fe(:,:) = za_sed_fe(:,:)
+         !!
+         za_sed_c(:,:)  = zn_sed_c(:,:)  + &
+         &                ( f_sbenin_c(:,:)  + f_fbenin_c(:,:)  - f_benout_c(:,:)  ) * (rdt / 86400.)
+         zn_sed_c(:,:)  = za_sed_c(:,:)
+      endif
+      if (jinorgben.eq.1) then
+         za_sed_si(:,:) = zn_sed_si(:,:) + & 
+         &                ( f_fbenin_si(:,:) - f_benout_si(:,:) ) * (rdt / 86400.)
+         zn_sed_si(:,:) = za_sed_si(:,:)
+         !!
+         za_sed_ca(:,:) = zn_sed_ca(:,:) + &
+         &                ( f_fbenin_ca(:,:) - f_benout_ca(:,:) ) * (rdt / 86400.)
+         zn_sed_ca(:,:) = za_sed_ca(:,:)
+      endif
+      IF( ln_diatrc ) THEN
+         DO jj = 2,jpjm1
+            DO ji = 2,jpim1
+               trc2d(ji,jj,131) = za_sed_n(ji,jj)
+               trc2d(ji,jj,132) = za_sed_fe(ji,jj)
+               trc2d(ji,jj,133) = za_sed_c(ji,jj)
+               trc2d(ji,jj,134) = za_sed_si(ji,jj)
+               trc2d(ji,jj,135) = za_sed_ca(ji,jj)
+            ENDDO
+         ENDDO
+         !! AXY (07/07/15): temporary hijacking
+# if defined key_roam
+  !!       trc2d(:,:,126) = zn_dms_chn(:,:)
+  !!       trc2d(:,:,127) = zn_dms_chd(:,:)
+  !!       trc2d(:,:,128) = zn_dms_mld(:,:)
+  !!       trc2d(:,:,129) = zn_dms_qsr(:,:)
+  !!       trc2d(:,:,130) = zn_dms_din(:,:)
+# endif
+      ENDIF 
+      !!
+      if (ibenthic.eq.2) then
+         !! The code below (in this if ... then ... endif loop) is
+         !! effectively commented out because it does not work as 
+         !! anticipated; it can be deleted at a later date
+         if (jorgben.eq.1) then
+            za_sed_n(:,:)  = ( f_sbenin_n(:,:)  + f_fbenin_n(:,:)  - f_benout_n(:,:)  ) * rdt
+            za_sed_fe(:,:) = ( f_sbenin_fe(:,:) + f_fbenin_fe(:,:) - f_benout_fe(:,:) ) * rdt
+            za_sed_c(:,:)  = ( f_sbenin_c(:,:)  + f_fbenin_c(:,:)  - f_benout_c(:,:)  ) * rdt
+         endif
+         if (jinorgben.eq.1) then
+            za_sed_si(:,:) = ( f_fbenin_si(:,:) - f_benout_si(:,:) ) * rdt
+            za_sed_ca(:,:) = ( f_fbenin_ca(:,:) - f_benout_ca(:,:) ) * rdt
+         endif
+         !!
+         !! Leap-frog scheme - only in explicit case, otherwise the time stepping
+         !! is already being done in trczdf
+         !! IF( l_trczdf_exp .AND. (ln_trcadv_cen2 .OR. ln_trcadv_tvd) ) THEN
+         !!    zfact = 2. * rdttra(jk) * FLOAT( ndttrc )
+         !!    IF( neuler == 0 .AND. kt == nittrc000 )   zfact = rdttra(jk) * FLOAT(ndttrc)
+         !!    if (jorgben.eq.1) then
+         !!       za_sed_n(:,:)  = zb_sed_n(:,:)  + ( zfact * za_sed_n(:,:)  )
+         !!      za_sed_fe(:,:) = zb_sed_fe(:,:) + ( zfact * za_sed_fe(:,:) )
+         !!       za_sed_c(:,:)  = zb_sed_c(:,:)  + ( zfact * za_sed_c(:,:)  )
+         !!    endif
+         !!    if (jinorgben.eq.1) then
+         !!       za_sed_si(:,:) = zb_sed_si(:,:) + ( zfact * za_sed_si(:,:) )
+         !!       za_sed_ca(:,:) = zb_sed_ca(:,:) + ( zfact * za_sed_ca(:,:) )
+         !!    endif
+         !! ENDIF
+         !! 
+         !! Time filter and swap of arrays
+         IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd  ) THEN ! centred or tvd scheme
+            IF( neuler == 0 .AND. kt == nittrc000 ) THEN
+               if (jorgben.eq.1) then
+                  zb_sed_n(:,:)  = zn_sed_n(:,:)
+                  zn_sed_n(:,:)  = za_sed_n(:,:)
+                  za_sed_n(:,:)  = 0.0
+                  !!
+                  zb_sed_fe(:,:) = zn_sed_fe(:,:)
+                  zn_sed_fe(:,:) = za_sed_fe(:,:)
+                  za_sed_fe(:,:) = 0.0
+                  !!
+                  zb_sed_c(:,:)  = zn_sed_c(:,:)
+                  zn_sed_c(:,:)  = za_sed_c(:,:)
+                  za_sed_c(:,:)  = 0.0
+               endif
+               if (jinorgben.eq.1) then
+                  zb_sed_si(:,:) = zn_sed_si(:,:)
+                  zn_sed_si(:,:) = za_sed_si(:,:)
+                  za_sed_si(:,:) = 0.0
+                  !!
+                  zb_sed_ca(:,:) = zn_sed_ca(:,:)
+                  zn_sed_ca(:,:) = za_sed_ca(:,:)
+                  za_sed_ca(:,:) = 0.0
+               endif
+            ELSE
+               if (jorgben.eq.1) then
+                  zb_sed_n(:,:)  = (atfp  * ( zb_sed_n(:,:)  + za_sed_n(:,:)  )) + (atfp1 * zn_sed_n(:,:) )
+                  zn_sed_n(:,:)  = za_sed_n(:,:)
+                  za_sed_n(:,:)  = 0.0
+                  !!
+                  zb_sed_fe(:,:) = (atfp  * ( zb_sed_fe(:,:) + za_sed_fe(:,:) )) + (atfp1 * zn_sed_fe(:,:))
+                  zn_sed_fe(:,:) = za_sed_fe(:,:)
+                  za_sed_fe(:,:) = 0.0
+                  !!
+                  zb_sed_c(:,:)  = (atfp  * ( zb_sed_c(:,:)  + za_sed_c(:,:)  )) + (atfp1 * zn_sed_c(:,:) )
+                  zn_sed_c(:,:)  = za_sed_c(:,:)
+                  za_sed_c(:,:)  = 0.0
+               endif
+               if (jinorgben.eq.1) then
+                  zb_sed_si(:,:) = (atfp  * ( zb_sed_si(:,:) + za_sed_si(:,:) )) + (atfp1 * zn_sed_si(:,:))
+                  zn_sed_si(:,:) = za_sed_si(:,:)
+                  za_sed_si(:,:) = 0.0
+                  !!
+                  zb_sed_ca(:,:) = (atfp  * ( zb_sed_ca(:,:) + za_sed_ca(:,:) )) + (atfp1 * zn_sed_ca(:,:))
+                  zn_sed_ca(:,:) = za_sed_ca(:,:)
+                  za_sed_ca(:,:) = 0.0
+               endif
+            ENDIF
+         ELSE                   !  case of smolar scheme or muscl
+            if (jorgben.eq.1) then
+               zb_sed_n(:,:)  = za_sed_n(:,:)
+               zn_sed_n(:,:)  = za_sed_n(:,:)
+               za_sed_n(:,:)  = 0.0
+               !!
+               zb_sed_fe(:,:) = za_sed_fe(:,:)
+               zn_sed_fe(:,:) = za_sed_fe(:,:)
+               za_sed_fe(:,:) = 0.0
+               !!
+               zb_sed_c(:,:)  = za_sed_c(:,:)
+               zn_sed_c(:,:)  = za_sed_c(:,:)
+               za_sed_c(:,:)  = 0.0
+            endif
+            if (jinorgben.eq.1) then
+               zb_sed_si(:,:) = za_sed_si(:,:)
+               zn_sed_si(:,:) = za_sed_si(:,:)
+               za_sed_si(:,:) = 0.0
+               !!
+               zb_sed_ca(:,:) = za_sed_ca(:,:)
+               zn_sed_ca(:,:) = za_sed_ca(:,:)
+               za_sed_ca(:,:) = 0.0
+            endif
+         ENDIF
+      endif
+      
+      IF( ln_diatrc ) THEN
+         !!----------------------------------------------------------------------
+         !! Output several accumulated diagnostics
+         !!   - biomass-average phytoplankton limitation terms
+         !!   - integrated tendency terms
+         !!----------------------------------------------------------------------
+         !! 
+         DO jj = 2,jpjm1
+            DO ji = 2,jpim1
+               !! non-diatom phytoplankton limitations
+               trc2d(ji,jj,25)  = trc2d(ji,jj,25) / MAX(ftot_pn(ji,jj), rsmall)
+               trc2d(ji,jj,26)  = trc2d(ji,jj,26) / MAX(ftot_pn(ji,jj), rsmall)
+               trc2d(ji,jj,27)  = trc2d(ji,jj,27) / MAX(ftot_pn(ji,jj), rsmall)
+               !! diatom phytoplankton limitations
+               trc2d(ji,jj,28)  = trc2d(ji,jj,28) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,29)  = trc2d(ji,jj,29) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,30)  = trc2d(ji,jj,30) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,31)  = trc2d(ji,jj,31) / MAX(ftot_pd(ji,jj), rsmall)
+               trc2d(ji,jj,32)  = trc2d(ji,jj,32) / MAX(ftot_pd(ji,jj), rsmall)
+               !! tendency terms
+               trc2d(ji,jj,76)  = fflx_n(ji,jj)
+               trc2d(ji,jj,77)  = fflx_si(ji,jj)
+               trc2d(ji,jj,78)  = fflx_fe(ji,jj)
+               !! integrated biomass
+               trc2d(ji,jj,79)  = ftot_pn(ji,jj)       !! integrated non-diatom phytoplankton
+               trc2d(ji,jj,80)  = ftot_pd(ji,jj)       !! integrated diatom phytoplankton
+               trc2d(ji,jj,217) = ftot_zmi(ji,jj)      !! Integrated microzooplankton
+               trc2d(ji,jj,218) = ftot_zme(ji,jj)      !! Integrated mesozooplankton
+               trc2d(ji,jj,219) = ftot_det(ji,jj)      !! Integrated slow detritus, nitrogen
+               trc2d(ji,jj,220) = ftot_dtc(ji,jj)      !! Integrated slow detritus, carbon
+# if defined key_roam
+               !! the balance of nitrogen production/consumption
+               trc2d(ji,jj,111) = fnit_prod(ji,jj)  !! integrated nitrogen production
+               trc2d(ji,jj,112) = fnit_cons(ji,jj)  !! integrated nitrogen consumption
+               !! the balance of carbon production/consumption
+               trc2d(ji,jj,113) = fcar_prod(ji,jj)  !! integrated carbon production
+               trc2d(ji,jj,114) = fcar_cons(ji,jj)  !! integrated carbon consumption
+               !! the balance of oxygen production/consumption
+               trc2d(ji,jj,115) = foxy_prod(ji,jj)  !! integrated oxygen production
+               trc2d(ji,jj,116) = foxy_cons(ji,jj)  !! integrated oxygen consumption
+               trc2d(ji,jj,117) = foxy_anox(ji,jj)  !! integrated unrealised oxygen consumption
+# endif
+            ENDDO
+         ENDDO
+         
+# if defined key_roam
+#  if defined key_axy_nancheck
+         !!----------------------------------------------------------------------
+         !! Check for NaNs in diagnostic outputs
+         !!----------------------------------------------------------------------
+         !! 
+         !! 2D diagnostics
+         DO jn = 1,150
+            fq0 = SUM(trc2d(:,:,jn))
+            !! AXY (30/01/14): "isnan" problem on HECTOR
+            !! if (fq0 /= fq0 ) then
+            if ( ieee_is_nan( fq0 ) ) then
+               !! there's a NaN here
+               if (lwp) write(numout,*) 'NAN detected in 2D diagnostic field', jn, 'at time', kt, 'at position:'
+               DO jj = 1,jpj
+                  DO ji = 1,jpi
+                     if ( ieee_is_nan( trc2d(ji,jj,jn) ) ) then
+                        if (lwp) write (numout,'(a,3i6)') 'NAN-CHECK', &
+                        &        ji, jj, jn
+                     endif
+                  ENDDO
+               ENDDO
+	       CALL ctl_stop( 'trcbio_medusa, NAN in 2D diagnostic field' )
+            endif
+         ENDDO
+         !!
+         !! 3D diagnostics
+         DO jn = 1,5
+            fq0 = SUM(trc3d(:,:,:,jn))
+            !! AXY (30/01/14): "isnan" problem on HECTOR
+            !! if (fq0 /= fq0 ) then
+            if ( ieee_is_nan( fq0 ) ) then
+               !! there's a NaN here
+               if (lwp) write(numout,*) 'NAN detected in 3D diagnostic field', jn, 'at time', kt, 'at position:'
+               DO jk = 1,jpk
+                  DO jj = 1,jpj
+                     DO ji = 1,jpi
+                        if ( ieee_is_nan( trc3d(ji,jj,jk,jn) ) ) then
+                           if (lwp) write (numout,'(a,4i6)') 'NAN-CHECK', &
+                           &        ji, jj, jk, jn
+                        endif
+                     ENDDO
+                  ENDDO
+               ENDDO
+	       CALL ctl_stop( 'trcbio_medusa, NAN in 3D diagnostic field' )
+            endif
+         ENDDO
+	 CALL flush(numout)
+#  endif
+# endif
+
+         !!----------------------------------------------------------------------
+         !! Don't know what this does; belongs to someone else ...
+         !!----------------------------------------------------------------------
+         !! 
+         !! Lateral boundary conditions on trc2d
+         DO jn=1,jp_medusa_2d
+             CALL lbc_lnk(trc2d(:,:,jn),'T',1. )
+         ENDDO 
+
+         !! Lateral boundary conditions on trc3d
+         DO jn=1,jp_medusa_3d
+             CALL lbc_lnk(trc3d(:,:,1,jn),'T',1. )
+         ENDDO 
+
+
+# if defined key_axy_nodiag
+         !!----------------------------------------------------------------------
+         !! Blank diagnostics as a NaN-trap
+         !!----------------------------------------------------------------------
+         !! 
+         !! blank 2D diagnostic array
+         trc2d(:,:,:) = 0.e0
+         !!
+         !! blank 3D diagnostic array
+         trc3d(:,:,:,:) = 0.e0
+# endif
+
+
+         !!----------------------------------------------------------------------
+         !! Add in XML diagnostics stuff
+         !!----------------------------------------------------------------------
+         !!
+         !! ** 2D diagnostics
+         DO jn=1,jp_medusa_2d
+            CALL iom_put(TRIM(ctrc2d(jn)), trc2d(:,:,jn))
+         END DO
+!! AXY (17/02/14): don't think I need this if I modify the above for all diagnostics
+!! #  if defined key_roam
+!!          DO jn=91,jp_medusa_2d
+!!             CALL iom_put(TRIM(ctrc2d(jn)), trc2d(:,:,jn))
+!!          END DO      
+!! #  endif
+         !!
+         !! ** 3D diagnostics
+         DO jn=1,jp_medusa_3d
+            CALL iom_put(TRIM(ctrc3d(jn)), trc3d(:,:,:,jn))
+         END DO
+!! AXY (17/02/14): don't think I need this if I modify the above for all diagnostics
+!! #  if defined key_roam
+!!          CALL iom_put(TRIM(ctrc3d(5)), trc3d(:,:,:,5))
+!! #  endif
+
+
+      ELSE IF( lk_iomput .AND. .NOT. ln_diatrc ) THEN
+         !!!----------------------------------------------------------------------
+         !! Add very last diag calculations 
+         !!!----------------------------------------------------------------------
+         DO jj = 2,jpjm1
+            DO ji = 2,jpim1
+               !!         
+               IF( med_diag%PN_JLIM%dgsave ) THEN
+                  fjln2d(ji,jj) = fjln2d(ji,jj)   / MAX(ftot_pn(ji,jj), rsmall)
+               ENDIF
+               IF( med_diag%PN_NLIM%dgsave ) THEN
+                  fnln2d(ji,jj) = fnln2d(ji,jj)   / MAX(ftot_pn(ji,jj), rsmall)
+               ENDIF
+               IF( med_diag%PN_FELIM%dgsave ) THEN
+                  ffln2d(ji,jj) = ffln2d(ji,jj)   / MAX(ftot_pn(ji,jj), rsmall)
+               ENDIF
+               IF( med_diag%PD_JLIM%dgsave ) THEN
+                  fjld2d(ji,jj) = fjld2d(ji,jj)   / MAX(ftot_pd(ji,jj), rsmall)
+               ENDIF
+               IF( med_diag%PD_NLIM%dgsave ) THEN
+                  fnld2d(ji,jj) = fnld2d(ji,jj)   / MAX(ftot_pd(ji,jj), rsmall)
+               ENDIF
+               IF( med_diag%PD_FELIM%dgsave ) THEN
+                  ffld2d(ji,jj) = ffld2d(ji,jj)   / MAX(ftot_pd(ji,jj), rsmall)
+               ENDIF
+               IF( med_diag%PD_SILIM%dgsave ) THEN
+                  fsld2d2(ji,jj) = fsld2d2(ji,jj) / MAX(ftot_pd(ji,jj), rsmall)
+               ENDIF
+               IF( med_diag%PDSILIM2%dgsave ) THEN
+                  fsld2d(ji,jj) = fsld2d(ji,jj)   / MAX(ftot_pd(ji,jj), rsmall)
+               ENDIF
+            ENDDO
+         ENDDO
+         !!----------------------------------------------------------------------
+         !! Add in XML diagnostics stuff
+         !!----------------------------------------------------------------------
+         !!
+         !! ** 2D diagnostics
+#   if defined key_debug_medusa
+         IF (lwp) write (numout,*) 'trc_bio_medusa: export all diag.'
+         CALL flush(numout)
+#   endif
+         IF ( med_diag%INVTN%dgsave ) THEN
+            CALL iom_put( "INVTN"  , ftot_n )
+         ENDIF
+         IF ( med_diag%INVTSI%dgsave ) THEN
+            CALL iom_put( "INVTSI"  , ftot_si )
+         ENDIF
+         IF ( med_diag%INVTFE%dgsave ) THEN
+            CALL iom_put( "INVTFE"  , ftot_fe )
+         ENDIF                           
+         IF ( med_diag%ML_PRN%dgsave ) THEN
+            CALL iom_put( "ML_PRN"  , fprn_ml )
+         ENDIF
+         IF ( med_diag%ML_PRD%dgsave ) THEN
+            CALL iom_put( "ML_PRD"  , fprd_ml )
+         ENDIF
+         IF ( med_diag%OCAL_LVL%dgsave ) THEN
+            CALL iom_put( "OCAL_LVL"  , fccd )
+         ENDIF
+         IF ( med_diag%PN_JLIM%dgsave ) THEN
+            CALL iom_put( "PN_JLIM"  , fjln2d )
+            CALL wrk_dealloc( jpi, jpj,   fjln2d   )
+         ENDIF
+         IF ( med_diag%PN_NLIM%dgsave ) THEN
+            CALL iom_put( "PN_NLIM"  , fnln2d )
+            CALL wrk_dealloc( jpi, jpj,   fnln2d   )
+         ENDIF
+         IF ( med_diag%PN_FELIM%dgsave ) THEN
+            CALL iom_put( "PN_FELIM"  , ffln2d )
+            CALL wrk_dealloc( jpi, jpj,   ffln2d   )
+         ENDIF
+         IF ( med_diag%PD_JLIM%dgsave ) THEN
+            CALL iom_put( "PD_JLIM"  , fjld2d )
+            CALL wrk_dealloc( jpi, jpj,  fjld2d    )
+         ENDIF
+         IF ( med_diag%PD_NLIM%dgsave ) THEN
+            CALL iom_put( "PD_NLIM"  , fnld2d )
+            CALL wrk_dealloc( jpi, jpj,   fnld2d  )
+         ENDIF
+         IF ( med_diag%PD_FELIM%dgsave ) THEN
+            CALL iom_put( "PD_FELIM"  , ffld2d )
+            CALL wrk_dealloc( jpi, jpj,  ffld2d    )
+         ENDIF
+         IF ( med_diag%PD_SILIM%dgsave ) THEN
+            CALL iom_put( "PD_SILIM"  , fsld2d2 )
+            CALL wrk_dealloc( jpi, jpj,   fsld2d2   )
+         ENDIF
+         IF ( med_diag%PDSILIM2%dgsave ) THEN
+            CALL iom_put( "PDSILIM2"  , fsld2d )
+            CALL wrk_dealloc( jpi, jpj,   fsld2d   )
+         ENDIF
+         IF ( med_diag%INTFLX_N%dgsave ) THEN
+            CALL iom_put( "INTFLX_N"  , fflx_n )
+         ENDIF
+         IF ( med_diag%INTFLX_SI%dgsave ) THEN
+            CALL iom_put( "INTFLX_SI"  , fflx_si )
+         ENDIF
+         IF ( med_diag%INTFLX_FE%dgsave ) THEN
+            CALL iom_put( "INTFLX_FE"  , fflx_fe )
+         ENDIF        
+         IF ( med_diag%INT_PN%dgsave ) THEN
+            CALL iom_put( "INT_PN"  , ftot_pn )
+         ENDIF
+         IF ( med_diag%INT_PD%dgsave ) THEN
+            CALL iom_put( "INT_PD"  , ftot_pd )
+         ENDIF         
+         IF ( med_diag%INT_ZMI%dgsave ) THEN
+            CALL iom_put( "INT_ZMI"  , ftot_zmi )
+         ENDIF
+         IF ( med_diag%INT_ZME%dgsave ) THEN
+            CALL iom_put( "INT_ZME"  , ftot_zme )
+         ENDIF
+         IF ( med_diag%INT_DET%dgsave ) THEN
+            CALL iom_put( "INT_DET"  , ftot_det )
+         ENDIF
+         IF ( med_diag%INT_DTC%dgsave ) THEN
+            CALL iom_put( "INT_DTC"  , ftot_dtc )
+         ENDIF
+         IF ( med_diag%BEN_N%dgsave ) THEN
+            CALL iom_put( "BEN_N"  , za_sed_n )
+         ENDIF
+         IF ( med_diag%BEN_FE%dgsave ) THEN
+            CALL iom_put( "BEN_FE"  , za_sed_fe )
+         ENDIF
+         IF ( med_diag%BEN_C%dgsave ) THEN
+            CALL iom_put( "BEN_C"  , za_sed_c )
+         ENDIF
+         IF ( med_diag%BEN_SI%dgsave ) THEN
+            CALL iom_put( "BEN_SI"  , za_sed_si )
+         ENDIF
+         IF ( med_diag%BEN_CA%dgsave ) THEN
+            CALL iom_put( "BEN_CA"  , za_sed_ca )
+         ENDIF
+         IF ( med_diag%RUNOFF%dgsave ) THEN
+            CALL iom_put( "RUNOFF"  , f_runoff )
+         ENDIF 
+# if defined key_roam        
+         IF ( med_diag%N_PROD%dgsave ) THEN
+            CALL iom_put( "N_PROD"  , fnit_prod )
+         ENDIF
+         IF ( med_diag%N_CONS%dgsave ) THEN
+            CALL iom_put( "N_CONS"  , fnit_cons )
+         ENDIF
+         IF ( med_diag%C_PROD%dgsave ) THEN
+            CALL iom_put( "C_PROD"  , fcar_prod )
+         ENDIF
+         IF ( med_diag%C_CONS%dgsave ) THEN
+            CALL iom_put( "C_CONS"  , fcar_cons )
+         ENDIF
+         IF ( med_diag%O2_PROD%dgsave ) THEN
+            CALL iom_put( "O2_PROD"  , foxy_prod )
+         ENDIF
+         IF ( med_diag%O2_CONS%dgsave ) THEN
+            CALL iom_put( "O2_CONS"  , foxy_cons )
+         ENDIF
+         IF ( med_diag%O2_ANOX%dgsave ) THEN
+            CALL iom_put( "O2_ANOX"  , foxy_anox )
+         ENDIF
+         IF ( med_diag%INVTC%dgsave ) THEN
+            CALL iom_put( "INVTC"  , ftot_c )
+         ENDIF
+         IF ( med_diag%INVTALK%dgsave ) THEN
+            CALL iom_put( "INVTALK"  , ftot_a )
+         ENDIF
+         IF ( med_diag%INVTO2%dgsave ) THEN
+            CALL iom_put( "INVTO2"  , ftot_o2 )
+         ENDIF
+         IF ( med_diag%COM_RESP%dgsave ) THEN
+            CALL iom_put( "COM_RESP"  , fcomm_resp )
+         ENDIF         
+# endif      
+         !!
+         !! diagnostic filled in the i-j-k main loop
+         !!--------------------------------------------
+         IF ( med_diag%PRN%dgsave ) THEN
+            CALL iom_put( "PRN"  , fprn2d )
+            CALL wrk_dealloc( jpi, jpj,   fprn2d   )
+         ENDIF
+         IF ( med_diag%MPN%dgsave ) THEN
+            CALL iom_put( "MPN"  ,fdpn2d  )
+            CALL wrk_dealloc( jpi, jpj,    fdpn2d  )
+         ENDIF
+         IF ( med_diag%PRD%dgsave ) THEN
+            CALL iom_put( "PRD"  ,fprd2d  )
+            CALL wrk_dealloc( jpi, jpj,   fprd2d  )
+         ENDIF
+         IF( med_diag%MPD%dgsave ) THEN
+            CALL iom_put( "MPD"  , fdpd2d )
+            CALL wrk_dealloc( jpi, jpj,    fdpd2d )
+         ENDIF
+         !  IF( med_diag%DSED%dgsave ) THEN
+         !      CALL iom_put( "DSED"  , ftot_n )
+         !  ENDIF
+         IF( med_diag%OPAL%dgsave ) THEN
+            CALL iom_put( "OPAL"  , fprds2d )
+            CALL wrk_dealloc( jpi, jpj,   fprds2d  )
+         ENDIF
+         IF( med_diag%OPALDISS%dgsave ) THEN
+            CALL iom_put( "OPALDISS"  , fsdiss2d )
+            CALL wrk_dealloc( jpi, jpj,   fsdiss2d  )
+         ENDIF
+         IF( med_diag%GMIPn%dgsave ) THEN
+            CALL iom_put( "GMIPn"  , fgmipn2d )
+            CALL wrk_dealloc( jpi, jpj,   fgmipn2d  )
+         ENDIF
+         IF( med_diag%GMID%dgsave ) THEN
+            CALL iom_put( "GMID"  , fgmid2d )
+            CALL wrk_dealloc( jpi, jpj,  fgmid2d  )
+         ENDIF
+         IF( med_diag%MZMI%dgsave ) THEN
+            CALL iom_put( "MZMI"  , fdzmi2d )
+            CALL wrk_dealloc( jpi, jpj,   fdzmi2d   )
+         ENDIF
+         IF( med_diag%GMEPN%dgsave ) THEN
+            CALL iom_put( "GMEPN"  , fgmepn2d )
+            CALL wrk_dealloc( jpi, jpj,   fgmepn2d  )
+         ENDIF
+         IF( med_diag%GMEPD%dgsave ) THEN
+            CALL iom_put( "GMEPD"  , fgmepd2d )
+            CALL wrk_dealloc( jpi, jpj,   fgmepd2d   )
+         ENDIF
+         IF( med_diag%GMEZMI%dgsave ) THEN
+            CALL iom_put( "GMEZMI"  , fgmezmi2d )
+            CALL wrk_dealloc( jpi, jpj,   fgmezmi2d   )
+         ENDIF
+         IF( med_diag%GMED%dgsave ) THEN
+            CALL iom_put( "GMED"  , fgmed2d )
+            CALL wrk_dealloc( jpi, jpj,    fgmed2d  )
+         ENDIF
+         IF( med_diag%MZME%dgsave ) THEN
+            CALL iom_put( "MZME"  , fdzme2d )
+            CALL wrk_dealloc( jpi, jpj,  fdzme2d    )
+         ENDIF
+         !  IF( med_diag%DEXP%dgsave ) THEN
+         !      CALL iom_put( "DEXP"  , ftot_n )
+         !  ENDIF
+         IF( med_diag%DETN%dgsave ) THEN
+            CALL iom_put( "DETN"  , fslown2d )
+            CALL wrk_dealloc( jpi, jpj,  fslown2d    )
+         ENDIF
+         IF( med_diag%MDET%dgsave ) THEN
+            CALL iom_put( "MDET"  , fdd2d )
+            CALL wrk_dealloc( jpi, jpj,   fdd2d   )
+         ENDIF
+         IF( med_diag%AEOLIAN%dgsave ) THEN
+            CALL iom_put( "AEOLIAN"  , ffetop2d )
+            CALL wrk_dealloc( jpi, jpj,   ffetop2d   )
+         ENDIF
+         IF( med_diag%BENTHIC%dgsave ) THEN
+            CALL iom_put( "BENTHIC"  , ffebot2d )
+            CALL wrk_dealloc( jpi, jpj,   ffebot2d   )
+         ENDIF
+         IF( med_diag%SCAVENGE%dgsave ) THEN
+            CALL iom_put( "SCAVENGE"  , ffescav2d )
+            CALL wrk_dealloc( jpi, jpj,   ffescav2d  )
+         ENDIF
+         !! 
+         IF( med_diag%TOTREG_N%dgsave ) THEN
+            CALL iom_put( "TOTREG_N"  , fregen2d )
+            CALL wrk_dealloc( jpi, jpj,   fregen2d   )
+         ENDIF
+         IF( med_diag%TOTRG_SI%dgsave ) THEN
+            CALL iom_put( "TOTRG_SI"  , fregensi2d )
+            CALL wrk_dealloc( jpi, jpj,    fregensi2d  )
+         ENDIF
+         !! 
+         IF( med_diag%FASTN%dgsave ) THEN
+            CALL iom_put( "FASTN"  , ftempn2d )
+            CALL wrk_dealloc( jpi, jpj,   ftempn2d   )
+         ENDIF
+         IF( med_diag%FASTSI%dgsave ) THEN
+            CALL iom_put( "FASTSI"  , ftempsi2d )
+            CALL wrk_dealloc( jpi, jpj,   ftempsi2d   )
+         ENDIF
+         IF( med_diag%FASTFE%dgsave ) THEN
+            CALL iom_put( "FASTFE"  , ftempfe2d )
+            CALL wrk_dealloc( jpi, jpj,    ftempfe2d  )
+         ENDIF
+         IF( med_diag%FASTC%dgsave ) THEN
+            CALL iom_put( "FASTC"  , ftempc2d )
+            CALL wrk_dealloc( jpi, jpj,  ftempc2d    )
+         ENDIF
+         IF( med_diag%FASTCA%dgsave ) THEN
+            CALL iom_put( "FASTCA"  , ftempca2d )
+            CALL wrk_dealloc( jpi, jpj,  ftempca2d   )
+         ENDIF
+         !! 
+         IF( med_diag%REMINN%dgsave ) THEN
+            CALL iom_put( "REMINN"  , freminn2d )
+            CALL wrk_dealloc( jpi, jpj,   freminn2d   )
+         ENDIF
+         IF( med_diag%REMINSI%dgsave ) THEN
+            CALL iom_put( "REMINSI"  , freminsi2d )
+            CALL wrk_dealloc( jpi, jpj,   freminsi2d   )
+         ENDIF
+         IF( med_diag%REMINFE%dgsave ) THEN
+            CALL iom_put( "REMINFE"  , freminfe2d )
+            CALL wrk_dealloc( jpi, jpj,  freminfe2d    )
+         ENDIF
+         IF( med_diag%REMINC%dgsave ) THEN
+            CALL iom_put( "REMINC"  , freminc2d )
+            CALL wrk_dealloc( jpi, jpj,    freminc2d  )
+         ENDIF
+         IF( med_diag%REMINCA%dgsave ) THEN
+            CALL iom_put( "REMINCA"  , freminca2d )
+            CALL wrk_dealloc( jpi, jpj,   freminca2d  )
+         ENDIF
+         IF( med_diag%SEAFLRN%dgsave ) THEN
+            CALL iom_put( "SEAFLRN"  , fsedn )
+         ENDIF
+         IF( med_diag%SEAFLRSI%dgsave ) THEN
+            CALL iom_put( "SEAFLRSI"  , fsedsi )
+         ENDIF
+         IF( med_diag%SEAFLRFE%dgsave ) THEN
+            CALL iom_put( "SEAFLRFE"  , fsedfe )
+         ENDIF
+         IF( med_diag%SEAFLRC%dgsave ) THEN
+            CALL iom_put( "SEAFLRC"  , fsedc )
+         ENDIF
+         IF( med_diag%SEAFLRCA%dgsave ) THEN
+            CALL iom_put( "SEAFLRCA"  , fsedca )
+         ENDIF
+         !!
+# if defined key_roam            
+         !!
+         IF( med_diag%RIV_N%dgsave ) THEN
+            CALL iom_put( "RIV_N"  , rivn2d )
+            CALL wrk_dealloc( jpi, jpj,    rivn2d  )
+         ENDIF
+         IF( med_diag%RIV_SI%dgsave ) THEN
+            CALL iom_put( "RIV_SI"  , rivsi2d )
+            CALL wrk_dealloc( jpi, jpj,   rivsi2d   )
+         ENDIF
+         IF( med_diag%RIV_C%dgsave ) THEN
+            CALL iom_put( "RIV_C"  , rivc2d )
+            CALL wrk_dealloc( jpi, jpj,    rivc2d  )
+         ENDIF
+         IF( med_diag%RIV_ALK%dgsave ) THEN
+            CALL iom_put( "RIV_ALK"  , rivalk2d )
+            CALL wrk_dealloc( jpi, jpj,  rivalk2d    )
+         ENDIF
+         IF( med_diag%DETC%dgsave ) THEN
+            CALL iom_put( "DETC"  , fslowc2d )
+            CALL wrk_dealloc( jpi, jpj,   fslowc2d   )
+         ENDIF
+         !!
+         IF( med_diag%PN_LLOSS%dgsave ) THEN
+            CALL iom_put( "PN_LLOSS"  , fdpn22d )
+            CALL wrk_dealloc( jpi, jpj,   fdpn22d   )
+         ENDIF
+         IF( med_diag%PD_LLOSS%dgsave ) THEN
+            CALL iom_put( "PD_LLOSS"  , fdpd22d )
+            CALL wrk_dealloc( jpi, jpj,   fdpd22d   )
+         ENDIF
+         IF( med_diag%ZI_LLOSS%dgsave ) THEN
+            CALL iom_put( "ZI_LLOSS"  , fdzmi22d )
+             CALL wrk_dealloc( jpi, jpj,    fdzmi22d  )
+          ENDIF
+          IF( med_diag%ZE_LLOSS%dgsave ) THEN
+             CALL iom_put( "ZE_LLOSS"  , fdzme22d )
+             CALL wrk_dealloc( jpi, jpj,   fdzme22d   )
+          ENDIF
+          IF( med_diag%ZI_MES_N%dgsave ) THEN
+             CALL iom_put( "ZI_MES_N"  , zimesn2d )
+             CALL wrk_dealloc( jpi, jpj,    zimesn2d  )
+          ENDIF
+          IF( med_diag%ZI_MES_D%dgsave ) THEN
+             CALL iom_put( "ZI_MES_D"  , zimesd2d )
+             CALL wrk_dealloc( jpi, jpj,    zimesd2d  )
+          ENDIF
+          IF( med_diag%ZI_MES_C%dgsave ) THEN
+             CALL iom_put( "ZI_MES_C"  , zimesc2d )
+             CALL wrk_dealloc( jpi, jpj,    zimesc2d  )
+          ENDIF
+          IF( med_diag%ZI_MESDC%dgsave ) THEN
+             CALL iom_put( "ZI_MESDC"  ,zimesdc2d  )
+             CALL wrk_dealloc( jpi, jpj,    zimesdc2d  )
+          ENDIF
+          IF( med_diag%ZI_EXCR%dgsave ) THEN
+             CALL iom_put( "ZI_EXCR"  , ziexcr2d )
+             CALL wrk_dealloc( jpi, jpj,    ziexcr2d )
+          ENDIF
+          IF( med_diag%ZI_RESP%dgsave ) THEN
+             CALL iom_put( "ZI_RESP"  , ziresp2d )
+             CALL wrk_dealloc( jpi, jpj,   ziresp2d   )
+          ENDIF
+          IF( med_diag%ZI_GROW%dgsave ) THEN
+             CALL iom_put( "ZI_GROW"  , zigrow2d )
+             CALL wrk_dealloc( jpi, jpj,   zigrow2d   )
+          ENDIF
+          IF( med_diag%ZE_MES_N%dgsave ) THEN
+             CALL iom_put( "ZE_MES_N"  , zemesn2d )
+             CALL wrk_dealloc( jpi, jpj,    zemesn2d  )
+          ENDIF
+          IF( med_diag%ZE_MES_D%dgsave ) THEN
+             CALL iom_put( "ZE_MES_D"  , zemesd2d )
+             CALL wrk_dealloc( jpi, jpj,    zemesd2d  )
+          ENDIF
+          IF( med_diag%ZE_MES_C%dgsave ) THEN
+             CALL iom_put( "ZE_MES_C"  , zemesc2d )
+             CALL wrk_dealloc( jpi, jpj,   zemesc2d   )
+          ENDIF
+          IF( med_diag%ZE_MESDC%dgsave ) THEN
+             CALL iom_put( "ZE_MESDC"  , zemesdc2d )
+             CALL wrk_dealloc( jpi, jpj,   zemesdc2d   )
+          ENDIF
+          IF( med_diag%ZE_EXCR%dgsave ) THEN
+             CALL iom_put( "ZE_EXCR"  , zeexcr2d )
+             CALL wrk_dealloc( jpi, jpj,   zeexcr2d   )
+          ENDIF
+          IF( med_diag%ZE_RESP%dgsave ) THEN
+             CALL iom_put( "ZE_RESP"  , zeresp2d )
+             CALL wrk_dealloc( jpi, jpj,    zeresp2d  )
+          ENDIF
+          IF( med_diag%ZE_GROW%dgsave ) THEN
+             CALL iom_put( "ZE_GROW"  , zegrow2d )
+             CALL wrk_dealloc( jpi, jpj,   zegrow2d   )
+          ENDIF
+          IF( med_diag%MDETC%dgsave ) THEN
+             CALL iom_put( "MDETC"  , mdetc2d )
+             CALL wrk_dealloc( jpi, jpj,   mdetc2d   )
+          ENDIF
+          IF( med_diag%GMIDC%dgsave ) THEN
+             CALL iom_put( "GMIDC"  , gmidc2d )
+             CALL wrk_dealloc( jpi, jpj,    gmidc2d  )
+          ENDIF
+          IF( med_diag%GMEDC%dgsave ) THEN
+             CALL iom_put( "GMEDC"  , gmedc2d )
+             CALL wrk_dealloc( jpi, jpj,    gmedc2d  )
+          ENDIF
+          IF( med_diag%IBEN_N%dgsave ) THEN
+             CALL iom_put( "IBEN_N"  , iben_n2d )
+             CALL wrk_dealloc( jpi, jpj,    iben_n2d  )
+          ENDIF
+          IF( med_diag%IBEN_FE%dgsave ) THEN
+             CALL iom_put( "IBEN_FE"  , iben_fe2d )
+             CALL wrk_dealloc( jpi, jpj,   iben_fe2d   )
+          ENDIF
+          IF( med_diag%IBEN_C%dgsave ) THEN
+             CALL iom_put( "IBEN_C"  , iben_c2d )
+             CALL wrk_dealloc( jpi, jpj,   iben_c2d   )
+          ENDIF
+          IF( med_diag%IBEN_SI%dgsave ) THEN
+             CALL iom_put( "IBEN_SI"  , iben_si2d )
+             CALL wrk_dealloc( jpi, jpj,   iben_si2d   )
+          ENDIF
+          IF( med_diag%IBEN_CA%dgsave ) THEN
+             CALL iom_put( "IBEN_CA"  , iben_ca2d )
+             CALL wrk_dealloc( jpi, jpj,   iben_ca2d   )
+          ENDIF
+          IF( med_diag%OBEN_N%dgsave ) THEN
+             CALL iom_put( "OBEN_N"  , oben_n2d )
+             CALL wrk_dealloc( jpi, jpj,    oben_n2d  )
+          ENDIF
+          IF( med_diag%OBEN_FE%dgsave ) THEN
+             CALL iom_put( "OBEN_FE"  , oben_fe2d )
+             CALL wrk_dealloc( jpi, jpj,    oben_fe2d  )
+          ENDIF
+          IF( med_diag%OBEN_C%dgsave ) THEN
+             CALL iom_put( "OBEN_C"  , oben_c2d )
+             CALL wrk_dealloc( jpi, jpj,    oben_c2d  )
+          ENDIF
+          IF( med_diag%OBEN_SI%dgsave ) THEN
+             CALL iom_put( "OBEN_SI"  , oben_si2d )
+             CALL wrk_dealloc( jpi, jpj,    oben_si2d  )
+          ENDIF
+          IF( med_diag%OBEN_CA%dgsave ) THEN
+             CALL iom_put( "OBEN_CA"  , oben_ca2d )
+             CALL wrk_dealloc( jpi, jpj, oben_ca2d     )
+          ENDIF
+          IF( med_diag%SFR_OCAL%dgsave ) THEN
+             CALL iom_put( "SFR_OCAL"  , sfr_ocal2d )
+             CALL wrk_dealloc( jpi, jpj,    sfr_ocal2d  )
+          ENDIF
+          IF( med_diag%SFR_OARG%dgsave ) THEN
+             CALL iom_put( "SFR_OARG"  , sfr_oarg2d )
+             CALL wrk_dealloc( jpi, jpj,    sfr_oarg2d  )
+          ENDIF
+          IF( med_diag%LYSO_CA%dgsave ) THEN
+             CALL iom_put( "LYSO_CA"  , lyso_ca2d )
+             CALL wrk_dealloc( jpi, jpj,    lyso_ca2d  )
+          ENDIF
+# endif                   
+          !!
+          !! ** 3D diagnostics
+          IF( med_diag%TPP3%dgsave ) THEN
+             CALL iom_put( "TPP3"  , tpp3d )
+             CALL wrk_dealloc( jpi, jpj, jpk,   tpp3d  )
+          ENDIF
+          IF( med_diag%DETFLUX3%dgsave ) THEN
+             CALL iom_put( "DETFLUX3"  , detflux3d )
+             CALL wrk_dealloc( jpi, jpj, jpk,    detflux3d )
+          ENDIF
+          IF( med_diag%REMIN3N%dgsave ) THEN
+             CALL iom_put( "REMIN3N"  , remin3dn )
+             CALL wrk_dealloc( jpi, jpj, jpk,   remin3dn  )
+          ENDIF
+# if defined key_roam          
+          IF( med_diag%PH3%dgsave ) THEN
+             CALL iom_put( "PH3"  , f3_pH )
+          ENDIF
+          IF( med_diag%OM_CAL3%dgsave ) THEN
+             CALL iom_put( "OM_CAL3"  , f3_omcal )
+          ENDIF
+          !!
+          !! AXY (09/11/16): 2D CMIP6 diagnostics
+          IF( med_diag%INTDISSIC%dgsave ) THEN
+             CALL iom_put( "INTDISSIC"  , intdissic )
+             CALL wrk_dealloc( jpi, jpj, intdissic   )
+          ENDIF          
+          IF( med_diag%INTDISSIN%dgsave ) THEN
+             CALL iom_put( "INTDISSIN"  , intdissin )
+             CALL wrk_dealloc( jpi, jpj, intdissin   )
+          ENDIF          
+          IF( med_diag%INTDISSISI%dgsave ) THEN
+             CALL iom_put( "INTDISSISI"  , intdissisi )
+             CALL wrk_dealloc( jpi, jpj, intdissisi  )
+          ENDIF          
+          IF( med_diag%INTTALK%dgsave ) THEN
+             CALL iom_put( "INTTALK"  , inttalk )
+             CALL wrk_dealloc( jpi, jpj, inttalk     )
+          ENDIF          
+          IF( med_diag%O2min%dgsave ) THEN
+             CALL iom_put( "O2min"  , o2min )
+             CALL wrk_dealloc( jpi, jpj, o2min       )
+          ENDIF          
+          IF( med_diag%ZO2min%dgsave ) THEN
+             CALL iom_put( "ZO2min"  , zo2min )
+             CALL wrk_dealloc( jpi, jpj, zo2min      )
+          ENDIF          
+          IF( med_diag%FBDDTALK%dgsave ) THEN
+             CALL iom_put( "FBDDTALK"  , fbddtalk   )
+             CALL wrk_dealloc( jpi, jpj, fbddtalk   )
+          ENDIF          
+          IF( med_diag%FBDDTDIC%dgsave ) THEN
+             CALL iom_put( "FBDDTDIC"  , fbddtdic   )
+             CALL wrk_dealloc( jpi, jpj, fbddtdic   )
+          ENDIF          
+          IF( med_diag%FBDDTDIFE%dgsave ) THEN
+             CALL iom_put( "FBDDTDIFE" , fbddtdife  )
+             CALL wrk_dealloc( jpi, jpj, fbddtdife  )
+          ENDIF          
+          IF( med_diag%FBDDTDIN%dgsave ) THEN
+             CALL iom_put( "FBDDTDIN"  , fbddtdin   )
+             CALL wrk_dealloc( jpi, jpj, fbddtdin   )
+          ENDIF          
+          IF( med_diag%FBDDTDISI%dgsave ) THEN
+             CALL iom_put( "FBDDTDISI" , fbddtdisi  )
+             CALL wrk_dealloc( jpi, jpj, fbddtdisi  )
+          ENDIF    
+          !!
+          !! AXY (09/11/16): 3D CMIP6 diagnostics
+          IF( med_diag%TPPD3%dgsave ) THEN
+             CALL iom_put( "TPPD3"     , tppd3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, tppd3      )
+          ENDIF          
+          IF( med_diag%BDDTALK3%dgsave ) THEN
+             CALL iom_put( "BDDTALK3"  , bddtalk3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, bddtalk3   )
+          ENDIF          
+          IF( med_diag%BDDTDIC3%dgsave ) THEN
+             CALL iom_put( "BDDTDIC3"  , bddtdic3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, bddtdic3   )
+          ENDIF          
+          IF( med_diag%BDDTDIFE3%dgsave ) THEN
+             CALL iom_put( "BDDTDIFE3" , bddtdife3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, bddtdife3  )
+          ENDIF          
+          IF( med_diag%BDDTDIN3%dgsave ) THEN
+             CALL iom_put( "BDDTDIN3"  , bddtdin3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, bddtdin3   )
+          ENDIF          
+          IF( med_diag%BDDTDISI3%dgsave ) THEN
+             CALL iom_put( "BDDTDISI3" , bddtdisi3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, bddtdisi3  )
+          ENDIF    
+          IF( med_diag%FD_NIT3%dgsave ) THEN
+             CALL iom_put( "FD_NIT3"  , fd_nit3 )
+             CALL wrk_dealloc( jpi, jpj, jpk,   fd_nit3  )
+          ENDIF
+          IF( med_diag%FD_SIL3%dgsave ) THEN
+             CALL iom_put( "FD_SIL3"  , fd_sil3 )
+             CALL wrk_dealloc( jpi, jpj, jpk,   fd_sil3  )
+          ENDIF
+          IF( med_diag%FD_CAL3%dgsave ) THEN
+             CALL iom_put( "FD_CAL3"  , fd_cal3 )
+             CALL wrk_dealloc( jpi, jpj, jpk,   fd_cal3  )
+          ENDIF
+          IF( med_diag%FD_CAR3%dgsave ) THEN
+             CALL iom_put( "FD_CAR3"  , fd_car3 )
+             CALL wrk_dealloc( jpi, jpj, jpk,   fd_car3  )
+          ENDIF
+          IF( med_diag%CO33%dgsave ) THEN
+             CALL iom_put( "CO33"  , f3_co3 )
+          ENDIF          	        
+          IF( med_diag%CO3SATARAG3%dgsave ) THEN
+             CALL iom_put( "CO3SATARAG3"  , f3_omarg )
+          ENDIF          	        
+          IF( med_diag%CO3SATCALC3%dgsave ) THEN
+             CALL iom_put( "CO3SATCALC3"  , f3_omcal )
+          ENDIF          	        
+          IF( med_diag%EXPC3%dgsave ) THEN
+             CALL iom_put( "EXPC3"  , expc3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, expc3  )
+          ENDIF          	        
+          IF( med_diag%EXPN3%dgsave ) THEN
+             CALL iom_put( "EXPN3"  , expn3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, expn3  )
+          ENDIF          	        
+          IF( med_diag%DCALC3%dgsave ) THEN
+             CALL iom_put( "DCALC3"  , dcalc3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, dcalc3  )
+          ENDIF          	        
+          IF( med_diag%FEDISS3%dgsave ) THEN
+             CALL iom_put( "FEDISS3"  , fediss3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, fediss3  )
+          ENDIF          	        
+          IF( med_diag%FESCAV3%dgsave ) THEN
+             CALL iom_put( "FESCAV3"  , fescav3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, fescav3  )
+          ENDIF          	        
+          IF( med_diag%MIGRAZP3%dgsave ) THEN
+             CALL iom_put( "MIGRAZP3"  , migrazp3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, migrazp3  )
+          ENDIF          	        
+          IF( med_diag%MIGRAZD3%dgsave ) THEN
+             CALL iom_put( "MIGRAZD3"  , migrazd3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, migrazd3  )
+          ENDIF          	        
+          IF( med_diag%MEGRAZP3%dgsave ) THEN
+             CALL iom_put( "MEGRAZP3"  , megrazp3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, megrazp3  )
+          ENDIF          	        
+          IF( med_diag%MEGRAZD3%dgsave ) THEN
+             CALL iom_put( "MEGRAZD3"  , megrazd3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, megrazd3  )
+          ENDIF          	        
+          IF( med_diag%MEGRAZZ3%dgsave ) THEN
+             CALL iom_put( "MEGRAZZ3"  , megrazz3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, megrazz3  )
+          ENDIF          	        
+          IF( med_diag%O2SAT3%dgsave ) THEN
+             CALL iom_put( "O2SAT3"  , o2sat3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, o2sat3 )
+          ENDIF          	        
+          IF( med_diag%PBSI3%dgsave ) THEN
+             CALL iom_put( "PBSI3"  , pbsi3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pbsi3  )
+          ENDIF          	        
+          IF( med_diag%PCAL3%dgsave ) THEN
+             CALL iom_put( "PCAL3"  , pcal3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pcal3  )
+          ENDIF          	        
+          IF( med_diag%REMOC3%dgsave ) THEN
+             CALL iom_put( "REMOC3"  , remoc3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, remoc3 )
+          ENDIF          	        
+          IF( med_diag%PNLIMJ3%dgsave ) THEN
+             CALL iom_put( "PNLIMJ3" , pnlimj3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pnlimj3  )
+          ENDIF          	        
+          IF( med_diag%PNLIMN3%dgsave ) THEN
+             CALL iom_put( "PNLIMN3" , pnlimn3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pnlimn3  )
+          ENDIF          	        
+          IF( med_diag%PNLIMFE3%dgsave ) THEN
+             CALL iom_put( "PNLIMFE3" , pnlimfe3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pnlimfe3 )
+          ENDIF          	        
+          IF( med_diag%PDLIMJ3%dgsave ) THEN
+             CALL iom_put( "PDLIMJ3" , pdlimj3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pdlimj3  )
+          ENDIF          	        
+          IF( med_diag%PDLIMN3%dgsave ) THEN
+             CALL iom_put( "PDLIMN3" , pdlimn3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pdlimn3  )
+          ENDIF          	        
+          IF( med_diag%PDLIMFE3%dgsave ) THEN
+             CALL iom_put( "PDLIMFE3" , pdlimfe3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pdlimfe3 )
+          ENDIF          	        
+          IF( med_diag%PDLIMSI3%dgsave ) THEN
+             CALL iom_put( "PDLIMSI3" , pdlimsi3 )
+             CALL wrk_dealloc( jpi, jpj, jpk, pdlimsi3 )
+          ENDIF          	        
+          
+# endif         
+
+          CALL wrk_dealloc( jpi, jpj,   zw2d   )
+
+       ENDIF                    ! end of ln_diatrc option
+
+# if defined key_trc_diabio
+       !! Lateral boundary conditions on trcbio
+       DO jn=1,jp_medusa_trd
+          CALL lbc_lnk(trbio(:,:,1,jn),'T',1. )
+       ENDDO 
+# endif
+
+# if defined key_debug_medusa
+       IF(lwp) WRITE(numout,*) ' MEDUSA exiting trc_bio_medusa at kt =', kt
+       CALL flush(numout)
+# endif
+
+   END SUBROUTINE trc_bio_medusa
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_bio_medusa( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_bio_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_bio_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcbio_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90	(revision 7693)
@@ -0,0 +1,1136 @@
+MODULE trcco2_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcco2_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2010-12  (A. Yool)             added for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA carbonate chemistry
+   !!----------------------------------------------------------------------
+   !!   trc_co2_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE in_out_manager  ! I/O manager
+
+      IMPLICIT NONE
+      PRIVATE
+      
+      PUBLIC   trc_co2_medusa    ! called in trc_bio_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+! The following is a map of the subroutines contained within this module
+! - trc_co2_medusa
+!      - CALLS CO2_dynamics
+!           - CALLS CO2DYN
+!		 - CALLS POLYCO
+!		      - CALLS CO2SET
+!		      - CALLS CO2CLC
+!           - CALLS CaCO3_Saturation
+!      - CALLS Air_sea_exchange
+
+CONTAINS
+
+!=======================================================================
+!
+      SUBROUTINE trc_co2_medusa( Temp, Sal, DIC, ALK, Depth, xkw, pCO2a, &
+      pH, pCO2w, h2co3, hco3, co3, om_cal, om_arg, co2flux, TDIC, TALK,  &
+      dcf, henry, iters )
+!      
+!=======================================================================
+!  
+! This file contains a set of FORTRAN subroutines that calculate the carbonate system 
+! at any given point in marine space time, given values for 
+! temperature, salinity, DIC, depth (pressure). 
+! This is essentially an implimentation of the Haltafall speciation code
+! (Ingri et al 1967, Talanta 14, 1261 - if it ain't broke don't fix it)
+! Another routine calulates the air sea exchange of CO2 given wind speed and atmospheric pCO2.
+! Code developed by Jerry blackford and others at PML, based on pre-existing code.
+! We accept no liability for errors or inaccuracies.
+! See Zeebe & Wolf-Gladrow, 2001. CO2 in seawater: equilibrium, kinetics and isotopes. 
+! Elsevier Oceanography Series 65, 346. for a reasonable overview. 
+! Many other packages exist, replicating the same functionality in different languages.
+! See http://cdiac.ornl.gov/oceans/co2rprt.html (CO2sys)
+! or  http://neon.otago.ac.nz/research/mfc/people/keith_hunter/software/swco2/
+! reference for prior usage of this code: Blackford & Gilbert, 2007. J Mar Sys 64, 229-241.
+! 
+! Modifications
+! 17/02/2010. Added conversion factor from per m3 to per kg (line 108-133)
+! 17/02/2010. Update calculation of K1, K2, Kb to make consistant with the OCMIP protocols.
+! 29/07/2011. Merged into MEDUSA with a raft of changes to this subroutine; less elsewhere
+! 23/06/2015. Modified to take gas transfer velocity as an input (rather than wind speed); 
+!             alter CO2 flux to /s rather than /d for consistency with other schemes
+!
+! Changes for MEDUSA include: 
+!     - making the program a module
+!     - passing in input variables (obvious given the last point)
+!     - making alkalinity a state variable (rather than a function of salinity)
+!
+      IMPLICIT NONE
+
+      REAL(wp), INTENT( in )    :: Temp       ! degrees C
+      REAL(wp), INTENT( in )    :: Sal        ! PSU
+      REAL(wp), INTENT( in )    :: DIC        ! mmol / m3
+      REAL(wp), INTENT( in )    :: ALK        ! meq  / m3
+      REAL(wp), INTENT( in )    :: Depth      ! m
+!     REAL(wp), INTENT( in )    :: Wnd        ! m / s
+      REAL(wp), INTENT( in )    :: xkw        ! m / s
+      REAL(wp), INTENT( in )    :: pCO2a      ! uatm
+!----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: pH         ! "normal" pH units
+      REAL(wp), INTENT( inout ) :: pCO2w      ! uatm
+      REAL(wp), INTENT( inout ) :: h2co3      ! mmol / m3
+      REAL(wp), INTENT( inout ) :: hco3       ! mmol / m3
+      REAL(wp), INTENT( inout ) :: co3        ! mmol / m3
+      REAL(wp), INTENT( inout ) :: om_cal     ! normalised
+      REAL(wp), INTENT( inout ) :: om_arg     ! normalised
+      REAL(wp), INTENT( inout ) :: co2flux    ! mmol / m2 / s
+      REAL(wp), INTENT( inout ) :: TDIC       ! umol / kg
+      REAL(wp), INTENT( inout ) :: TALK       ! ueq  / kg
+      REAL(wp), INTENT( inout ) :: dcf        ! m3 / kg
+      REAL(wp), INTENT( inout ) :: henry      ! ?
+      INTEGER,  INTENT( inout ) :: iters      ! # iterations to convergence
+!----------------------------------------------------------------------
+!     REAL(wp) :: cco2,bicarb,carb,henry
+      REAL(wp) :: cco2,bicarb,carb
+! ======================================================================
+
+! write inputs to screen
+!  WRITE(*,*) " "
+!  WRITE(*,'(A28)')       "    .........Inputs........."
+!  WRITE(*,'(A24,F10.3)') "    Temperature   (C) = ", Temp
+!  WRITE(*,'(A24,F10.3)') "    Salinity    (psu) = ", Sal
+!  WRITE(*,'(A24,F10.3)') "    Depth         (m) = ", Depth
+!  WRITE(*,'(A24,F10.3)') "    DIC     (mmol/m3) = ", DIC
+!  WRITE(*,'(A24,F10.3)') "    ALK      (ueq/m3) = ", ALK
+!  WRITE(*,'(A24,F10.3)') "    Wind speed  (m/s) = ", Wnd
+!  WRITE(*,'(A24,F10.3)') "    pCO2 atmos (uatm) = ", pCO2a
+
+! AXY (07/05/13) ==================================================
+! set total number of iterations to zero
+      iters = 0
+! AXY (07/05/13) ==================================================
+  
+   call CO2_dynamics( Temp, Sal, Depth, DIC, ALK, pCO2a, &                  ! inputs
+      pco2w, ph, h2co3, hco3, co3, henry, om_cal, om_arg, TDIC, TALK, &     ! outputs
+      dcf, iters)                                                           ! outputs
+
+   ! AXY (18/08/11): only do air-sea exchange calculation if depth = 0 
+   !                 (i.e. surface calculations being performed)
+   if (Depth .eq. 0.0) then
+      call Air_sea_exchange( Temp, xkw, pCO2w, pCO2a, henry, dcf, &         ! inputs
+         co2flux )                                                          ! output
+   else
+      co2flux = 0.0
+   endif      
+
+! AXY (09/01/14) ==================================================
+! check for non-convergence and NaNs
+   !!
+   if (iters .eq. 25) then
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: ITERS WARNING, ', &
+      iters, ' AT depth =', Depth
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: ztmp    =', Temp
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: zsal    =', Sal
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: zdic    =', DIC
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: zalk    =', ALK
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_kw660 =', xkw
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_ph    =', ph
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_pco2w =', pCO2w
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_h2co3 =', h2co3
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_hco3  =', hco3
+      IF(lwp) WRITE(numout,*) ' trc_co2_medusa: f_co3   =', co3
+   endif
+   !!
+   !! AXY (29/10/13): NaN checks
+   if (co2flux /= co2flux) then
+      !! if (lwp) write (numout,'(a,1pe10.2,4i6)') 'CO2FLUX-NAN', &
+      !! &        tmask(ji,jj,jk), kt, ji, jj, jk
+      if (lwp) write (numout,'(a,a,f10.3,a,f10.3)') 'CO2FLUX-NAN', &
+      &        ' TMP', Temp, ' SAL', Sal
+      if (lwp) write (numout,'(a,a,f10.3,a,f10.3)') 'CO2FLUX-NAN', &
+      &        ' DIC', DIC, ' ALK', ALK
+      if (lwp) write (numout,'(a,a,f10.3,a,f10.3)') 'CO2FLUX-NAN', &
+      &        ' XKW', xkw, ' PH ', ph
+      if (lwp) write (numout,'(a,a,i6)') 'CO2FLUX-NAN', &
+      &        ' ITERS', iters
+   endif
+   !!
+   !! AXY (09/01/14): NaN fudges
+   if (co2flux /= co2flux) then
+      ph      = 8.1
+      pCO2w   = pCO2a
+      h2co3   = 0.005 * DIC
+      hco3    = 0.865 * DIC
+      co3     = 0.130 * DIC
+      om_cal  = 4.
+      om_arg  = 2.
+      co2flux = 0.
+      TDIC    = DIC
+      TALK    = ALK
+      dcf     = 1.
+      henry   = 1.
+   endif
+! AXY (09/01/14) ==================================================
+
+! write outputs to screen
+!  WRITE(*,*) " "
+!  WRITE(*,'(A32,F10.3)') "    ..........Outputs..........."
+!  WRITE(*,'(A27,F10.3)') "    pH                 (pH) = ", pH
+!  WRITE(*,'(A27,F10.3)') "    DIC           (umol/kg) = ", TDIC
+!  WRITE(*,'(A27,F10.3)') "    TALK           (ueq/kg) = ", TALK
+!  WRITE(*,'(A27,F10.3)') "    pco2w            (uatm) = ", pco2w
+!  WRITE(*,'(A27,F10.3)') "    carbonic acid (mmol/m3) = ", h2co3
+!  WRITE(*,'(A27,F10.3)') "    bicarbonate   (mmol/m3) = ", bicarb
+!  WRITE(*,'(A27,F10.3)') "    carbonate     (mmol/m3) = ", carb
+!  WRITE(*,'(A27,F10.3)') "    Omega calcite       (~) = ", om_cal
+!  WRITE(*,'(A27,F10.3)') "    Omega aragonite     (~) = ", om_arg
+!  WRITE(*,'(A27,F10.3)') "    air sea flux(mmol/m2/s) = ", flux
+!  WRITE(*,*) " "
+
+   END SUBROUTINE trc_co2_medusa
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      subroutine CO2_dynamics( T, S, Z, DIC, TALK, pco2a, &
+      pco2w, ph, h2co3, bicarb, carb, henry, om_cal, om_arg, TCO2, TA, &
+      dcf, iters )
+!      
+!=======================================================================
+!  
+   IMPLICIT NONE
+
+      REAL(wp), INTENT( in )    :: T          ! temperature (C)
+      REAL(wp), INTENT( in )    :: S          ! salinity (psu)
+      REAL(wp), INTENT( in )    :: Z          ! depth (metres)
+      REAL(wp), INTENT( in )    :: DIC        ! total dissolved inorganic carbon (mmol.m-3)
+      REAL(wp), INTENT( in )    :: TALK       ! total alkalinity (meq.m-3)
+      REAL(wp), INTENT( in )    :: pco2a      ! atmospheric pCO2
+!----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: pco2w      ! seawater pCO2
+      REAL(wp), INTENT( inout ) :: ph         ! seawater pH
+      REAL(wp), INTENT( inout ) :: h2co3      ! seawater carbonic acid (H2CO3)
+      REAL(wp), INTENT( inout ) :: bicarb     ! seawater bicarbonate ion (HCO3)
+      REAL(wp), INTENT( inout ) :: carb       ! seawater carbonate ion (CO3)
+      REAL(wp), INTENT( inout ) :: henry      ! Henry constant
+      REAL(wp), INTENT( inout ) :: om_cal     ! Omega calcite
+      REAL(wp), INTENT( inout ) :: om_arg     ! Omega aragonite
+      REAL(wp), INTENT( inout ) :: TCO2       ! total dissolved inorganic carbon (mol.kg-1)
+      REAL(wp), INTENT( inout ) :: TA         ! total alkalinity (eq.kg-1)
+      REAL(wp), INTENT( inout ) :: dcf        ! density conversion factor
+      INTEGER,  INTENT( inout ) :: iters      ! # iterations to convergence
+!----------------------------------------------------------------------
+      REAL(wp) :: a, b, c
+      REAL(wp) :: ca, bc, cb
+      REAL(wp) :: pco2water, fairco2
+
+! ======================================================================
+
+! Adjust to correct units.
+! Haltafall uses mol/kg rather than umol/kg necessitating a scaling factor of /1.0D6
+! DIC (mmol/m3) needs to be converted to umol/kg via the calculation of water density at prevailing T&S
+! sea-water density (Millero & Poisson, Deep-Sea Research, 1981, also known as UNESCO, 1981)
+! with T: Temperature in degree Celsius; S: Salinity in practical units, density in kg/m3
+! valid for 0<T<40 and 0.5<S<43. Density Conversion factor (dcf) = * density * 1.0D3
+
+          a   =  8.24493d-1 - 4.0899d-3*T +  7.6438d-5*T**2 - 8.2467d-7*T**3 + 5.3875d-9*T**4
+          b   = -5.72466d-3 + 1.0227d-4*T - 1.6546d-6*T**2 
+          c   = 4.8314d-4
+          dcf = (999.842594 + 6.793952d-2*T- 9.095290d-3*T**2 + 1.001685d-4*T**3 &
+                - 1.120083d-6*T**4 + 6.536332d-9*T**5+a*S+b*S**1.5+c*S**2)/1.0D3
+
+          TA    = TALK / (1.0D6*dcf)
+          TCO2  = DIC  / (1.0D6*dcf)
+
+! Call the parent routine for the carbonate system
+          CALL CO2DYN ( TCO2, TA, T, S, pco2a, &     ! inputs
+          pco2water, pH, HENRY, ca, bc, cb, iters )  ! outputs
+
+! Adjust outputs back to units used in the parent model code (e.g. mmol/m3) if appropriate
+
+          pco2w  = pco2water * (1.0D6) 	! partial pressure of co2 in water 
+          TA     = TA * (1.0D6)         ! total alkalinity (umol/kg)
+          h2co3  = ca * (1.0D6*dcf)     ! carbonic acid concentration (mmol/m3)
+          bicarb = bc * (1.0D6*dcf)     ! bicarbonate ion concentration (mmol/m3)
+          carb   = cb * (1.0D6*dcf)     ! carbonate ion concentration (mmol/m3)
+          TCO2   = TCO2 * (1.0D6)       ! total C or DIC in units of umol/kg
+
+! Call carbonate saturation state subroutine to calculate calcite and aragonite calcification states
+
+          CALL CaCO3_Saturation ( T, S, Z, cb, &  ! inputs
+          om_cal, om_arg )                        ! outputs
+
+   RETURN
+
+   END SUBROUTINE CO2_dynamics
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE Air_sea_exchange( T, xkw, pco2w, pco2a, henry, dcf, &
+      flux )
+!      
+!=======================================================================
+!  
+!  This routine should be called for the surface box only (like, duh)
+!  Uses the Nightingale and Liss parameterisation (GBC 14, 373-388 (2000).
+!  SC is the Schmidt number from Wanninkhof (1992, JGR 97,7373-7382), the Nightingale et al (2000)
+!  transfer velocity being for Sc=600 and the dependence of tranfer velocity on Sc coming 
+!  from Jahne et al (1987, J. Geophys Res 92, 1937-1949).
+
+!  Inputs
+!  pCO2w    partial pressure of CO2 in the water (from carbonate system subroutine call)
+!  pCO2a    partial pressure of CO2 in the atmosphere (usually external forcing).
+!  T        temperature (C)
+!  Wnd      wind speed, metres (DELETED)
+!  xkw      gas transfer velocity
+!  Henry    henry's constant
+!  density  the density of water for conversion between mmol/m3 and umol/kg
+
+!  Outputs are
+!  flux     flux of CO2 in mmol C /m2/d 
+!           +ve is in-gassing (air to sea), -ve is outgassing (sea to air).
+
+   IMPLICIT NONE
+
+      REAL(wp), INTENT( in )    :: T, xkw, pco2w, pco2a, henry, dcf ! INPUT PARAMETERS:
+!-----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: flux                             ! OUTPUT Variables
+!-----------------------------------------------------------------------
+      REAL(wp)                  :: sc, fwind                        ! LOCAL VARIABLES:
+
+! calculate the Schmidt number and unit conversions
+          sc    = 2073.1-125.62*T+3.6276*T**2.0-0.0432190*T**3.0
+!         fwind = (0.222d0 * wnd**2d0 + 0.333d0 * wnd)*(sc/660.d0)**(-0.5)
+          fwind = xkw * (sc/660.d0)**(-0.5)
+          fwind = fwind*24.d0/100.d0   ! convert to m/day
+
+! flux depends on the difference in partial pressures, wind and henry
+! here it is rescaled to mmol/m2/d
+          flux = fwind * henry * ( pco2a - pco2w ) * dcf
+
+! AXY (23/06/15): let's get it from /d to /s
+          flux = flux / ( 86400. )
+
+  RETURN 
+
+  END SUBROUTINE Air_sea_exchange
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CO2dyn ( TCO2, TA, T, S, PCO2A, PCO2, PH, HENRY, ca, bc, cb, iters )
+!      
+!=======================================================================
+!
+!     This subroutine acts as an interface to the Haltafall iteration, setting options etc.
+
+      REAL(wp), INTENT( in )    :: TCO2, TA, T, S, PCO2A
+!-----------------------------------------------------------------------
+      REAL(wp), INTENT( inout ) :: PCO2, PH, HENRY, ca, bc, cb
+      INTEGER,  INTENT( inout ) :: iters
+!-----------------------------------------------------------------------
+      REAL(wp) :: PRSS
+      INTEGER  :: MCONC, MKVAL, ICONST, ICALC
+
+      PARAMETER ( MCONC = 9,MKVAL = 4 )
+
+      REAL(wp), DIMENSION(MKVAL) :: AKVAL
+      REAL(wp), DIMENSION(MCONC) :: CONCS
+
+      ICONST = 6
+      PRSS = 1.0D0
+      CONCS(1) = TCO2
+      CONCS(2) = TA
+      ICALC = 1
+      
+      CALL POLYCO(PRSS,T,S,CONCS,MCONC,AKVAL,MKVAL,ICALC,ICONST,iters)
+
+      if(iters.eq.25) then
+         ! AXY (13/05/13): this location has failed to converge; use
+         !                 some standard values to plug the hole
+         CONCS(3) = PCO2A * 1E-06 ! atmospheric value
+         CONCS(4) = 8.1           ! global average pH
+         CONCS(5) = TCO2 * 0.005  ! some "standard" values plucked
+         CONCS(6) = TCO2 * 0.865  ! from pages 5-6 of Zeebe & Wolf-
+         CONCS(7) = TCO2 * 0.130  ! Gladow (2001)
+         AKVAL(1) = 0.5E-01       ! trial-and-error value
+         IF(lwp) THEN
+            WRITE(numout,*) ' CO2DYN : reset failed outputs'
+         ENDIF
+      endif
+
+      PCO2  = CONCS(3)
+      PH    = CONCS(4)
+      ca    = CONCS(5)
+      bc    = CONCS(6)
+      cb    = CONCS(7)
+      HENRY = AKVAL(1)
+    
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE POLYCO(PD,TD,SD,CONCS,NCONC,AKVAL,NKVAL,ICALC,ICONST,iters)
+!      
+!=======================================================================
+!
+! MASTER SUBROUTINE FOR CALCULATION OF THE CO2 SYSTEM THERMODYNAMICS
+!
+! EXPLANATION OF POLYCO PARAMETERS
+!       AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+!       P - PRESSURE IN ATMOSPHERES (P<>1 CODED only for ICONST=3 and ICONST=6)
+!       T - TEMPERATURE IN DEG.C
+!       S - SALINITY IN PPT
+!      CONCS(1) - TOTAL C (MOL/KG)
+!      CONCS(2) - TOTAL ALKALINITY (MOL/KG)
+!      CONCS(3) - PCO2 (ATM)
+!      CONCS(4) - PH
+!      CONCS(5) - {H2CO3} (MOL/KG)
+!      CONCS(6) - {HCO3} (MOL/KG)
+!      CONCS(7) - {CO3} (MOL/KG)
+!        CONCS(8) - CARBONATE ALKALINITY  ) FOR ICONST = 4,5,6
+!        CONCS(9) - BORATE ALKALINITY     )       ONLY
+!         NCONC - SIZE OF CONCS ARRAY (7 FOR ICONST=1,2,3; 9 FOR ICONST
+!     AKVAL(1) - KP (HENRY'S LAW CONSTANT) (MOL/KG/ATM)
+!     AKVAL(2) - K1C (H2CO3 DISSOCIATION) (MOL/KG)
+!       AKVAL(3) - K2C (HCO3 DISSOCIATION) (MOL/KG)
+!       AKVAL(4) - KB (B(OH)3 DISSOCIATION) (MOL/KG)  FOR ICONST=4,5,6
+!        NKVAL - SIZE OF AKVAL ARRAY (3 FOR ICONST=1,2,3; 4 FOR ICONST=
+!        ICALC - SELECTION OF THE TWO INPUT PARAMETERS:
+!       ICALC = 1  TOTAL C AND ALKALINITY
+!       ICALC = 2  TOTAL C AND PCO2
+!       ICALC = 3  TOTAL C AND PH
+!       ICALC = 4  ALKALINITY AND PCO2
+!       ICALC = 5  ALKALINITY AND PH
+!       ICALC = 6  PCO2 AND PH
+!       ICALC = 7  CALCULATE CONSTANTS AKVAL ONLY
+!       ICONST - SELECTION OF PH SCALE AND COMPONENTS:
+!       ICONST = 1  NBS PH SCALE
+!       ICONST = 2  HANSSON'S SCALE (SWS WITHOUT FLUORIDE)
+!       ICONST = 3  SWS PH SCALE
+!       ICONST = 4  AS 1 BUT INCLUDING BORATE IN THE CALCULATION
+!       ICONST = 5  AS 2 BUT INCLUDING BORATE IN THE CALCULATION
+!       ICONST = 6  AS 3 BUT INCLUDING BORATE IN THE CALCULATION
+
+!  NOTE: FOR ICONST=1,2,3 CONCS(2) REPRESENTS CARBONATE ALKALINITY SINC
+!        BORATE IS NOT INCLUDED IN THE CALCULATION. FOR ICONST=4,5,6 CO
+!        REPRESENTS TOTAL ALKALINITY (CARBONATE + BORATE), THE COMPONEN
+!        WHICH ARE GIVEN IN CONCS(8) AND CONCS(9)
+
+      REAL(wp) :: PMIN, PMAX, SMIN, SMAX, TMIN, TMAX, & 
+     &     PD, TD, SD, P, T, S, BTOT
+      INTEGER  :: MINJC, MAXJC, MINJK, MAXJK, MINCAL, MAXCAL, MINCON,  &
+     &     MAXCON, NCONC, NKVAL, ICALC, ICONST, IC, iters
+      LOGICAL  :: BORON
+
+      PARAMETER(MINJC=7,MAXJC=9,MINJK=3,MAXJK=4)
+      PARAMETER(MINCAL=1,MAXCAL=7,MINCON=1,MAXCON=6)
+      !! AXY (11/08/11): TMIN changed to -2 to stop error messages in polar regions
+      !! AXY (09/01/14): TMIN changed to -3 to stop error messages in polar regions
+      !! AXY (03/03/14): SMAX changed to 42 to stop error messages in salty regions (the Great Answer ...)
+      !! AXY (05/03/14): SMAX changed to 45 to stop error messages in salty regions
+      PARAMETER(PMIN=0.99999D0,PMAX=1.00001D0,SMIN=0.0D0,  &
+     &  SMAX=45.0D0,TMIN=-3.0D0,TMAX=40.0D0)
+      REAL(wp), DIMENSION(NKVAL) :: AKVAL
+      REAL(wp), DIMENSION(NCONC) :: CONCS
+
+      P = PD
+      S = SD
+      T = TD
+      
+      !! AXY (09/08/11): STOP statements commented out and WARNING messages added
+      IF(lwp) THEN
+         IF(T.LT.TMIN.OR.T.GT.TMAX) WRITE(numout,*) ' trc_co2_medusa: T WARNING, ', T, TMIN, TMAX, S, P
+         IF(S.LT.SMIN.OR.S.GT.SMAX) WRITE(numout,*) ' trc_co2_medusa: S WARNING, ', S, SMIN, SMAX, T, P
+         IF(P.LT.PMIN.OR.P.GT.PMAX) WRITE(numout,*) ' trc_co2_medusa: P WARNING, ', P, PMIN, PMAX, T, S
+      ENDIF
+      ! IF(T.LT.TMIN.OR.T.GT.TMAX)WRITE (*,*) P, S, T, TMIN, TMAX
+      ! IF(P.LT.PMIN.OR.P.GT.PMAX) STOP'POLYCO - PRESSURE OUT OF RANGE'
+      ! IF(S.LT.SMIN.OR.S.GT.SMAX) STOP'POLYCO - SALINITY OUT OF RANGE'
+      ! IF(T.LT.TMIN.OR.T.GT.TMAX) STOP'POLYCO - TEMP. OUT OF RANGE'
+
+      !! AXY (17/04/13): iMARNET climate change simulation appears to be compromised
+      !!                 by excessive Caspian Sea salinity (> 45 PSU); this may be
+      !!                 a runoff glitch that doesn't manifest on local instance of
+      !!                 NEMO; fudging this here by replacing excessively high
+      !!                 salinity values with maximum salinity value for the purpose
+      !!                 of carbonate chemistry calculations; if this works, a more
+      !!                 sensible solution might be to kill Caspian, etc.
+      IF(lwp) THEN
+         IF(S.LT.SMIN) THEN
+            WRITE(numout,*) ' trc_co2_medusa: S RESET, ', S, '->', SMIN
+            S = SMIN
+         ENDIF
+         IF(S.GT.SMAX) THEN
+            WRITE(numout,*) ' trc_co2_medusa: S RESET, ', S, '->', SMAX
+            S = SMAX
+         ENDIF
+      ENDIF
+      
+      !! AXY (28/02/13): as above, but for T; this has been done for 1/4-degree
+      !!                 simulations to provide a temporary fix to a strange
+      !!                 glitch in ocean temperature; basically, T has been found
+      !!                 to spike upwards arbitrarily (e.g. 24C -> 53C); this 
+      !!                 causes the carbonate chemistry calculations to fail;
+      !!                 this fix aims to stop the problem so that we can estimate
+      !!                 how frequent a problem this is; it's suggestive of a
+      !!                 memory leak
+      IF(lwp) THEN
+         IF(T.LT.TMIN) THEN
+            WRITE(numout,*) ' trc_co2_medusa: T RESET, ', T, '->', TMIN
+            T = TMIN
+         ENDIF
+         IF(T.GT.TMAX) THEN
+            WRITE(numout,*) ' trc_co2_medusa: T RESET, ', T, '->', TMAX
+            T = TMAX
+         ENDIF
+      ENDIF
+     
+      IF(ICALC.LT.MINCAL.OR.ICALC.GT.MAXCAL) STOP 'POLYCO - ICALC OUT OR RANGE'
+      IF(ICONST.LT.MINCON.OR.ICONST.GT.MAXCON) STOP 'POLYCO - ICONST OUT OF RANGE'
+      BORON=(ICONST.GT.3)
+      IF(BORON) THEN
+        IC=ICONST-3
+        BTOT=0.0004128D0*S/35.0D0
+        IF(NCONC.NE.MAXJC) STOP 'POLYCO - WRONG NCONC VALUE'
+        IF(NKVAL.NE.MAXJK) STOP 'POLYCO - WRONG NKVAL VALUE'
+      ELSE
+        IC=ICONST
+        IF(NCONC.NE.MINJC) STOP 'POLYCO - WRONG NCONC VALUE'
+        IF(NKVAL.NE.MINJK) STOP 'POLYCO - WRONG NKVAL VALUE'
+      ENDIF
+
+      CALL CO2SET(P,T,S,AKVAL,NKVAL,IC)
+
+      IF(ICALC.LT.MAXCAL)  &
+     & CALL CO2CLC(CONCS,NCONC,AKVAL,NKVAL,ICALC,BORON,BTOT,iters)
+
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CO2SET(P,T,S,AKVAL,NKVAL,IC)
+!      
+!=======================================================================
+!
+! Routine to calculate CO2 system constants under the conditions set by
+! P,S,T     (NOTE: PRESSURE <> 1ATM IS NOT YET CODED)
+
+! I. Calculate constants at P=1 and S=0 using
+
+!      ln K0  =  A + B/TK + C ln TK
+!                                   (where TK is in Kelvin)
+
+! II. Calculate constants at P=1 and salinity S using
+
+!    ln K  =  ln K0 + (a0 + a1/TK + a2 ln TK) S**1/2
+!                 + (b0 + b1TK + b2TK**2) S
+
+! The sources of the coefficients are as follows:
+
+!  IC=                  1                    2                  3
+!               (NBS pH scale)        (SWS pH scale       (SWS pH scale
+!                                       with no F)
+
+!  KP            WEISS (1974)           WEISS(1974)          WEISS(1974
+
+!  K1C )      MEHRBACH ACC. TO       HANSSON ACC. TO    HANSSON AND MEH
+!  K2C )       MILLERO (1979)         MILLERO (1979)      ACC. TO DICKS
+!   KB )                                                 AND MILLERO (1
+!                                                         (K1C AND K2C
+!                                                           HANSSON ACC
+!                                                            MILLERO (1
+!                                                              (KB ONLY
+
+! ***
+!      IMPLICIT real*8 (A-H,O-Z)
+
+!     Modified by jcb 17/02/10 to use OCMIP calculations of K1, K2, Kb. 
+!     Differences are subtle rather than significant
+
+      INTEGER             :: MAXK, MAXCON, NKVAL, ICON, IC, IK
+! ***
+      PARAMETER(MAXK=4,MAXCON=3)
+      REAL(wp), DIMENSION(MAXK)        :: A, B, C
+      REAL(wp), DIMENSION(MAXK,MAXCON) :: A0, A1, A2
+      REAL(wp), DIMENSION(MAXK,MAXCON) :: B0, B1, B2
+      REAL(wp), DIMENSION(NKVAL)       :: AKVAL
+!     AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+!     REAL(wp)            :: P,T,S,VAL,TK
+      REAL(wp)            :: P,T,S,VAL,TK, delta, kappa, Rgas
+      REAL(wp)            :: dlogTK, S2, sqrtS, S15, k1, k2, kb
+! ***
+!     AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+      DATA Rgas/83.131/
+
+      DATA A/-167.8108D0, 290.9097D0, 207.6548D0, 148.0248D0/
+      DATA B/9345.17D0, -14554.21D0, -11843.79D0, -8966.9D0/
+      DATA C/23.3585D0, -45.0575D0, -33.6485D0, -24.4344D0/
+      DATA (A0(1,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (A0(2,ICON),ICON=1,MAXCON) /0.0221D0, 0.5709D0, -45.8076D0/
+      DATA (A0(3,ICON),ICON=1,MAXCON) /0.9805D0, 1.4853D0, -39.5492D0/
+      DATA (A0(4,ICON),ICON=1,MAXCON) /0.0473D0, 0.5998D0, 0.5998D0/
+      DATA (A1(1,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (A1(2,ICON),ICON=1,MAXCON) /34.02D0, -84.25D0, 1935.07D0/
+      DATA (A1(3,ICON),ICON=1,MAXCON) /-92.65D0, -192.69D0, 1590.14D0/
+      DATA (A1(4,ICON),ICON=1,MAXCON) /49.10D0, -75.25D0, -75.25D0/
+      DATA (A2(1,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (A2(2,ICON),ICON=1,MAXCON) /2*0.0D0,6.9513D0/
+      DATA (A2(3,ICON),ICON=1,MAXCON) /2*0.0D0,6.1523D0/
+      DATA (A2(4,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B0(1,ICON),ICON=1,MAXCON) /3*0.023517D0/
+      DATA (B0(2,ICON),ICON=1,MAXCON) /0.0D0,-0.01632D0,-0.01566D0/
+      DATA (B0(3,ICON),ICON=1,MAXCON) /-0.03294D0,-0.05058D0,-0.04997D0/
+      DATA (B0(4,ICON),ICON=1,MAXCON) /0.0D0, -0.01767D0, -0.01767D0/
+      DATA (B1(1,ICON),ICON=1,MAXCON) /3*-2.3656D-4/
+      DATA (B1(2,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B1(3,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B1(4,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B2(1,ICON),ICON=1,MAXCON) /3*4.7036D-7/
+      DATA (B2(2,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B2(3,ICON),ICON=1,MAXCON) /3*0.0D0/
+      DATA (B2(4,ICON),ICON=1,MAXCON) /3*0.0D0/
+
+      TK=T+273.15D0
+      DO 100 IK=1,NKVAL
+        VAL=A(IK) + B(IK)/TK + C(IK)*LOG(TK)
+        VAL=VAL + (A0(IK,IC) + A1(IK,IC)/TK + A2(IK,IC)*LOG(TK))*SQRT(S)
+        VAL=VAL + (B0(IK,IC) + B1(IK,IC)*TK + B2(IK,IC)*TK*TK)*S
+        AKVAL(IK)=EXP(VAL)
+100    CONTINUE
+
+      IF (IC .EQ. 3) THEN
+!  Calculation of constants as used in the OCMIP process for ICONST = 3 or 6
+!  see http://www.ipsl.jussieu.fr/OCMIP/
+!  added jcb 17/02/10
+
+!  Derive simple terms used more than once
+	dlogTK = log(TK)
+	S2 = S*S
+	sqrtS = sqrt(S)
+	S15 = S**1.5
+! k1 = [H][HCO3]/[H2CO3]
+! k2 = [H][CO3]/[HCO3]
+! Millero p.664 (1995) using Mehrbach et al. data on seawater scale 
+	k1=10**(-1*(3670.7/TK - 62.008 + 9.7944*dlogTK - &
+     &		0.0118 * S + 0.000116*S2))
+	k2=10**(-1*(1394.7/TK + 4.777 - &
+     &		0.0184*S + 0.000118*S2))
+! AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+! Correction for high pressure (from Millero 1995)
+! added YA 04/10/2010
+        delta=-25.5+0.1271*T
+        kappa=(-3.08+0.0877*T)/1000.0
+        k1=k1*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+        delta=-15.82-0.0219*T
+        kappa=(1.13-0.1475*T)/1000.0
+        k2=k2*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+
+! kb = [H][BO2]/[HBO2]
+! Millero p.669 (1995) using data from Dickson (1990)
+	kb=exp((-8966.90 - 2890.53*sqrtS - 77.942*S + &
+     &		1.728*S15 - 0.0996*S2)/TK + &
+     &		(148.0248 + 137.1942*sqrtS + 1.62142*S) + &
+     &		(-24.4344 - 25.085*sqrtS - 0.2474*S) * &
+     &		dlogTK + 0.053105*sqrtS*TK)
+! AXY (16/08/11): Yuri change for non-surface carbonate chemistry 
+! Correction for high pressure (from Millero, 1995)
+! added YA 04/10/2010
+        delta=-29.48+0.1622*T-0.002608*T**2.0
+        kappa=-2.84/1000.0
+        kb=kb*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+! Correction for high pressure of Kw (from Millero 1995)
+! added YA 04/10/2010
+        delta=-25.60+0.2324*T-0.0036246*T**2
+        kappa=(-5.13+0.0794*T)/1000.0
+        AKVAL(1)=AKVAL(1)*exp((-delta+0.5*kappa*P)*P/(Rgas*TK))
+
+! replace haltafall calculations with OCMIP calculations
+      AKVAL(2) = k1
+      AKVAL(3) = k2
+      AKVAL(4) = kb
+      END IF ! section implimenting OCMIP coefficients
+
+      RETURN
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CO2CLC(CONCS,NCONC,AKVAL,NKVAL,ICALC,BORON,BTOT,iters)
+!      
+!=======================================================================
+! 
+! ROUTINE TO CARRY OUT CO2 CALCULATIONS WITH 2 FIXED PARAMETERS ACCORDI
+! THE EQUATIONS GIVEN BY PARKS(1969) AND SKIRROW (1975)
+! WITH ADDITIONS FOR INCLUDING BORON IF BORON=.TRUE.
+
+
+!      IMPLICIT real*8 (A-H,O-Z)
+      INTEGER             :: NCONC, NKVAL, ICALC, II, KARL, LQ, iters
+! AXY (07/05/13) ==================================================
+! put counter in to check duration in convergence loop
+      INTEGER             :: COUNTER,C_CHECK,C_SW,III
+! AXY (07/05/13) ==================================================
+      REAL(wp)            :: CTOT,ALK,PCO2,PH,H2CO3,HCO3,CO3,ALKC
+      REAL(wp)            :: ALKB,AKP,AK1C,AK2C,AKB,BTOT
+      REAL(wp)            :: AKR,AHPLUS
+      REAL(wp)            :: PROD,tol1,tol2,tol3,tol4,steg,fak
+      REAL(wp)            :: STEGBY,Y,X,W,X1,Y1,X2,Y2,FACTOR,TERM,Z
+      REAL(wp), DIMENSION(NCONC) :: CONCS
+      REAL(wp), DIMENSION(NKVAL) :: AKVAL
+      REAL(wp), DIMENSION(9)     :: CONCS2
+      REAL(wp), DIMENSION(4)     :: AKVAL2
+
+! AXY (07/05/13) ==================================================
+! setup array to store old values of concs
+      real(wp),DIMENSION(:) :: old_CONCS(NCONC)
+! AXY (07/05/13) ==================================================
+
+      EQUIVALENCE (CTOT  , CONCS2(1)), (ALK   , CONCS2(2)),  &
+     &            (PCO2  , CONCS2(3)), (PH    , CONCS2(4)),  &
+     &            (H2CO3 , CONCS2(5)), (HCO3  , CONCS2(6)),  &
+     &            (CO3   , CONCS2(7)), (ALKC  , CONCS2(8)),  &
+     &            (ALKB  , CONCS2(9)),                       &
+     &            (AKP   , AKVAL2(1)), (AK1C  , AKVAL2(2)),  &
+     &            (AK2C  , AKVAL2(3)), (AKB   , AKVAL2(4))
+      LOGICAL             :: BORON,DONE
+
+! AXY (07/05/13) ==================================================
+!  DERIVING PH REQUIRES FOLLOWING LOOP TO CONVERGE.
+!  THIS SUBROUTINE RELIES ON CONVERGENCE.  IF THE ENVIRONMENTAL
+!  CONDITIONS DO NOT ALLOW FOR CONVERGENCE (IN 3D MODEL THIS IS
+!  LIKELY TO OCCUR NEAR LOW SALINITY REGIONS) THE MODEL WILL 
+!  BE STUCK IN THE LOOP.  TO AVOID THIS A CONVERGENCE CONDITION
+!  IS PUT IN PLACE TO SET A FLAGG OF -99 IN THE PH VAR FOR NON CONVEGENCE. 
+!  THE MODEL IS THEN ALLOWED TO CONTINUE. 'COUNTER, C_SW,C_CHECK' ARE 
+!  THE LOCAL VARS USED.
+! C_SW = condition of convergence 0=yes, 1= no
+! COUNTER = number of iterations
+! C_CHECK = maximum number of iterations
+
+! SET COUNTER AND SWITCH TO ZERO AND OFF
+      COUNTER=0
+      C_SW=0
+! FROM EXPERIENCE IF THE ITERATIONS IN THE FOLLOWING DO LOOP
+! EXCEEDS 15 CONVERGENCE WILL NOT OCCUR.  THE OVERHEAD OF 25 ITERATIONS 
+! IS OK FOR SMALL DOMAINS WITH 1/10 AND 1/15 DEG RESOLUTION.
+! I RECOMMEND A LOWER VALUE OF 15 FOR HIGHER RESOLUTION OR LARGER DOMAINS.
+      C_CHECK=25
+! AXY (07/05/13) ==================================================
+
+      DO 100 II=1,NCONC
+        CONCS2(II)=CONCS(II)
+
+! AXY (07/05/13) ==================================================
+! IF CONVERGENCE IS NOT ACHIEVED THE LOCAL ARRAY CONCS MUST BE STORED TO 
+! ALLOW THE MODEL TO CONTINUE. THEREFORE ....
+! UPDATE OLD_CONCS
+        old_CONCS(II)=CONCS(II)
+! AXY (07/05/13) ==================================================
+
+100    CONTINUE
+      DO 110 II=1,NKVAL
+        AKVAL2(II)=AKVAL(II)
+110    CONTINUE
+      AKR = AK1C/AK2C
+      AHPLUS=10.0D0**(-PH)
+      PROD=AKR*AKP*PCO2
+     
+      IF(BORON) THEN
+
+        IF(ICALC.EQ.1.OR.ICALC.EQ.4) THEN
+!         *** ALK, BTOT AND CTOT OR PCO2 FIXED ***
+!         *** ITERATIVE CALCULATION NECESSARY HERE
+
+!         SET INITIAL GUESSES AND TOLERANCE
+          H2CO3=PCO2*AKP
+          CO3=ALK/10.0D0
+          AHPLUS=1.0D-8
+          ALKB=BTOT
+          TOL1=ALK/1.0D5
+          TOL2=H2CO3/1.0D5
+          TOL3=CTOT/1.0D5
+          TOL4=BTOT/1.0D5
+
+!         HALTAFALL iteration to determine CO3, ALKB, AHPLUS
+          KARL=1
+          STEG=2.0D0
+          FAK=1.0D0
+          STEGBY=0.4D0
+10        DONE=.TRUE.
+
+! AXY (07/05/13) ==================================================
+! SET COUNTER UPDATE. FLAG 10 IS THE POINT OF RETURN FOR 
+! THE CONVERGENCE CONDITION
+          COUNTER=COUNTER+1
+	  iters  = COUNTER
+! CHECK IF CONVERGENCE HAS OCCURED IN THE NUMBER OF 
+! ACCEPTABLE ITTERATIONS.  SET C_SW TO LET MODEL KNOW
+! WHAT TO DO AT THE END OF THE SUBROUTINE
+          if(counter.ge.c_check)then
+             IF(lwp) THEN
+                WRITE(numout,*) ' CO2CLC : ITERS WARNING, ', iters
+             ENDIF
+             c_sw=1
+             GOTO 123
+          endif
+! AXY (07/05/13) ==================================================
+
+          IF(ICALC.EQ.4) THEN
+!         *** PCO2 IS FIXED ***
+            Y=AHPLUS*AHPLUS*CO3/(AK1C*AK2C)
+            IF(ABS(Y-H2CO3).GT.TOL2) THEN
+              CO3=CO3*H2CO3/Y
+              DONE=.FALSE.
+            ENDIF
+          ELSEIF(ICALC.EQ.1) THEN
+!           *** CTOT IS FIXED ***
+            Y=CO3*(1.0D0+AHPLUS/AK2C+AHPLUS*AHPLUS/(AK1C*AK2C))
+            IF(ABS(Y-CTOT).GT.TOL3) THEN
+              CO3=CO3*CTOT/Y
+              DONE=.FALSE.
+            ENDIF
+          ENDIF
+          Y=ALKB*(1.0D0+AHPLUS/AKB)
+          IF(ABS(Y-BTOT).GT.TOL4) THEN
+            ALKB=ALKB*BTOT/Y
+            DONE=.FALSE.
+          ENDIF
+
+! Alkalinity is equivalent to -(total H+), so the sign of W is opposite
+! to that normally used
+
+          Y=CO3*(2.0D0+AHPLUS/AK2C)+ALKB
+          IF(ABS(Y-ALK).GT.TOL1) THEN
+            DONE=.FALSE.
+            X=LOG(AHPLUS)
+!           W=SIGN(1.0D0,Y-ALK)
+            IF ( Y-ALK .GE. 0.0D0 ) THEN
+            W=1.0D0
+            ELSE
+            W=-1.0D0
+            ENDIF
+            IF(W.GE.0.0D0) THEN
+              X1=X
+              Y1=Y
+            ELSE
+              X2=X
+              Y2=Y
+            ENDIF
+            LQ=KARL
+            IF(LQ.EQ.1) THEN
+              KARL=2*NINT(W)
+            ELSEIF(IABS(LQ).EQ.2.AND.(LQ*W).LT.0.) THEN
+              FAK=0.5D0
+              KARL=3
+            ENDIF
+            IF(KARL.EQ.3.AND.STEG.LT.STEGBY) THEN
+              W=(X2-X1)/(Y2-Y1)
+              X=X1+W*(ALK-Y1)
+            ELSE
+              STEG=STEG*FAK
+              X=X+STEG*W
+            ENDIF
+            AHPLUS=EXP(X)  
+          ENDIF
+          IF(.NOT.DONE) GOTO 10
+          
+          HCO3=CO3*AHPLUS/AK2C
+          IF(ICALC.EQ.4) THEN
+            CTOT=H2CO3+HCO3+CO3
+          ELSEIF(ICALC.EQ.1) THEN
+            H2CO3=HCO3*AHPLUS/AK1C
+            PCO2=H2CO3/AKP
+          ENDIF
+          PH=-LOG10(AHPLUS)
+          ALKC=ALK-ALKB
+        ELSEIF(ICALC.EQ.2) THEN
+!         *** CTOT, PCO2, AND BTOT FIXED ***
+          Y=SQRT(PROD*(PROD-4.0D0*AKP*PCO2+4.0D0*CTOT))
+          H2CO3=PCO2*AKP
+          HCO3=(Y-PROD)/2.0D0
+          CO3=CTOT-H2CO3-HCO3
+          ALKC=HCO3+2.0D0*CO3
+          AHPLUS=AK1C*H2CO3/HCO3
+          PH=-LOG10(AHPLUS)
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          ALK=ALKC+ALKB
+        ELSEIF(ICALC.EQ.3) THEN
+!         *** CTOT, PH AND BTOT FIXED ***
+          FACTOR=CTOT/(AHPLUS*AHPLUS+AK1C*AHPLUS+AK1C*AK2C)
+          CO3=FACTOR*AK1C*AK2C
+          HCO3=FACTOR*AK1C*AHPLUS
+          H2CO3=FACTOR*AHPLUS*AHPLUS
+          PCO2=H2CO3/AKP
+          ALKC=HCO3+2.0D0*CO3
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          ALK=ALKC+ALKB
+        ELSEIF(ICALC.EQ.5) THEN
+!         *** ALK, PH AND BTOT FIXED ***
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          ALKC=ALK-ALKB
+          HCO3=ALKC/(1.0D0+2.0D0*AK2C/AHPLUS)
+          CO3=HCO3*AK2C/AHPLUS
+          H2CO3=HCO3*AHPLUS/AK1C
+          PCO2=H2CO3/AKP
+          CTOT=H2CO3+HCO3+CO3
+        ELSEIF(ICALC.EQ.6) THEN
+!         *** PCO2, PH AND BTOT FIXED ***
+          ALKB=BTOT/(1.0D0+AHPLUS/AKB)
+          H2CO3=PCO2*AKP
+          HCO3=H2CO3*AK1C/AHPLUS
+          CO3=HCO3*AK2C/AHPLUS
+          CTOT=H2CO3+HCO3+CO3
+          ALKC=HCO3+2.0D0*CO3
+          ALK=ALKC+ALKB
+        ENDIF
+      ELSE
+        IF(ICALC.EQ.1) THEN
+!         *** CTOT AND ALK FIXED ***
+          TERM=4.0D0*ALK+CTOT*AKR-ALK*AKR
+          Z=SQRT(TERM*TERM+4.0D0*(AKR-4.0D0)*ALK*ALK)
+          CO3=(ALK*AKR-CTOT*AKR-4.0D0*ALK+Z)/(2.0D0*(AKR-4.0D0))
+          HCO3=(CTOT*AKR-Z)/(AKR-4.0D0)
+          H2CO3=CTOT-ALK+CO3
+          PCO2=H2CO3/AKP
+          PH=-LOG10(AK1C*H2CO3/HCO3)
+        ELSEIF(ICALC.EQ.2) THEN
+!         *** CTOT AND PCO2 FIXED ***
+          Y=SQRT(PROD*(PROD-4.0D0*AKP*PCO2+4.0D0*CTOT))
+          H2CO3=PCO2*AKP
+          HCO3=(Y-PROD)/2.0D0
+          CO3=CTOT-H2CO3-HCO3
+          ALK=HCO3+2.0D0*CO3
+          PH=-LOG10(AK1C*H2CO3/HCO3)
+        ELSEIF(ICALC.EQ.3) THEN
+!         *** CTOT AND PH FIXED ***
+          FACTOR=CTOT/(AHPLUS*AHPLUS+AK1C*AHPLUS+AK1C*AK2C)
+          CO3=FACTOR*AK1C*AK2C
+          HCO3=FACTOR*AK1C*AHPLUS
+          H2CO3=FACTOR*AHPLUS*AHPLUS
+          PCO2=H2CO3/AKP
+          ALK=HCO3+2.0D0*CO3
+        ELSEIF(ICALC.EQ.4) THEN
+!         *** ALK AND PCO2 FIXED ***
+          TERM=SQRT((8.0D0*ALK+PROD)*PROD)
+          CO3=ALK/2.0D0+PROD/8.0D0-TERM/8.0D0
+          HCO3=-PROD/4.0D0+TERM/4.0D0
+          H2CO3=PCO2*AKP
+          CTOT=CO3+HCO3+H2CO3
+          PH=-LOG10(AK1C*H2CO3/HCO3)
+        ELSEIF(ICALC.EQ.5) THEN
+!         *** ALK AND PH FIXED ***
+          HCO3=ALK/(1.0D0+2.0D0*AK2C/AHPLUS)
+          CO3=HCO3*AK2C/AHPLUS
+          H2CO3=HCO3*AHPLUS/AK1C
+          PCO2=H2CO3/AKP
+          CTOT=H2CO3+HCO3+CO3
+        ELSEIF(ICALC.EQ.6) THEN
+!         *** PCO2 AND PH FIXED ***
+          H2CO3=PCO2*AKP
+          HCO3=H2CO3*AK1C/AHPLUS
+          CO3=HCO3*AK2C/AHPLUS
+          CTOT=H2CO3+HCO3+CO3
+          ALK=HCO3+2.0D0*CO3
+        ENDIF
+      ENDIF
+
+      DO 120 II=1,NCONC
+        CONCS(II)=CONCS2(II)
+120    CONTINUE
+
+! AXY (07/05/13) ==================================================
+! C_SW IS SET AT 0 TO START
+! THEN IF NON CONVERGENCE C_SW SET TO 1
+123   IF(C_SW.EQ.1)THEN
+! IF NON CONVERGENCE, THE MODEL REQUIRES CONCS TO CONTAIN USABLE VALUES.
+! BEST OFFER BEING THE OLD CONCS VALUES WHEN CONVERGENCE HAS BEEN 
+! ACHIEVED
+        DO II=1,NCONC
+           CONCS(II)=OLD_CONCS(II)
+        END DO
+
+! SPECIFIC CARBONATE VALUES TO PUSH CODE ON THROUGH THE
+! NON CONVERGENCE CONDITIONS
+! PCO2W = 0 SO CO2 UPTAKE WILL BE ENCOURAGED
+!       CONCS(3)=O3C(III)*0.005_fp8/1.e6_fp8
+! -99 IS A FLAG TO SHOW WHEN AND WHERE NON CONVERGENCE OCCURED
+! CONCS(4)=PH, OUTPUT OF -99 MEANS NON-CONVERGENCE
+!       CONCS(4)=-99._fp8
+! 
+! AXY (10/05/13): remove this -99 flag; this is handled instead up in
+!                 trcbio_medusa.F90 where the iters variable is both 
+!                 output and may be used to trigger action
+!
+! RESET SWITCH FOR NEXT CALL TO THIS SUBROUTINE
+        C_SW=0
+      ENDIF
+! AXY (07/05/13) ==================================================
+
+
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+      SUBROUTINE CaCO3_Saturation (Tc, S, D, CO3, &
+      Om_cal, Om_arg)
+!      
+!=======================================================================
+!
+! Routine to calculate the saturation state of calcite and aragonite    
+! Inputs:                                                               
+!               Tc      Temperature (C)                                 
+!               S       Salinity                                        
+!               D       Depth (m)                                       
+!               CO3     Carbonate ion concentration (mol.kg-1 ie /1D6)
+!                                                                       
+! Outputs                                                               
+!               Om_cal  Calite saturation                               
+!               Om_arg  Aragonite saturation                            
+!                                                                       
+! Intermediates                                                         
+!               K_cal   Stoichiometric solubility product for calcite   
+!               K_arg   Stoichiometric solubility product for aragonite 
+!               Ca      Calcium 2+ concentration (mol.kg-1) 
+!               P       Pressure (bars)
+!                                                                       
+! Source                                                                
+!       Zeebe & Wolf-Gladrow 2001 following Mucci (1983)                
+!       with pressure corrections from Millero (1995)                   
+!       Code tested against reference values given in Z & W-G
+!       Built Jerry Blackford, 2008
+!=======================================================================
+
+        IMPLICIT None
+        REAL(wp), INTENT( in )    :: Tc, S, D, CO3
+        REAL(wp), INTENT( inout ) :: Om_cal, Om_arg
+        REAL(wp) :: Tk, Kelvin, Ca
+        REAL(wp) :: logKspc, Kspc
+        REAL(wp) :: logKspa, Kspa
+        REAL(wp) :: tmp1, tmp2, tmp3
+        REAL(wp) :: dV, dK, P, R
+               
+! setup
+        Kelvin = 273.15
+        Tk = Tc + Kelvin 
+        Ca = 0.01028    ! Currently oceanic mean value at S=25, needs refining)
+        Ca = 0.010279 * (S / 35.0)  ! Ca varies with salinity (cf. Feeley et al., 2004; Yool et al., 2010)
+        R = 83.131      !(cm3.bar.mol-1.K-1)
+        P = D / 10.0    !pressure in bars
+
+! calculate K for calcite
+        tmp1 = -171.9065 - (0.077993*Tk) + (2839.319/Tk) + 71.595*log10(Tk) 
+        tmp2 = + (-0.77712 + (0.0028426*Tk) + (178.34/Tk))*SQRT(S) 
+        tmp3 = - (0.07711*S) + (0.0041249*(S**1.5))
+        logKspc = tmp1 + tmp2 + tmp3
+        Kspc = 10.0**logKspc
+      
+! correction for pressure for calcite
+        IF ( D .GT. 0) THEN
+          dV = -48.76 + 0.5304*Tc
+          dK = -11.76/1.0D3 + (0.3692/1.0D3) * Tc
+          tmp1 = -(dV/(R*Tk))*P + (0.5*dK/(R*Tk))*P*P
+          Kspc = Kspc*exp(tmp1)
+          logKspc = log10(Kspc)
+        END IF
+        
+! calculate K for aragonite
+        tmp1 = -171.945 - 0.077993*Tk + 2903.293 / Tk + 71.595* log10(Tk)
+        tmp2 = + (-0.068393 + 0.0017276*Tk + 88.135/Tk)*SQRT(S)    
+        tmp3 = - 0.10018*S + 0.0059415*S**1.5
+        logKspa = tmp1 + tmp2 + tmp3
+        Kspa = 10.0**logKspa
+     
+! correction for pressure for aragonite
+        IF ( D .GT. 0) THEN
+          dV = -46.00 + 0.5304*Tc
+          dK = -11.76/1.0D3 + (0.3692/1.0D3) * Tc
+          tmp1 = -(dV/(R*Tk))*P + (0.5*dK/(R*Tk))*P*P
+          Kspa = Kspa*exp(tmp1)
+          logKspa = log10(Kspa)
+        END IF
+        
+! calculate saturation states
+        Om_cal = (CO3 * Ca) / Kspc
+        Om_arg = (CO3 * Ca) / Kspa
+      
+      RETURN
+
+      END SUBROUTINE
+!-----------------------------------------------------------------------
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#  else
+   !!======================================================================
+   !!  Dummy module :                         No MEDUSA carbonate chemistry
+   !!======================================================================
+
+CONTAINS
+
+   SUBROUTINE trc_co2_medusa( kt )                   ! Empty routine
+
+      INTEGER, INTENT( in ) ::   kt
+
+      WRITE(*,*) 'trc_co2_medusa: You should not have seen this print! error?', kt
+
+   END SUBROUTINE trc_co2_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcco2_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcctl_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcctl_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcctl_medusa.F90	(revision 7693)
@@ -0,0 +1,83 @@
+MODULE trcctl_medusa
+   !!======================================================================
+   !!                         ***  trcctl_medusa.F90  ***
+   !! TOP :                Control of MEDUSA_TRC biogeochemical model
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !! History :   1.0  !  2000-12 (C. Ethe) assign a parameter to name individual tracers
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!----------------------------------------------------------------------
+
+#if defined key_medusa
+
+   USE oce_trc
+   USE trc
+   USE in_out_manager
+   USE par_medusa
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_ctl_medusa     ! called by ???
+
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ctl_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_ctl_medusa  ***
+      !!
+      !! ** Purpose :   control the cpp options, namelist and files 
+      !!----------------------------------------------------------------------
+
+!      IF(lwp) WRITE(numout,*)
+!      IF(lwp) WRITE(numout,*) 'use MEDUSA biological model  '
+
+! Check number of tracers
+! -----------------------
+# if defined key_roam
+      IF (jp_medusa /= 15) THEN 
+          IF (lwp) THEN 
+              WRITE (numout,*) ' ===>>>> : W A R N I N G '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                             &
+              &   ' STOP, change jp_medusa to 15 in '      &
+              &  ,' par_medusa.F90 '  
+          END IF 
+          STOP 'TRC_CTL'
+      END IF 
+# else
+      IF (jp_medusa /= 11) THEN 
+          IF (lwp) THEN 
+              WRITE (numout,*) ' ===>>>> : W A R N I N G '
+              WRITE (numout,*) ' =======   ============= '
+              WRITE (numout,*)                             &
+              &   ' STOP, change jp_medusa to 11 in '      &
+              &  ,' par_medusa.F90 '  
+          END IF 
+          STOP 'TRC_CTL'
+      END IF 
+# endif
+
+   END SUBROUTINE trc_ctl_medusa
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Empty module :                                            No MEDUSA
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ctl_medusa               ! Dummy routine
+   END SUBROUTINE trc_ctl_medusa
+#endif
+
+   !!======================================================================
+END MODULE trcctl_medusa
+      
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90	(revision 7693)
@@ -0,0 +1,180 @@
+MODULE trcdms_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcdms_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2014-08  (J. Palmiéri - A. Yool)    added for UKESM1 project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA DMS surface concentration
+   !!----------------------------------------------------------------------
+   !!   trc_dms_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+      USE in_out_manager  ! I/O manager
+
+      IMPLICIT NONE
+      PRIVATE
+
+      PUBLIC   trc_dms_medusa    ! called in trc_bio_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+
+CONTAINS
+
+!=======================================================================
+!
+   SUBROUTINE trc_dms_medusa( chn, chd, mld, xqsr, xdin,   &  !! inputs
+     &  dms_andr, dms_simo, dms_aran, dms_hall )              !! outputs
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates DMS ocean surface concentration
+      !! Author : Julien Palmiéri and Andrew Yool
+      !! Date   : 08/08/14 
+      !!
+      !! DMS module is called in trc_bio's huge jk,jj,ji loop
+      !! --> DMS concentration is calculated in a specific cell 
+      !! (no need of ji,jj,jk)
+      !!
+      !! AXY (13/03/15): amend to include all four schemes tested
+      !!                 during winter/spring 2015; these are:
+      !!
+      !!                 1. Anderson et al. (2001); this uses fields
+      !!                    of surface chl, irradiance and nutrients
+      !!                    to empirically estimate DMS via a broken
+      !!                    stick approach
+      !!
+      !!                 2. Simo & Dachs (2002); this uses fields of
+      !!                    surface chl and mixed layer depth
+      !!
+      !!                 3. Aranami & Tsunogai (2004); this is an
+      !!                    embellishment of Simo & Dachs
+      !!
+      !!                 4. Halloran et al. (2010); this is an
+      !!                    alternative embellishment of Sim & Dachs
+      !!                    and is included because it is formally
+      !!                    published (and different from the above)
+      !!
+      !! AXY (08/07/15): amend to remove Julien's original calculation
+      !!                 as this is now superfluous; the four schemes 
+      !!                 are calculated and one is chosen to be passed
+      !!                 to the atmosphere in trc_bio_medusa
+      !!
+!=======================================================================
+
+      IMPLICIT NONE
+!
+      REAL(wp), INTENT( in )    :: chn                  !! non-diatom chlorophyll    (mg/m3)
+      REAL(wp), INTENT( in )    :: chd                  !! diatom chlorophyll        (mg/m3)
+      REAL(wp), INTENT( in )    :: mld                  !! mix layer depth           (m)
+      REAL(wp), INTENT( in )    :: xqsr                 !! surface irradiance        (W/m2)
+      REAL(wp), INTENT( in )    :: xdin                 !! surface DIN               (mmol N/m3)
+      REAL(wp), INTENT( inout ) :: dms_andr             !! DMS surface concentration (nmol/L) 
+      REAL(wp), INTENT( inout ) :: dms_simo             !! DMS surface concentration (nmol/L) 
+      REAL(wp), INTENT( inout ) :: dms_aran             !! DMS surface concentration (nmol/L) 
+      REAL(wp), INTENT( inout ) :: dms_hall             !! DMS surface concentration (nmol/L) 
+!
+      REAL(wp) :: CHL, cmr, sw_dms
+      REAL(wp) :: Jterm, Qterm
+      !! temporary variables
+      REAL(wp) ::    fq1,fq2,fq3
+! 
+!=======================================================================
+!
+! AXY (13/03/15): per remarks above, the following calculations estimate
+!                 DMS using all of the schemes examined for UKESM1
+!
+      CHL = 0.0
+      CHL = chn+chd                                 !! mg/m3 
+      cmr = CHL / mld
+!
+! AXY (13/03/15): Anderson et al. (2001)
+        Jterm = xqsr + 1.0e-6
+        !! this next line makes a hard-coded assumption about the 
+        !! half-saturation constant of MEDUSA (which should be
+        !! done properly; perhaps even scaled with the proportion
+        !! of diatoms and non-diatoms)
+        Qterm = xdin / (xdin + 0.5)
+        fq1 = log10(CHL * Jterm * Qterm)
+        if (fq1 > 1.72) then
+           dms_andr = (8.24 * (fq1 - 1.72)) + 2.29
+        else
+           dms_andr = 2.29
+        endif
+!
+! AXY (13/03/15): Simo & Dachs (2002)
+        fq1 = (-1 * log(mld)) + 5.7
+        fq2 = (55.8 * cmr) + 0.6
+        if (cmr < 0.02) then
+           dms_simo = fq1
+        else
+           dms_simo = fq2
+        endif
+!           
+! AXY (13/03/15): Aranami & Tsunogai (2004)
+        fq1 = 60.0 / mld
+        fq2 = (55.8 * cmr) + 0.6
+        if (cmr < 0.02) then
+           dms_aran = fq1
+        else
+           dms_aran = fq2
+        endif
+!        
+! AXY (13/03/15): Halloran et al. (2010)
+        fq1 = (-1 * log(mld)) + 5.7
+        fq2 = (55.8 * cmr) + 0.6
+        fq3 = (90.0 / mld)
+        if (cmr < 0.02) then
+           dms_hall = fq1
+        else
+           dms_hall = fq2
+        endif
+        if (mld > 182.5) then
+           dms_hall = fq3
+        endif
+
+  END SUBROUTINE trc_dms_medusa
+
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+
+CONTAINS
+
+!=======================================================================
+!
+   SUBROUTINE trc_dms_medusa( kt )                                        !! EMPTY Routine
+!      
+!
+      INTEGER, INTENT( in ) ::   kt
+!
+
+      WRITE(*,*) 'trc_dms_medusa: You should not have seen this print! error?'
+
+   END SUBROUTINE trc_dms_medusa
+#endif
+
+   !!======================================================================
+END MODULE  trcdms_medusa
+
+
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 7693)
@@ -0,0 +1,490 @@
+MODULE trcini_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcini_medusa  ***
+   !! TOP :   initialisation of the MEDUSA tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                         MEDUSA tracers
+   !!----------------------------------------------------------------------
+   !! trc_ini_medusa   : MEDUSA model initialisation
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE oce_trc
+   USE trc
+   USE in_out_manager
+   !! AXY (04/11/13): add this in for initialisation stuff
+   USE iom
+   USE par_medusa
+   !! AXY (13/01/12): add this in for sediment variables
+   USE sms_medusa
+   !! AXY (04/11/13): add this in for initialisation stuff
+   USE trcsed_medusa
+   USE sbc_oce, ONLY: lk_oasis
+   USE oce,     ONLY: CO2Flux_out_cpl, DMS_out_cpl  !! Coupling variable
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_ini_medusa   ! called by trcini.F90 module
+
+   !! AXY (25/02/10)
+   LOGICAL, PUBLIC ::                  &
+      bocalccd = .TRUE.
+   !! JPALM (14/09/15)
+   LOGICAL, PUBLIC ::                  &
+      ln_ccd = .TRUE.
+
+   INTEGER ::                          &
+      numccd
+
+   !! AXY (25/02/10)
+   INTEGER ::                          &
+      numriv
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_ini_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_ini_medusa  ***  
+      !!
+      !! ** Purpose :   initialization for MEDUSA model
+      !!
+      !! ** Method  : - Read the namcfc namelist and check the parameter values
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+      !! vertical array index
+      INTEGER  ::    jk, ierr
+      !! AXY (19/07/12): added jk2 to set up friver_dep array
+      INTEGER            :: jk2
+      !! AXY (19/07/12): added tfthk to set up friver_dep array
+      REAL(wp)           :: fthk, tfthk
+      !! AXY (04/11/13): add in temporary variables for checks
+      REAL(wp)           :: fq0, fq1, fq2
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialisation of MEDUSA model'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+# if defined key_debug_medusa
+            CALL flush(numout)
+# endif
+
+                                           ! Allocate MEDUSA arrays
+      ierr =         sms_medusa_alloc()
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) '------------------------------'
+            IF (lwp) write (numout,*) 'Jpalm - debug'
+            IF (lwp) write (numout,*) 'in trc_ini_medusa, just after array allocate'
+            IF (lwp) write (numout,*) ' '
+            CALL flush(numout)
+# endif
+
+!!
+!! AXY (19/07/12): setup array to control distribution of river nutrients
+      friver_dep(:,:) = 0.
+      DO jk = 1,jpk
+         tfthk = 0.
+         DO jk2 = 1,jriver_dep
+            fthk  = e3t_1d(jk2)
+            if (jk2 .le. jk) then
+               tfthk = tfthk + fthk
+               friver_dep(jk2,jk) = fthk
+            endif
+         ENDDO
+         DO jk2 = 1,jriver_dep
+            friver_dep(jk2,jk) = friver_dep(jk2,jk) / tfthk
+         ENDDO
+      ENDDO
+!!
+!! Have a look at the result of this for a single depth (jriver_dep + 1)
+      IF(lwp) THEN
+          WRITE(numout,*) '=== River nutrient fraction by depth (for a water column of jpk depth)'
+          DO jk = 1,jpk
+             WRITE(numout,*)     &
+             &   ' cell = ', jk, ', friver_dep value = ', friver_dep(jk,jpk)
+          ENDDO
+          IF(lwp) CALL flush(numout)
+       ENDIF
+
+#if defined key_roam
+!! ROAM 3D and 2D carbonate system fields (calculated on first time
+!! step, then monthly)
+      f3_pH(:,:,:)    = 0.
+      f3_h2co3(:,:,:) = 0.
+      f3_hco3(:,:,:)  = 0.
+      f3_co3(:,:,:)   = 0.
+      f3_omcal(:,:,:) = 0.
+      f3_omarg(:,:,:) = 0.
+!!
+      f2_ccd_cal(:,:) = 0.
+      f2_ccd_arg(:,:) = 0.
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: carbonate fields initialised to zero'
+#endif
+      IF(lwp) CALL flush(numout)
+
+      !!----------------------------------------------------------------------
+      !! State variable initial conditions (all mmol / m3)
+      !!----------------------------------------------------------------------
+      !!     
+      !! biological and detrital components are initialised to nominal
+      !! values above 100 m depth and zero below; the latter condition
+      !! is applied since non-linear loss processes allow significant
+      !! concentrations of these components to persist at depth
+      !!
+      trn(:,:,:,jpchn) = 0.
+      trn(:,:,:,jpchd) = 0.
+      trn(:,:,:,jpphn) = 0.
+      trn(:,:,:,jpphd) = 0.
+      trn(:,:,:,jppds) = 0.
+      trn(:,:,:,jpzmi) = 0.
+      trn(:,:,:,jpzme) = 0.
+      trn(:,:,:,jpdet) = 0.
+      !!
+      DO jk = 1,13
+         !! non-diatom chlorophyll         (nominal)
+         trn(:,:,jk,jpchn) = 0.01
+         !!
+         !! diatom chlorophyll             (nominal)
+         trn(:,:,jk,jpchd) = 0.01
+         !!
+         !! non-diatom                     (nominal)
+         trn(:,:,jk,jpphn) = 0.01
+         !!
+         !! diatom                         (nominal)
+         trn(:,:,jk,jpphd) = 0.01
+         !!
+         !! diatom silicon                 (nominal)
+         trn(:,:,jk,jppds) = 0.01
+         !!
+         !! microzooplankton               (nominal)
+         trn(:,:,jk,jpzmi) = 0.01
+         !!
+         !! mesozooplankton                (nominal)
+         trn(:,:,jk,jpzme) = 0.01
+         !!
+         !! detrital nitrogen              (nominal)
+         trn(:,:,jk,jpdet) = 0.01
+      ENDDO
+      !!
+      !! dissolved inorganic nitrogen     (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpdin) = 30.
+      !!
+      !! dissolved silicic acid           (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpsil) = 90.
+      !!
+      !! dissolved "total" iron           (nominal; typically initialised from model-derived climatology)
+      trn(:,:,:,jpfer) = 1.0e-4           !! = 0.1 umol Fe / m3
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: MEDUSA-1 fields initialised to defaults'
+# if defined key_roam
+      !!
+      !! detrital carbon                  (nominal)
+      trn(:,:,:,jpdtc) = 0.
+      DO jk = 1,13
+         trn(:,:,jk,jpdtc) = 0.06625
+      ENDDO
+      !!
+      !! dissolved inorganic carbon (DIC) (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpdic) = 2330.
+      !!
+      !! total alkalinity                 (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpalk) = 2450.
+      !!
+      !! dissolved oxygen                 (nominal average value; typically initialised from climatology)
+      trn(:,:,:,jpoxy) = 175.
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: MEDUSA-2 fields initialised to defaults'
+# endif
+      IF(lwp) CALL flush(numout)
+
+      !!----------------------------------------------------------------------
+      !! Sediment pools initial conditions (all mmol / m2)
+      !!----------------------------------------------------------------------
+      !!     
+      !! these pools store biogenic material that has sunk to the seabed,
+      !! and act as a temporary reservoir
+      zb_sed_n(:,:)  = 0.0  !! organic N
+      zn_sed_n(:,:)  = 0.0
+      za_sed_n(:,:)  = 0.0
+      zb_sed_fe(:,:) = 0.0  !! organic Fe
+      zn_sed_fe(:,:) = 0.0
+      za_sed_fe(:,:) = 0.0
+      zb_sed_si(:,:) = 0.0  !! inorganic Si
+      zn_sed_si(:,:) = 0.0
+      za_sed_si(:,:) = 0.0
+      zb_sed_c(:,:)  = 0.0  !! organic C
+      zn_sed_c(:,:)  = 0.0
+      za_sed_c(:,:)  = 0.0
+      zb_sed_ca(:,:) = 0.0  !! inorganic C
+      zn_sed_ca(:,:) = 0.0
+      za_sed_ca(:,:) = 0.0
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: benthic fields initialised to zero'
+      IF(lwp) CALL flush(numout)
+     
+      !!----------------------------------------------------------------------
+      !! Averaged properties for DMS calculations (various units)
+      !!----------------------------------------------------------------------
+      !!     
+      !! these store temporally averaged properties for DMS calculations (AXY, 07/07/15)
+      zb_dms_chn(:,:)  = 0.0  !! CHN
+      zn_dms_chn(:,:)  = 0.0
+      za_dms_chn(:,:)  = 0.0
+      zb_dms_chd(:,:)  = 0.0  !! CHD
+      zn_dms_chd(:,:)  = 0.0
+      za_dms_chd(:,:)  = 0.0
+      zb_dms_mld(:,:)  = 0.0  !! MLD
+      zn_dms_mld(:,:)  = 0.0
+      za_dms_mld(:,:)  = 0.0
+      zb_dms_qsr(:,:)  = 0.0  !! QSR
+      zn_dms_qsr(:,:)  = 0.0
+      za_dms_qsr(:,:)  = 0.0
+      zb_dms_din(:,:)  = 0.0  !! DIN
+      zn_dms_din(:,:)  = 0.0
+      za_dms_din(:,:)  = 0.0
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: average fields for DMS initialised to zero'
+      IF(lwp) CALL flush(numout)
+      !!
+      !!---------------------------------------------------------------------
+      !!JPALM (14-06-2016): init dms and co2 flux for coupling with atm (UKESM)
+      !!---------------------------------------------------------------------
+      !!
+      zb_co2_flx(:,:)  = 0.0  !! CHN
+      zn_co2_flx(:,:)  = 0.0
+      za_co2_flx(:,:)  = 0.0
+      zb_dms_srf(:,:)  = 0.0  !! CHD
+      zn_dms_srf(:,:)  = 0.0
+      za_dms_srf(:,:)  = 0.0
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: DMS and CO2 flux (UKESM) initialised to zero'
+      IF(lwp) CALL flush(numout)
+      IF (lk_oasis) THEN
+         CO2Flux_out_cpl(:,:) =  zn_co2_flx(:,:)   !! Coupling variable
+         DMS_out_cpl(:,:)     =  zn_dms_srf(:,:)   !! Coupling variable
+      END IF
+      !!
+      !!----------------------------------------------------------------------
+      !! AXY (04/11/13): initialise fields previously done by trc_sed_medusa
+      !!----------------------------------------------------------------------
+      !!     
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialising dust deposition fields'
+      CALL trc_sed_medusa_sbc( nit000 )
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialising ocean CCD array'
+      CALL trc_ini_medusa_ccd( nit000 )
+      fq0 = MINVAL(ocal_ccd(:,:))
+      fq1 = MAXVAL(ocal_ccd(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'CCD: min ', fq0, ' max ', fq1
+      !!
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: initialising riverine nutrient arrays'
+      riv_n(:,:)   = 0.0
+      riv_si(:,:)  = 0.0
+      riv_c(:,:)   = 0.0
+      riv_alk(:,:) = 0.0 
+      !!
+      CALL trc_ini_medusa_river( nit000 )
+      fq0 = MINVAL(riv_n(:,:))
+      fq1 = MAXVAL(riv_n(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_N:   min ', fq0, ' max ', fq1
+      fq0 = MINVAL(riv_si(:,:))
+      fq1 = MAXVAL(riv_si(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_SI:  min ', fq0, ' max ', fq1
+      fq0 = MINVAL(riv_c(:,:))
+      fq1 = MAXVAL(riv_c(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_C:   min ', fq0, ' max ', fq1
+      fq0 = MINVAL(riv_alk(:,:))
+      fq1 = MAXVAL(riv_alk(:,:))
+      if (lwp) write (numout,'(a,f10.3,a,f10.3)') & 
+         & 'RIV_ALK: min ', fq0, ' max ', fq1
+      IF(lwp) CALL flush(numout)
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_ini_medusa: MEDUSA initialised'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      IF(lwp) CALL flush(numout)
+
+   END SUBROUTINE trc_ini_medusa
+
+   !! ======================================================================
+   !! ======================================================================
+   !! ======================================================================
+
+   !! AXY (25/02/10)
+   SUBROUTINE trc_ini_medusa_ccd(kt)
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ini_medusa_ccd  ***
+      !!
+      !! ** Purpose :   Read CCD field
+      !!
+      !! ** Method  :   Read the file
+      !!
+      !! ** input   :   external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !!---------------------------------------------------------------------
+
+      !! Open the file
+      !! -------------
+      !!
+      !!!! JPALM -- 14-09-2015 -- 
+      !!!!       -- to test on ORCA2 with Christian, no file available, so initiate to 0 
+      IF (ln_ccd) THEN
+         IF(lwp) WRITE(numout,*) ' '
+         IF(lwp) WRITE(numout,*) ' **** Routine trc_ini_medusa_ccd'
+         CALL iom_open ( 'ccd_ocal_nemo.nc', numccd )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_ccd: ccd_ocal_nemo.nc opened'
+
+      !! Read the data
+      !! -------------
+      !!
+         CALL iom_get ( numccd, jpdom_data, 'OCAL_CCD', ocal_ccd )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_ccd: data read'
+
+      !! Close the file
+      !! --------------
+      !!
+         CALL iom_close ( numccd )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_ccd: ccd_ocal_nemo.nc closed'
+         IF(lwp) CALL flush(numout)
+      ELSE
+         IF(lwp) WRITE(numout,*) ' '
+         IF(lwp) WRITE(numout,*) ' **** Routine trc_ini_medusa_ccd'
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_ccd: do not read ccd_ocal_nemo.nc'
+         IF(lwp) WRITE(numout,*) ' **** ln_ccd = FALSE and ocal_ccd = 0.0 ---'
+         ocal_ccd(:,:) = 0.0  
+      ENDIF
+ 
+   END SUBROUTINE trc_ini_medusa_ccd
+
+   !! ======================================================================
+   !! ======================================================================
+   !! ======================================================================
+
+   !! AXY (26/01/12)
+   SUBROUTINE trc_ini_medusa_river(kt)
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_ini_medusa_river  ***
+      !!
+      !! ** Purpose :   Read riverine nutrient fields
+      !!
+      !! ** Method  :   Read the file
+      !!
+      !! ** input   :   external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+
+      !!---------------------------------------------------------------------
+
+      IF(lwp) THEN
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' **** Routine trc_ini_medusa_river'
+         WRITE(numout,*) ' '
+      ENDIF
+
+      !! Open and read the files
+      !! -----------------------
+      !!
+      if (jriver_n.gt.0) then
+         if (jriver_n.eq.1) CALL iom_open ( 'river_N_conc_orca100.nc', numriv )
+         if (jriver_n.eq.2) CALL iom_open ( 'river_N_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_N', riv_n )
+         IF(lwp) THEN
+            if (jriver_n.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: N CONC data read'
+            if (jriver_n.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: N FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river N file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: N data NOT read'
+         ENDIF
+      endif
+      !!
+      if (jriver_si.gt.0) then
+         if (jriver_si.eq.1) CALL iom_open ( 'river_Si_conc_orca100.nc', numriv )
+         if (jriver_si.eq.2) CALL iom_open ( 'river_Si_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_SI', riv_si )
+         IF(lwp) THEN
+            if (jriver_si.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: Si CONC data read'
+            if (jriver_si.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: Si FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river Si file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: Si data NOT read'
+         ENDIF
+      endif
+      !!
+      if (jriver_c.gt.0) then
+         if (jriver_c.eq.1) CALL iom_open ( 'river_C_conc_orca100.nc', numriv )
+         if (jriver_c.eq.2) CALL iom_open ( 'river_C_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_C', riv_c )
+         IF(lwp) THEN
+            if (jriver_c.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: C CONC data read'
+            if (jriver_c.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: C FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river C file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: C data NOT read'
+         ENDIF
+      endif
+      !!
+      if (jriver_alk.gt.0) then
+         if (jriver_alk.eq.1) CALL iom_open ( 'river_alk_conc_orca100.nc', numriv )
+         if (jriver_alk.eq.2) CALL iom_open ( 'river_alk_flux_orca100.nc', numriv )
+         CALL iom_get  ( numriv, jpdom_data, 'RIV_ALK', riv_alk )
+         IF(lwp) THEN
+            if (jriver_alk.eq.1) WRITE(numout,*) ' **** trc_ini_medusa_river: alkalinity CONC data read'
+            if (jriver_alk.eq.2) WRITE(numout,*) ' **** trc_ini_medusa_river: alkalinity FLUX data read'
+         ENDIF
+         CALL iom_close ( numriv )
+         IF(lwp) WRITE(numout,*) ' **** trc_ini_medusa_river: river alkalinity file closed'
+      else
+         IF(lwp) THEN
+            WRITE(numout,*) ' **** trc_ini_medusa_river: alkalinity data NOT read'
+         ENDIF
+      endif
+      IF(lwp) CALL flush(numout)
+
+   END SUBROUTINE trc_ini_medusa_river
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No MEDUSA model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_ini_medusa             ! Empty routine
+   END SUBROUTINE trc_ini_medusa
+#endif
+
+   !!======================================================================
+END MODULE trcini_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90	(revision 7693)
@@ -0,0 +1,2442 @@
+MODULE trcnam_medusa
+   !!======================================================================
+   !!                      ***  MODULE trcnam_medusa  ***
+   !! TOP :   initialisation of some run parameters for MEDUSA bio-model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!              -   !  2013-05  (A. Yool) renamed (from trclsm) for v3.5
+   !!              -   !  2015-11  (J. Palmieri) added iom_use for diags
+   !!              -   !  2016-11  (A. Yool) updated diags for CMIP6
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'   :                                       MEDUSA model
+   !!----------------------------------------------------------------------
+   !! trc_nam_medusa      : MEDUSA model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms_medusa      ! sms trends
+   USE iom             ! I/O manager
+   !!USE trc_nam_dia     ! JPALM 13-11-2015 -- if iom_use for diag
+
+   !! AXY (04/02/14): necessary to find NaNs on HECTOR
+   USE, INTRINSIC :: ieee_arithmetic 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_nam_medusa       ! called by trcnam.F90 module
+   PUBLIC   trc_nam_iom_medusa   ! called by trcnam.F90 module
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nam_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_nam_medusa  ***  
+      !!
+      !! ** Purpose :   read MEDUSA namelist
+      !!
+      !! ** input   :   file 'namelist.trc.sms' containing the following
+      !!             namelist: natbio, natopt, and natdbi ("key_trc_diabio")
+      !!
+      !! ekp: namelist nabio contains ALL parameters of the ecosystem 
+      !!      point sourses and sinks PLUS sediment exchange
+      !!      dia_bio - used by Lobster to output all point terms 
+      !!                (sourses and sinks of bio)
+      !!      dia_add - additional diagnostics for biology such as 
+      !!                primary production (2d depth integrated field or 3d)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER            :: ji,jj,jk
+      REAL(wp)           :: fthk, fdep, fdep1
+      REAL(wp)           :: q1, q2, q3
+      !
+      NAMELIST/natbio/ xxi,xaln,xald,jphy,xvpn,xvpd,          &
+      &    xsin0,xnsi0,xuif,jliebig, jq10,                    &
+      &    xthetam,xthetamd,xnln,xnld,xsld,xfln,xfld,         &
+      &  xgmi,xgme,xkmi,xkme,xphi,xbetan,xbetac,xkc,          &
+      &    xpmipn,xpmid,xpmepn,xpmepd,xpmezmi,xpmed,          &
+      &  xmetapn,xmetapd,xmetazmi,xmetazme,                   &
+      &  jmpn,xmpn,xkphn,jmpd,xmpd,xkphd,jmzmi,xmzmi,xkzmi,   &
+      &    jmzme,xmzme,xkzme,jmd,jsfd,xmd,xmdc,               &
+      &  xthetapn,xthetapd,xthetazmi,xthetazme,xthetad,       &
+      &    xrfn,xrsn,vsed,xhr,                                &
+      &  jiron,xfe_mass,xfe_sol,xfe_sed,xLgT,xk_FeL,xk_sc_Fe, &
+      &  jexport,jfdfate,jrratio,jocalccd,xridg_r0,           &
+      &    xfdfrac1,xfdfrac2,xfdfrac3,                        &
+      &    xcaco3a,xcaco3b,xmassc,xmassca,xmasssi,xprotca,    &
+      &    xprotsi,xfastc,xfastca,xfastsi,                    &
+      &  jorgben,jinorgben,xsedn,xsedfe,xsedsi,xsedc,xsedca,  &
+      &    xburial,                                           &
+      &  jriver_n,jriver_si,jriver_c,jriver_alk,jriver_dep,   &
+      &    friver_dep,                                        &
+      &  xsdiss,                                              &
+      &  vsed,xhr,                                            &
+      &  sedlam,sedlostpoc,jpkb,jdms,jdms_input,jdms_model
+#if defined key_roam
+      NAMELIST/natroam/ xthetaphy,xthetazoo,xthetanit,        &
+      &    xthetarem,xo2min,                                  &
+      &    f3_pH,f3_h2co3,f3_hco3,f3_co3,f3_omcal,f3_omarg,   &
+      &    f2_ccd_cal,f2_ccd_arg
+#endif
+      NAMELIST/natopt/xkg0,xkr0,xkgp,xkrp,xlg,xlr,rpig
+      INTEGER :: jl, jn
+      INTEGER :: ios                 ! Local integer output status for namelist read
+      TYPE(DIAG), DIMENSION(jp_medusa_2d)  :: meddia2d
+      TYPE(DIAG), DIMENSION(jp_medusa_3d)  :: meddia3d
+      TYPE(DIAG), DIMENSION(jp_medusa_trd) :: meddiabio
+      CHARACTER(LEN=32)   ::   clname
+      !!
+      NAMELIST/nammeddia/ meddia3d, meddia2d     ! additional diagnostics
+
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      clname = 'namelist_medusa'
+      IF(lwp) WRITE(numout,*) ' trc_nam_medusa: read MEDUSA namelist'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+
+
+      CALL ctl_opn( numnatp_ref, TRIM( clname )//'_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      CALL ctl_opn( numnatp_cfg, TRIM( clname )//'_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+      IF(lwm) CALL ctl_opn( numonp     , 'output.namelist.pis' , 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'open namelist_medusa -- OK'
+      IF (lwp) write (numout,*) 'Now, read namilists inside :'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+      !
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Just before reading namelist_medusa :: nammeddia'
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+
+     IF( ( .NOT.lk_iomput .AND. ln_diatrc ) .OR. ( ln_diatrc .AND. lk_medusa ) ) THEN
+         !
+         ! Namelist nammeddia
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist nammeddia in reference namelist : MEDUSA diagnostics
+         READ  ( numnatp_ref, nammeddia, IOSTAT = ios, ERR = 901)
+901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist nammeddia in configuration namelist : MEDUSA diagnostics
+         READ  ( numnatp_cfg, nammeddia, IOSTAT = ios, ERR = 902 )
+902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, nammeddia )
+
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) 'reading namelist_medusa :: nammeddia OK'
+         IF (lwp) write (numout,*) 'Check number of variable in nammeddia:'
+         IF (lwp) write (numout,*) 'jp_medusa_2d: ',jp_medusa_2d ,'jp_medusa_3d: ',jp_medusa_3d
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+         DO jl = 1, jp_medusa_2d
+            jn = jp_msa0_2d + jl - 1
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) 'Check what is readden in nammeddia: -- 2D'
+            IF (lwp) write (numout,*) jl,'meddia2d-sname: ',meddia2d(jl)%sname 
+            IF (lwp) write (numout,*) jl,'meddia2d-lname: ',meddia2d(jl)%lname 
+            IF (lwp) write (numout,*) jl,'meddia2d-units: ',meddia2d(jl)%units 
+            CALL flush(numout)
+# endif
+            ctrc2d(jn) = meddia2d(jl)%sname
+            ctrc2l(jn) = meddia2d(jl)%lname
+            ctrc2u(jn) = meddia2d(jl)%units
+         END DO
+
+         DO jl = 1, jp_medusa_3d
+            jn = jp_msa0_3d + jl - 1
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) 'Check what is readden in nammeddia: -- 3D'
+            IF (lwp) write (numout,*) jl,'meddia3d-sname: ',meddia3d(jl)%sname 
+            IF (lwp) write (numout,*) jl,'meddia3d-lname: ',meddia3d(jl)%lname
+            IF (lwp) write (numout,*) jl,'meddia3d-units: ',meddia3d(jl)%units
+            CALL flush(numout)
+# endif
+            ctrc3d(jn) = meddia3d(jl)%sname
+            ctrc3l(jn) = meddia3d(jl)%lname
+            ctrc3u(jn) = meddia3d(jl)%units
+         END DO
+
+         IF(lwp) THEN                   ! control print
+# if defined key_debug_medusa
+            IF (lwp) write (numout,*) '------------------------------'
+            IF (lwp) write (numout,*) 'Jpalm - debug'
+            IF (lwp) write (numout,*) 'Var name assignation OK'
+            IF (lwp) write (numout,*) 'next check var names'
+            IF (lwp) write (numout,*) ' '
+            CALL flush(numout)
+# endif
+            WRITE(numout,*)
+            WRITE(numout,*) ' Namelist : natadd'
+            DO jl = 1, jp_medusa_3d
+               jn = jp_msa0_3d + jl - 1
+               WRITE(numout,*) '  3d diag nb : ', jn, '    short name : ', ctrc3d(jn), &
+                 &             '  long name  : ', ctrc3l(jn), '   unit : ', ctrc3u(jn)
+            END DO
+            WRITE(numout,*) ' '
+
+            DO jl = 1, jp_medusa_2d
+               jn = jp_msa0_2d + jl - 1
+               WRITE(numout,*) '  2d diag nb : ', jn, '    short name : ', ctrc2d(jn), &
+                 &             '  long name  : ', ctrc2l(jn), '   unit : ', ctrc2u(jn)
+            END DO
+            WRITE(numout,*) ' '
+         ENDIF
+         !
+      ENDIF   
+         !
+# if defined key_debug_medusa
+            CALL flush(numout)
+# endif
+
+      ! 1.4 namelist natbio : biological parameters
+      ! -------------------------------------------
+      
+      xxi         = 0.
+      xaln        = 0.
+      xald        = 0.
+      jphy        = 0
+      xvpn        = 0.
+      xvpd        = 0.
+      xthetam     = 0.
+      xthetamd    = 0.
+!!
+      xsin0       = 0.
+      xnsi0       = 0.
+      xuif        = 0.
+!!
+      jliebig     = 0
+      xnln        = 0.
+      xnld        = 0.
+      xsld        = 0.
+      xfln        = 0.
+      xfld        = 0.
+!!
+      xgmi        = 0.
+      xgme        = 0.
+      xkmi        = 0.
+      xkme        = 0.
+      xphi	  = 0.
+      xbetan      = 0.
+      xbetac      = 0.
+      xkc         = 0.
+      xpmipn      = 0.
+      xpmid       = 0.
+      xpmepn      = 0.
+      xpmepd      = 0.
+      xpmezmi     = 0.
+      xpmed       = 0.
+!!
+      xmetapn     = 0.
+      xmetapd     = 0.
+      xmetazmi    = 0.
+      xmetazme    = 0.
+!!
+      jmpn        = 0
+      xmpn        = 0.
+      xkphn       = 0.
+      jmpd        = 0
+      xmpd        = 0.
+      xkphd       = 0.
+      jmzmi       = 0
+      xmzmi       = 0.
+      xkzmi       = 0.
+      jmzme       = 0
+      xmzme       = 0.
+      xkzme       = 0.
+!!
+      jmd         = 0
+      jsfd        = 0
+      xmd         = 0.
+      xmdc        = 0.
+!!
+      xthetapn    = 0.
+      xthetapd    = 0.
+      xthetazmi   = 0.
+      xthetazme   = 0.
+      xthetad     = 0.
+      xrfn        = 0.
+      xrsn        = 0.  !: (NOT USED HERE; RETAINED FOR LOBSTER)
+!!
+      jiron       = 0
+      xfe_mass    = 0.
+      xfe_sol     = 0.
+      xfe_sed     = 0.
+      xLgT        = 0.
+      xk_FeL	  = 0.
+      xk_sc_Fe    = 0.
+!!
+      jexport     = 0
+      jfdfate     = 0
+      jrratio     = 0
+      jocalccd    = 0
+      xridg_r0    = 0.
+      xfdfrac1	  = 0.
+      xfdfrac2	  = 0.
+      xfdfrac3	  = 0.
+      xcaco3a	  = 0.
+      xcaco3b	  = 0.
+      xmassc	  = 0.
+      xmassca	  = 0.
+      xmasssi	  = 0.
+      xprotca	  = 0.
+      xprotsi	  = 0.
+      xfastc	  = 0.
+      xfastca	  = 0.
+      xfastsi	  = 0.
+!!
+      jorgben     = 0
+      jinorgben   = 0
+      xsedn       = 0.
+      xsedfe      = 0.
+      xsedsi      = 0.
+      xsedc       = 0.
+      xsedca      = 0.
+      xburial     = 0.
+!!
+      jriver_n    = 0
+      jriver_si   = 0
+      jriver_c    = 0
+      jriver_alk  = 0
+      jriver_dep  = 1
+!!
+      xsdiss	  = 0.
+!!
+      vsed        = 0.
+      xhr         = 0.
+!!
+      sedlam	  = 0.
+      sedlostpoc  = 0.
+      jpkb	  = 0.
+      jdms        = 0
+      jdms_input  = 0
+      jdms_input  = 3
+            
+      !REWIND(numnatm)
+      !READ(numnatm,natbio)
+         ! Namelist natbio
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist natbio in reference namelist : MEDUSA diagnostics
+         READ  ( numnatp_ref, natbio, IOSTAT = ios, ERR = 903)
+903      IF( ios /= 0 ) CALL ctl_nam ( ios , 'natbio in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist natbio in configuration namelist : MEDUSA diagnostics
+         READ  ( numnatp_cfg, natbio, IOSTAT = ios, ERR = 904 )
+904      IF( ios /= 0 ) CALL ctl_nam ( ios , 'natbio in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, natbio )
+
+!! Primary production and chl related quantities
+!!       xxi         :  conversion factor from gC to mmolN 
+!!       xaln        :  Chl-a specific initial slope of P-I curve for non-diatoms 
+!!       xald        :  Chl-a specific initial slope of P-I curve for diatoms
+!!       jphy        :  phytoplankton T-dependent growth switch
+!!       xvpn        :  maximum growth rate for non-diatoms
+!!       xvpd        :  maximum growth rate for diatoms
+!!       xthetam     :  maximum Chl to C ratio for non-diatoms      
+!!       xthetamd    :  maximum Chl to C ratio for diatoms      
+!!
+!! Diatom silicon parameters
+!!       xsin0       :  minimum diatom Si:N ratio
+!!       xnsi0       :  minimum diatom N:Si ratio
+!!       xuif        :  hypothetical growth ratio at infinite Si:N ratio
+!!
+!! Nutrient limitation
+!!       jliebig     :  Liebig nutrient uptake switch
+!!       xnln        :  half-sat constant for DIN uptake by non-diatoms 
+!!       xnld        :  half-sat constant for DIN uptake by diatoms 
+!!       xsl         :  half-sat constant for Si uptake by diatoms 
+!!       xfld        :  half-sat constant for Fe uptake by diatoms  
+!!       xfln        :  half-sat constant for Fe uptake by non-datoms 
+!!
+!! Grazing
+!!       xgmi        :  microzoo maximum growth rate 
+!!       xgme        :  mesozoo maximum growth rate 
+!!       xkmi        :  microzoo grazing half-sat parameter
+!!       xkme        :  mesozoo grazing half-sat parameter
+!!       xphi        :  micro/mesozoo grazing inefficiency
+!!       xbetan      :  micro/mesozoo N assimilation efficiency
+!!       xbetac      :  micro/mesozoo C assimilation efficiency
+!!       xkc         :  micro/mesozoo net C growth efficiency
+!!       xpmipn      :  grazing preference of microzoo for non-diatoms
+!!       xpmid       :  grazing preference of microzoo for diatoms
+!!       xpmepn      :  grazing preference of mesozoo for non-diatoms 
+!!       xpmepd      :  grazing preference of mesozoo for diatoms
+!!       xpmezmi     :  grazing preference of mesozoo for microzoo
+!!       xpmed       :  grazing preference of mesozoo for detritus
+!!
+!! Metabolic losses
+!!       xmetapn     :  non-diatom metabolic loss rate
+!!       xmetapd     :  diatom     metabolic loss rate
+!!       xmetazmi    :  microzoo   metabolic loss rate
+!!       xmetazme    :  mesozoo    metabolic loss rate
+!!
+!! Mortality/Remineralisation
+!!       jmpn        :  non-diatom mortality functional form
+!!       xmpn        :  non-diatom mortality rate
+!!       xkphn       :  non-diatom mortality half-sat constant
+!!       jmpd        :  diatom     mortality functional form
+!!       xmpd        :  diatom mortality rate
+!!       xkphd       :  diatom mortality half-sat constant
+!!       jmzmi       :  microzoo   mortality functional form
+!!       xmzmi       :  microzoo mortality rate
+!!       xkzmi       :  microzoo mortality half-sat constant
+!!       jmzme       :  mesozoo    mortality functional form
+!!       xmzme       :  mesozoo mortality rate
+!!       xkzme       :  mesozoo mortality half-sat constant
+!!
+!! Remineralisation
+!!       jmd         :  detritus T-dependent remineralisation switch
+!!       jsfd        :  accelerate seafloor detritus remin. switch
+!!       xmd         :  detrital nitrogen remineralisation rate 
+!!       xmdc        :  detrital carbon remineralisation rate 
+!!
+!! Stochiometric ratios
+!!       xthetapn    :  non-diatom C:N ratio
+!!       xthetapd    :  diatom C:N ratio
+!!       xthetazmi   :  microzoo C:N ratio
+!!       xthetazme   :  mesozoo C:N ratio
+!!       xthetad     :  detritus C:N ratio
+!!       xrfn        :  phytoplankton Fe:N ratio
+!!	 xrsn        :  diatom Si:N ratio (*NOT* used)
+!!
+!! Iron parameters
+!!       jiron       :  iron scavenging submodel switch
+!!       xfe_mass    :  iron atomic mass
+!!	 xfe_sol     :  aeolian iron solubility
+!!	 xfe_sed     :  sediment iron input
+!!	 xLgT	     :  total ligand concentration (umol/m3)
+!!	 xk_FeL	     :  dissociation constant for (Fe + L)
+!!	 xk_sc_Fe    :  scavenging rate of "free" iron
+!!	 
+!! Fast-sinking detritus parameters
+!!       jexport     :  fast detritus remineralisation switch
+!!       jfdfate     :  fate of fast detritus at seafloor switch
+!!       jrratio     :  rain ratio switch
+!!       jocalccd    :  CCD switch
+!!       xridg_r0    :  Ridgwell rain ratio coefficient
+!!       xfdfrac1    :  fast-sinking fraction of diatom nat. mort. losses
+!!       xfdfrac2    :  fast-sinking fraction of meszooplankton mort. losses
+!!       xfdfrac3    :  fast-sinking fraction of diatom silicon grazing losses
+!!       xcaco3a     :  polar (high latitude) CaCO3 fraction
+!!       xcaco3b     :  equatorial (low latitude) CaCO3 fraction
+!!       xmassc      :  organic C mass:mole ratio, C106 H175 O40 N16 P1
+!!       xmassca     :  calcium carbonate mass:mole ratio, CaCO3
+!!       xmasssi     :  biogenic silicon mass:mole ratio, (H2SiO3)n
+!!       xprotca     :  calcium carbonate protection ratio
+!!       xprotsi     :  biogenic silicon protection ratio
+!!       xfastc      :  organic C remineralisation length scale
+!!       xfastca     :  calcium carbonate dissolution length scale
+!!       xfastsi     :  biogenic silicon dissolution length scale
+!!
+!! Benthic 
+!!       jorgben     :  does   organic detritus go to the benthos?
+!!       jinorgben   :  does inorganic detritus go to the benthos?
+!!       xsedn       :  organic   nitrogen sediment remineralisation rate 
+!!       xsedfe      :  organic   iron     sediment remineralisation rate 
+!!       xsedsi      :  inorganic silicon  sediment dissolution      rate 
+!!       xsedc       :  organic   carbon   sediment remineralisation rate 
+!!       xsedca      :  inorganic carbon   sediment dissolution      rate 
+!!       xburial     :  burial rate of seafloor detritus
+!!
+!! Riverine inputs
+!!       jriver_n    :  riverine N          input?
+!!       jriver_si   :  riverine Si         input?
+!!       jriver_c    :  riverine C          input?
+!!       jriver_alk  :  riverine alkalinity input?
+!!       jriver_dep  :  depth of riverine   input?
+!!
+!! Miscellaneous
+!!       xsdiss      :  diatom frustule dissolution rate
+!!
+!! Gravitational sinking      
+!!       vsed        :  detritus gravitational sinking rate 
+!!       xhr         :  coeff for Martin's remineralisation profile
+!!
+!! Additional parameters
+!!       sedlam      :  time coeff of POC in sediments
+!!      sedlostpoc   :  sediment geol loss for POC
+!!       jpkb        :  vertical layer for diagnostic of the vertical flux 
+!!                      NOTE that in LOBSTER it is a first vertical layers where 
+!!                      biology is active  
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+!!       jdms        :  include dms diagnostics
+!!	 jdms_input  :  use instant (0) or diel-avg (1) inputs
+!!       jdms_model  :  choice of DMS model passed to atmosphere
+!!                      1 = ANDR, 2 = SIMO, 3 = ARAN, 4 = HALL
+!!
+      IF(lwp) THEN
+!!
+!! AXY (08/11/13): compilation key notification
+         WRITE(numout,*) '=== Compilation keys'
+#if defined key_roam
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = INACTIVE'
+#endif        
+#if defined key_axy_carbchem
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = INACTIVE'
+#endif        
+#if defined key_mocsy
+         WRITE(numout,*)     &
+         &   ' key_mocsy                                                              = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_mocsy                                                              = INACTIVE'
+#endif        
+#if defined key_avgqsr_medusa
+         WRITE(numout,*)     &
+         &   ' key_avgqsr_medusa                                                      = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_avgqsr_medusa                                                      = INACTIVE'
+#endif        
+#if defined key_bs_axy_zforce
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = INACTIVE'
+#endif        
+#if defined key_bs_axy_yrlen
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = INACTIVE'
+#endif        
+#if defined key_deep_fe_fix
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = INACTIVE'
+#endif        
+#if defined key_axy_nancheck
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = INACTIVE'
+#endif        
+# if defined key_axy_pi_co2
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = INACTIVE'
+# endif
+# if defined key_debug_medusa
+         WRITE(numout,*)     &
+         &   ' key_debug_medusa                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_debug_medusa                                                       = INACTIVE'
+# endif
+         WRITE(numout,*) ' '
+
+         WRITE(numout,*) 'natbio'
+         WRITE(numout,*) ' '
+!!
+!! Primary production and chl related quantities
+         WRITE(numout,*) '=== Primary production'
+         WRITE(numout,*)     &
+         &   ' conversion factor from gC to mmolN,                        xxi         =', xxi
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for non-diatoms, xaln        = ', xaln
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for diatoms,     xald        = ', xald
+         if (jphy.eq.1) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-dependent*            jphy        = ', jphy
+         elseif (jphy.eq.2) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-dependent(Q10)*       jphy        = ', jphy
+         elseif (jphy.eq.0) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-independent*          jphy        = ', jphy
+         endif
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for non-diatoms,                       xvpn        = ', xvpn
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for diatoms,                           xvpn        = ', xvpd
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for non-diatoms,                    xthetam     = ', xthetam
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for diatoms,                        xthetamd    = ', xthetamd
+         WRITE(numout,*)     &
+         &   ' specific Q10 value (jphy==2),                                  jq10    = ', jq10
+!!
+!! Diatom silicon parameters
+         WRITE(numout,*) '=== Diatom silicon parameters'
+         WRITE(numout,*)     &
+         &   ' minimum diatom Si:N ratio,                                 xsin0       = ', xsin0
+         WRITE(numout,*)     &
+         &   ' minimum diatom N:Si ratio,                                 xnsi0       = ', xnsi0
+         WRITE(numout,*)     &
+         &   ' hypothetical growth ratio at infinite Si:N ratio,          xuif        = ', xuif
+!!
+!! Nutrient limitation
+         WRITE(numout,*) '=== Nutrient limitation'
+         if (jliebig.eq.1) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a Liebig Law (= most limiting) function jliebig     = ', jliebig
+         elseif (jliebig.eq.0) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a multiplicative function               jliebig     = ', jliebig
+         endif
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by non-diatoms,           xnln        = ', xnln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by diatoms,               xnld        = ', xnld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Si uptake by diatoms,                xsld        = ', xsld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by non-diatoms,            xfln        = ', xfln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by diatoms,                xfld        = ', xfld
+!!
+!! Grazing
+         WRITE(numout,*) '=== Zooplankton grazing'
+         WRITE(numout,*)     &
+         &   ' microzoo maximum growth rate,                              xgmi        = ', xgmi
+         WRITE(numout,*)     &
+         &   ' mesozoo maximum growth rate,                               xgme        = ', xgme
+         WRITE(numout,*)     &
+         &   ' microzoo grazing half-sat parameter,                       xkmi        = ', xkmi
+         WRITE(numout,*)     &
+         &   ' mesozoo grazing half-sat parameter,                        xkme        = ', xkme
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo grazing inefficiency,                        xphi        = ', xphi
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo N assimilation efficiency,                   xbetan      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo C assimilation efficiency,                   xbetac      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo net C growth efficiency,                     xkc         = ', xkc
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for non-diatoms,            xpmipn      = ', xpmipn
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for detritus,               xpmid       = ', xpmid
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for non-diatoms,             xpmepn      = ', xpmepn
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for diatoms,                 xpmepd      = ', xpmepd
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for microzoo,                xpmezmi     = ', xpmezmi
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for detritus,                xpmed       = ', xpmed
+!!
+!! Metabolic losses
+         WRITE(numout,*) '=== Metabolic losses'
+         WRITE(numout,*)     &
+         &   ' non-diatom metabolic loss rate,                            xmetapn     = ', xmetapn
+         WRITE(numout,*)     &
+         &   ' diatom     metabolic loss rate,                            xmetapd     = ', xmetapd
+         WRITE(numout,*)     &
+         &   ' microzoo   metabolic loss rate,                            xmetazmi    = ', xmetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo    metabolic loss rate,                            xmetazme    = ', xmetazme
+!!
+!! Mortality losses
+         WRITE(numout,*) '=== Mortality losses'
+         if (jmpn.eq.1) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,            LINEAR    jmpn        = ', jmpn
+         elseif (jmpn.eq.2) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,         QUADRATIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.3) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,        HYPERBOLIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.4) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,           SIGMOID    jmpn        = ', jmpn
+         endif
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality rate,                                 xmpn        = ', xmpn
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality half-sat constant                     xkphn       = ', xkphn
+         if (jmpd.eq.1) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,                LINEAR    jmpd        = ', jmpd
+         elseif (jmpd.eq.2) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,             QUADRATIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.3) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,            HYPERBOLIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.4) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,               SIGMOID    jmpd        = ', jmpd
+         endif
+         WRITE(numout,*)     &
+         &   ' diatom mortality rate,                                     xmpd        = ', xmpd
+         WRITE(numout,*)     &
+         &   ' diatom mortality half-sat constant                         xkphd       = ', xkphd
+         if (jmzmi.eq.1) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,              LINEAR    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.2) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,           QUADRATIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.3) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,          HYPERBOLIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.4) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,             SIGMOID    jmzmi       = ', jmzmi
+         endif
+         WRITE(numout,*)     &
+         &   ' microzoo mortality rate,                                   xmzmi       = ', xmzmi
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzmi       = ', xkzmi
+         if (jmzme.eq.1) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,               LINEAR    jmzme       = ', jmzme
+         elseif (jmzme.eq.2) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,            QUADRATIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.3) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,           HYPERBOLIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.4) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,              SIGMOID    jmzme       = ', jmzme
+         endif
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality rate,                                    xmzme       = ', xmzme
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzme       = ', xkzme
+!!
+!! Remineralisation
+         WRITE(numout,*) '=== Remineralisation'
+         if (jmd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-dependent*       jmd         = ', jmd
+         elseif (jmd.eq.2) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-dependent(Q10)*  jmd         = ', jmd
+         elseif (jmd.eq.0) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-independent*     jmd         = ', jmd
+         endif
+         if (jsfd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation is *accelerated*        jsfd        = ', jsfd
+         else
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation occurs at same rate     jsfd        = ', jsfd
+         endif
+         WRITE(numout,*)     &
+         &   ' detrital nitrogen remineralisation rate,                   xmd         = ', xmd
+         WRITE(numout,*)     &
+         &   ' detrital carbon remineralisation rate,                     xmdc        = ', xmdc
+!!
+!! Stochiometric ratios
+         WRITE(numout,*) '=== Stoichiometric ratios'
+         WRITE(numout,*)     &
+         &   ' non-diatom C:N ratio,                                      xthetapn    = ', xthetapn
+         WRITE(numout,*)     &
+         &   ' diatom C:N ratio,                                          xthetapd    = ', xthetapd
+         WRITE(numout,*)     &
+         &   ' microzoo C:N ratio,                                        xthetazmi   = ', xthetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo C:N ratio,                                         xthetazme   = ', xthetazme
+         WRITE(numout,*)     &
+         &   ' detritus C:N ratio,                                        xthetad     = ', xthetad
+         WRITE(numout,*)     &
+         &   ' phytoplankton Fe:N ratio,                                  xrfn        = ', xrfn
+         WRITE(numout,*)     &
+         &   ' diatom Si:N ratio,                                         xrsn        = ', xrsn
+!!	  
+!! Iron parameters
+         WRITE(numout,*) '=== Iron parameters'
+         if (jiron.eq.1) then
+            WRITE(numout,*)     &
+            &   ' Dutkiewicz et al. (2005) iron scavenging                   jiron       = ', jiron
+         elseif (jiron.eq.2) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2004) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.3) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2008) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.4) then
+            WRITE(numout,*)     &
+            &   ' Galbraith et al. (2010) iron scavenging                    jiron       = ', jiron
+         else
+            WRITE(numout,*)     &
+            &   ' There is **no** iron scavenging                            jiron       = ', jiron
+         endif
+         WRITE(numout,*)     &
+         &   ' iron atomic mass,                                          xfe_mass    = ', xfe_mass
+         WRITE(numout,*)     &
+         &   ' aeolian iron solubility,                                   xfe_sol     = ', xfe_sol
+         WRITE(numout,*)     &
+         &   ' sediment iron input,                                       xfe_sed     = ', xfe_sed
+         WRITE(numout,*)     &
+         &   ' total ligand concentration (umol/m3),                      xLgT        = ', xLgT
+         WRITE(numout,*)     &
+         &   ' dissociation constant for (Fe + L),                        xk_FeL      = ', xk_FeL
+         WRITE(numout,*)     &
+         &   ' scavenging rate for free iron,                             xk_sc_Fe    = ', xk_sc_Fe
+!!
+!! Fast-sinking detritus parameters
+         WRITE(numout,*) '=== Fast-sinking detritus'
+         if (jexport.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Dunne et al. (2007; ballast)     jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Martin et al. (1987)             jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Henson et al. (2011)             jexport     = ', jexport
+         endif
+         if (jfdfate.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor becomes slow-detritus      jfdfate     = ', jfdfate
+         elseif (jfdfate.eq.0) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor instantly remineralised    jfdfate     = ', jfdfate
+         endif
+#if defined key_roam
+         if (jrratio.eq.0) then
+            WRITE(numout,*) &
+            &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+         elseif (jrratio.eq.1) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (surface omega) jrratio     = ', jrratio
+         elseif (jrratio.eq.2) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (3D omega)      jrratio     = ', jrratio
+         endif
+#else          
+         jrratio = 0
+         WRITE(numout,*) &
+         &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+#endif          
+#if defined key_roam
+         if (jocalccd.eq.0) then
+            WRITE(numout,*) &
+            &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+         elseif (jocalccd.eq.1) then
+            WRITE(numout,*) &
+            &   ' Calculated, dynamic CCD used                               jocalccd    = ', jocalccd
+         endif
+#else          
+         jocalccd = 0
+         WRITE(numout,*) &
+         &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+#endif
+         WRITE(numout,*)     &
+         &   ' Ridgwell rain ratio coefficient,                           xridg_r0    = ', xridg_r0
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom nat. mort. losses,         xfdfrac1    = ', xfdfrac1
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of mesozooplankton mort. losses,     xfdfrac2    = ', xfdfrac2
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom silicon grazing losses,    xfdfrac3    = ', xfdfrac3
+         WRITE(numout,*)     &
+         &   ' polar (high latitude) CaCO3 fraction,                      xcaco3a     = ', xcaco3a
+         WRITE(numout,*)     &
+         &   ' equatorial (low latitude) CaCO3 fraction,                  xcaco3b     = ', xcaco3b
+         WRITE(numout,*)     &
+         &   ' organic C mass:mole ratio, C106 H175 O40 N16 P1,           xmassc      = ', xmassc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate mass:mole ratio, CaCO3,                  xmassca     = ', xmassca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon mass:mole ratio, (H2SiO3)n,               xmasssi     = ', xmasssi
+         WRITE(numout,*)     &
+         &   ' calcium carbonate protection ratio,                        xprotca     = ', xprotca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon protection ratio,                         xprotsi     = ', xprotsi
+         WRITE(numout,*)     &
+         &   ' organic C remineralisation length scale,                   xfastc      = ', xfastc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate dissolution length scale,                xfastca     = ', xfastca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon dissolution length scale,                 xfastsi     = ', xfastsi
+!!
+!! Benthos parameters
+         WRITE(numout,*) '=== Benthos parameters'
+         WRITE(numout,*)     &
+         &   ' does   organic detritus go to the benthos?,                jorgben     = ', jorgben
+         WRITE(numout,*)     &
+         &   ' does inorganic detritus go to the benthos?,                jinorgben   = ', jinorgben
+!!
+!! Some checks on parameters related to benthos parameters
+         if (jorgben.eq.1 .and. jsfd.eq.1) then
+            !! slow detritus going to benthos at an accelerated rate
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jsfd *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.1 .and. jfdfate.eq.1) then
+            !! fast detritus going to benthos but via slow detritus
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jfdfate *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.0 .and. jinorgben.eq.1) then
+            !! inorganic fast detritus going to benthos but organic fast detritus is not
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jinorgben is active but jorgben is not - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         WRITE(numout,*)     &
+         &   ' organic   nitrogen sediment remineralisation rate,         xsedn       = ', xsedn
+         WRITE(numout,*)     &
+         &   ' organic   iron     sediment remineralisation rate,         xsedfe      = ', xsedfe
+         WRITE(numout,*)     &
+         &   ' inorganic silicon  sediment remineralisation rate,         xsedsi      = ', xsedsi
+         WRITE(numout,*)     &
+         &   ' organic   carbon   sediment remineralisation rate,         xsedc       = ', xsedc
+         WRITE(numout,*)     &
+         &   ' inorganic carbon   sediment remineralisation rate,         xsedca      = ', xsedca
+         WRITE(numout,*)     &
+         &   ' burial rate of seafloor detritus,                          xburial     = ', xburial
+!!
+!! Riverine inputs
+         WRITE(numout,*) '=== Riverine inputs'
+         if (jriver_n.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine N input,                                     jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine N concentrations specified,                       jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine N inputs specified,                               jriver_n    = ', jriver_n
+         endif
+         if (jriver_si.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine Si input,                                    jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine Si concentrations specified,                      jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine Si inputs specified,                              jriver_si   = ', jriver_si
+         endif
+         if (jriver_c.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine C input,                                     jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine C concentrations specified,                       jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine C inputs specified,                               jriver_c    = ', jriver_c
+         endif
+         if (jriver_alk.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine alkalinity input,                            jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity concentrations specified,              jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity inputs specified,                      jriver_alk  = ', jriver_alk
+         endif
+         !! AXY (19/07/12): prevent (gross) stupidity on part of user
+         if (jriver_dep.lt.1.or.jriver_dep.ge.jpk) then
+            jriver_dep = 1
+         endif
+         WRITE(numout,*)     &
+         &   ' riverine input applied to down to depth k = ...            jriver_dep  = ', jriver_dep
+!!
+!! Miscellaneous
+         WRITE(numout,*) '=== Miscellaneous'
+         WRITE(numout,*)     &
+         &   ' diatom frustule dissolution rate,                          xsdiss      = ', xsdiss
+!!
+!! Gravitational sinking      
+         WRITE(numout,*) '=== Gravitational sinking'
+         WRITE(numout,*)     &
+         &   ' detritus gravitational sinking rate,                       vsed        = ', vsed
+         WRITE(numout,*)     & 
+         &   ' coefficient for Martin et al. (1987) remineralisation,     xhr         = ', xhr
+!!
+!! Non-Medusa parameters
+         WRITE(numout,*) '=== Non-Medusa parameters'
+         WRITE(numout,*)     & 
+         &   ' time coeff of POC in sediments,                            sedlam      = ', sedlam
+         WRITE(numout,*)     &
+         &   ' Sediment geol loss for POC,                                sedlostpoc  = ', sedlostpoc
+         WRITE(numout,*)     &
+         &   ' Vert layer for diagnostic of vertical flux,                jpkp        = ', jpkb
+!!
+!! UKESM1 - new diagnostics  !! Jpalm; AXY (08/07/15)
+         WRITE(numout,*) '=== UKESM1-related parameters'
+         WRITE(numout,*)     &
+         &   ' include DMS diagnostic?,                                   jdms        = ', jdms
+         if (jdms_input .eq. 0) then
+            WRITE(numout,*)     &
+            &   ' use instant (0) or diel-avg (1) inputs,                    jdms_input  = instantaneous'
+         else
+            WRITE(numout,*)     &
+            &   ' use instant (0) or diel-avg (1) inputs,                    jdms_input  = diel-average'
+         endif
+	 if (jdms_model .eq. 1) then
+            WRITE(numout,*)     &
+            &   ' choice of DMS model passed to atmosphere,                  jdms_model  = Anderson et al. (2001)'
+	 elseif (jdms_model .eq. 2) then
+            WRITE(numout,*)     &
+            &   ' choice of DMS model passed to atmosphere,                  jdms_model  = Simo & Dachs (2002)'
+	 elseif (jdms_model .eq. 3) then
+            WRITE(numout,*)     &
+            &   ' choice of DMS model passed to atmosphere,                  jdms_model  = Aranami & Tsunogai (2004)'
+	 elseif (jdms_model .eq. 4) then
+            WRITE(numout,*)     &
+            &   ' choice of DMS model passed to atmosphere,                  jdms_model  = Halloran et al. (2010)'
+         endif
+!!
+      ENDIF
+!!
+!! Key depth positions (with thanks to Andrew Coward for bug-fixing this bit)
+      DO jk = 1,jpk
+         !! level thickness
+         fthk  = e3t_1d(jk)
+         !! level depth (top of level)
+         fdep  = gdepw_1d(jk)
+         !! level depth (bottom of level)
+         fdep1 = fdep + fthk
+         !!
+         if (fdep.lt.100.0.AND.fdep1.gt.100.0) then        !  100 m
+            i0100 = jk
+         elseif (fdep.lt.150.0.AND.fdep1.gt.150.0) then    !  150 m (for BASIN)
+            i0150 = jk
+         elseif (fdep.lt.200.0.AND.fdep1.gt.200.0) then    !  200 m
+            i0200 = jk
+         elseif (fdep.lt.500.0.AND.fdep1.gt.500.0) then    !  500 m
+            i0500 = jk
+         elseif (fdep.lt.1000.0.AND.fdep1.gt.1000.0) then  ! 1000 m
+            i1000 = jk
+         elseif (fdep1.lt.1100.0) then                     ! 1100 m (for Moore et al. sedimentary iron)
+            i1100 = jk
+         endif
+      enddo
+      !!
+      IF(lwp) THEN
+          WRITE(numout,*) '=== Position of key depths'
+          WRITE(numout,*)     & 
+          &   ' jk position of  100 m horizon                              i0100       = ', i0100
+          WRITE(numout,*)     &
+          &   ' jk position of  150 m horizon                              i0150       = ', i0150
+          WRITE(numout,*)     & 
+          &   ' jk position of  200 m horizon                              i0200       = ', i0200
+          WRITE(numout,*)     & 
+          &   ' jk position of  500 m horizon                              i0500       = ', i0500
+          WRITE(numout,*)     & 
+          &   ' jk position of 1000 m horizon                              i1000       = ', i1000
+          WRITE(numout,*)     & 
+          &   ' jk position of 1100 m horizon [*]                          i1100       = ', i1100
+          WRITE(numout,*) 'Got here ' , SIZE(friver_dep)
+          CALL flush(numout)
+      ENDIF
+
+#if defined key_roam
+
+      ! 1.4b namelist natroam : ROAM parameters
+      ! ---------------------------------------
+      
+      xthetaphy = 0.
+      xthetazoo = 0.
+      xthetanit = 0.
+      xthetarem = 0.
+      xo2min    = 0.
+
+      !READ(numnatm,natroam)
+         ! Namelist natroam
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist natroam in reference namelist : MEDUSA diagnostics
+         READ  ( numnatp_ref, natroam, IOSTAT = ios, ERR = 905)
+905      IF( ios /= 0 ) CALL ctl_nam ( ios , 'natroam in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist natroam in configuration namelist : MEDUSA diagnostics
+         READ  ( numnatp_cfg, natroam, IOSTAT = ios, ERR = 906 )
+906      IF( ios /= 0 ) CALL ctl_nam ( ios , 'natroam in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, natroam )
+
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+!!       xthetaphy :  oxygen evolution/consumption by phytoplankton
+!!       xthetazoo :  oxygen consumption by zooplankton
+!!       xthetanit :  oxygen consumption by nitrogen remineralisation
+!!       xthetarem :  oxygen consumption by carbon remineralisation
+!!       xo2min    :  oxygen minimum concentration
+
+      IF(lwp) THEN
+          WRITE(numout,*) 'natroam'
+          WRITE(numout,*) ' '
+!!
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+          WRITE(numout,*) '=== ROAM carbon, alkalinity and oxygen cycle parameters'
+          WRITE(numout,*)     &
+          &   ' oxygen evolution/consumption by phytoplankton              xthetaphy   = ', xthetaphy
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by zooplankton                          xthetazoo   = ', xthetazoo
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by nitrogen remineralisation            xthetanit   = ', xthetanit
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by carbon remineralisation              xthetarem   = ', xthetarem
+          WRITE(numout,*)     &
+          &   ' oxygen minimum concentration                               xo2min      = ', xo2min
+       ENDIF
+
+#endif
+
+      CALL flush(numout)
+
+      ! 1.5 namelist natopt : parameters for optic
+      ! ------------------------------------------
+
+      xkg0  = 0.
+      xkr0  = 0.
+      xkgp  = 0.
+      xkrp  = 0.
+      xlg   = 0.
+      xlr   = 0.
+      rpig  = 0.
+
+      !READ(numnatm,natopt)
+         ! Namelist natopt
+         ! -------------------
+         REWIND( numnatp_ref )              ! Namelist natopt in reference namelist : MEDUSA diagnostics
+         READ  ( numnatp_ref, natopt, IOSTAT = ios, ERR = 907)
+907      IF( ios /= 0 ) CALL ctl_nam ( ios , 'natopt in reference namelist', lwp )
+
+         REWIND( numnatp_cfg )              ! Namelist natopt in configuration namelist : MEDUSA diagnostics
+         READ  ( numnatp_cfg, natopt, IOSTAT = ios, ERR = 908 )
+908      IF( ios /= 0 ) CALL ctl_nam ( ios , 'natopt in configuration namelist', lwp )
+         IF(lwm) WRITE ( numonp, natopt )
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'natopt'
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' green   water absorption coeff  xkg0  = ',xkg0
+         WRITE(numout,*) ' red water absorption coeff      xkr0  = ',xkr0
+         WRITE(numout,*) ' pigment red absorption coeff    xkrp  = ',xkrp
+         WRITE(numout,*) ' pigment green absorption coeff  xkgp  = ',xkgp
+         WRITE(numout,*) ' green chl exposant              xlg   = ',xlg
+         WRITE(numout,*) ' red   chl exposant              xlr   = ',xlr
+         WRITE(numout,*) ' chla/chla+phea ratio            rpig  = ',rpig
+         WRITE(numout,*) ' '
+
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'NaN check'
+         WRITE(numout,*) ' '
+         q1 = -1.
+         q2 = 0.
+         q3 = log(q1)
+         write (numout,*) 'q3 = ', q3
+         if ( ieee_is_nan( q3 ) ) then
+            write (numout,*) 'NaN detected'
+         else
+            write (numout,*) 'NaN not detected'
+         endif
+         WRITE(numout,*) ' '
+       ENDIF
+
+   END SUBROUTINE trc_nam_medusa
+   
+   SUBROUTINE trc_nam_iom_medusa
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_nam_iom_medusa  ***
+      !!
+      !! ** Purpose : read all diag requested in iodef file through iom_use
+      !!              So it is done only once 
+      !!            ** All diagnostic MEDUSA could asked are registered in
+      !!            the med_diag type with a boolean value
+      !!            So if required, one diagnostic will be true.
+      !!
+      !!---------------------------------------------------------------------
+      !!
+      !!
+      !!----------------------------------------------------------------------            
+      !! Variable conventions
+      !!----------------------------------------------------------------------
+      !!
+      IF (iom_use("INVTN")) THEN 
+          med_diag%INVTN%dgsave = .TRUE.
+      ELSE 
+          med_diag%INVTN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INVTSI")) THEN 
+          med_diag%INVTSI%dgsave = .TRUE.
+      ELSE 
+          med_diag%INVTSI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INVTFE")) THEN 
+          med_diag%INVTFE%dgsave = .TRUE.
+      ELSE 
+          med_diag%INVTFE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PRN")) THEN 
+          med_diag%PRN%dgsave = .TRUE.
+      ELSE 
+          med_diag%PRN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MPN")) THEN 
+          med_diag%MPN%dgsave = .TRUE.
+      ELSE 
+          med_diag%MPN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PRD")) THEN 
+          med_diag%PRD%dgsave = .TRUE.
+      ELSE 
+          med_diag%PRD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MPD")) THEN 
+          med_diag%MPD%dgsave = .TRUE.
+      ELSE 
+          med_diag%MPD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DSED")) THEN 
+          med_diag%DSED%dgsave = .TRUE.
+      ELSE 
+          med_diag%DSED%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OPAL")) THEN 
+          med_diag%OPAL%dgsave = .TRUE.
+      ELSE 
+          med_diag%OPAL%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OPALDISS")) THEN 
+          med_diag%OPALDISS%dgsave = .TRUE.
+      ELSE 
+          med_diag%OPALDISS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMIPn")) THEN 
+          med_diag%GMIPn%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMIPn%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMID")) THEN 
+          med_diag%GMID%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMID%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MZMI")) THEN 
+          med_diag%MZMI%dgsave = .TRUE.
+      ELSE 
+          med_diag%MZMI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMEPN")) THEN 
+          med_diag%GMEPN%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMEPN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMEPD")) THEN 
+          med_diag%GMEPD%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMEPD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMEZMI")) THEN 
+          med_diag%GMEZMI%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMEZMI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMED")) THEN 
+          med_diag%GMED%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMED%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MZME")) THEN 
+          med_diag%MZME%dgsave = .TRUE.
+      ELSE 
+          med_diag%MZME%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DEXP")) THEN 
+          med_diag%DEXP%dgsave = .TRUE.
+      ELSE 
+          med_diag%DEXP%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DETN")) THEN 
+          med_diag%DETN%dgsave = .TRUE.
+      ELSE 
+          med_diag%DETN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MDET")) THEN 
+          med_diag%MDET%dgsave = .TRUE.
+      ELSE 
+          med_diag%MDET%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("AEOLIAN")) THEN 
+          med_diag%AEOLIAN%dgsave = .TRUE.
+      ELSE 
+          med_diag%AEOLIAN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BENTHIC")) THEN 
+          med_diag%BENTHIC%dgsave = .TRUE.
+      ELSE 
+          med_diag%BENTHIC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SCAVENGE")) THEN 
+          med_diag%SCAVENGE%dgsave = .TRUE.
+      ELSE 
+          med_diag%SCAVENGE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PN_JLIM")) THEN 
+          med_diag%PN_JLIM%dgsave = .TRUE.
+      ELSE 
+          med_diag%PN_JLIM%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PN_NLIM")) THEN 
+          med_diag%PN_NLIM%dgsave = .TRUE.
+      ELSE 
+          med_diag%PN_NLIM%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PN_FELIM")) THEN 
+          med_diag%PN_FELIM%dgsave = .TRUE.
+      ELSE 
+          med_diag%PN_FELIM%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PD_JLIM")) THEN 
+          med_diag%PD_JLIM%dgsave = .TRUE.
+      ELSE 
+          med_diag%PD_JLIM%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PD_NLIM")) THEN 
+          med_diag%PD_NLIM%dgsave = .TRUE.
+      ELSE 
+          med_diag%PD_NLIM%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PD_FELIM")) THEN 
+          med_diag%PD_FELIM%dgsave = .TRUE.
+      ELSE 
+          med_diag%PD_FELIM%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PD_SILIM")) THEN 
+          med_diag%PD_SILIM%dgsave = .TRUE.
+      ELSE 
+          med_diag%PD_SILIM%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PDSILIM2")) THEN 
+          med_diag%PDSILIM2%dgsave = .TRUE.
+      ELSE 
+          med_diag%PDSILIM2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDT__100")) THEN 
+          med_diag%SDT__100%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDT__100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDT__200")) THEN 
+          med_diag%SDT__200%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDT__200%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDT__500")) THEN 
+          med_diag%SDT__500%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDT__500%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDT_1000")) THEN 
+          med_diag%SDT_1000%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDT_1000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("TOTREG_N")) THEN 
+          med_diag%TOTREG_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%TOTREG_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("TOTRG_SI")) THEN 
+          med_diag%TOTRG_SI%dgsave = .TRUE.
+      ELSE 
+          med_diag%TOTRG_SI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REG__100")) THEN 
+          med_diag%REG__100%dgsave = .TRUE.
+      ELSE 
+          med_diag%REG__100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REG__200")) THEN 
+          med_diag%REG__200%dgsave = .TRUE.
+      ELSE 
+          med_diag%REG__200%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REG__500")) THEN 
+          med_diag%REG__500%dgsave = .TRUE.
+      ELSE 
+          med_diag%REG__500%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REG_1000")) THEN 
+          med_diag%REG_1000%dgsave = .TRUE.
+      ELSE 
+          med_diag%REG_1000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FASTN")) THEN 
+          med_diag%FASTN%dgsave = .TRUE.
+      ELSE 
+          med_diag%FASTN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FASTSI")) THEN 
+          med_diag%FASTSI%dgsave = .TRUE.
+      ELSE 
+          med_diag%FASTSI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FASTFE")) THEN 
+          med_diag%FASTFE%dgsave = .TRUE.
+      ELSE 
+          med_diag%FASTFE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FASTC")) THEN 
+          med_diag%FASTC%dgsave = .TRUE.
+      ELSE 
+          med_diag%FASTC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FASTCA")) THEN 
+          med_diag%FASTCA%dgsave = .TRUE.
+      ELSE 
+          med_diag%FASTCA%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDT__100")) THEN 
+          med_diag%FDT__100%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDT__100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDT__200")) THEN 
+          med_diag%FDT__200%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDT__200%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDT__500")) THEN 
+          med_diag%FDT__500%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDT__500%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDT_1000")) THEN 
+          med_diag%FDT_1000%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDT_1000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RG__100F")) THEN 
+          med_diag%RG__100F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RG__100F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RG__200F")) THEN 
+          med_diag%RG__200F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RG__200F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RG__500F")) THEN 
+          med_diag%RG__500F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RG__500F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RG_1000F")) THEN 
+          med_diag%RG_1000F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RG_1000F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDS__100")) THEN 
+          med_diag%FDS__100%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDS__100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDS__200")) THEN 
+          med_diag%FDS__200%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDS__200%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDS__500")) THEN 
+          med_diag%FDS__500%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDS__500%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FDS_1000")) THEN 
+          med_diag%FDS_1000%dgsave = .TRUE.
+      ELSE 
+          med_diag%FDS_1000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RGS_100F")) THEN 
+          med_diag%RGS_100F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RGS_100F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RGS_200F")) THEN 
+          med_diag%RGS_200F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RGS_200F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RGS_500F")) THEN 
+          med_diag%RGS_500F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RGS_500F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RGS1000F")) THEN 
+          med_diag%RGS1000F%dgsave = .TRUE.
+      ELSE 
+          med_diag%RGS1000F%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REMINN")) THEN 
+          med_diag%REMINN%dgsave = .TRUE.
+      ELSE 
+          med_diag%REMINN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REMINSI")) THEN 
+          med_diag%REMINSI%dgsave = .TRUE.
+      ELSE 
+          med_diag%REMINSI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REMINFE")) THEN 
+          med_diag%REMINFE%dgsave = .TRUE.
+      ELSE 
+          med_diag%REMINFE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REMINC")) THEN 
+          med_diag%REMINC%dgsave = .TRUE.
+      ELSE 
+          med_diag%REMINC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REMINCA")) THEN 
+          med_diag%REMINCA%dgsave = .TRUE.
+      ELSE 
+          med_diag%REMINCA%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SEAFLRN")) THEN 
+          med_diag%SEAFLRN%dgsave = .TRUE.
+      ELSE 
+          med_diag%SEAFLRN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SEAFLRSI")) THEN 
+          med_diag%SEAFLRSI%dgsave = .TRUE.
+      ELSE 
+          med_diag%SEAFLRSI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SEAFLRFE")) THEN 
+          med_diag%SEAFLRFE%dgsave = .TRUE.
+      ELSE 
+          med_diag%SEAFLRFE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SEAFLRC")) THEN 
+          med_diag%SEAFLRC%dgsave = .TRUE.
+      ELSE 
+          med_diag%SEAFLRC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SEAFLRCA")) THEN 
+          med_diag%SEAFLRCA%dgsave = .TRUE.
+      ELSE 
+          med_diag%SEAFLRCA%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MED_QSR")) THEN 
+          med_diag%MED_QSR%dgsave = .TRUE.
+      ELSE 
+          med_diag%MED_QSR%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MED_XPAR")) THEN 
+          med_diag%MED_XPAR%dgsave = .TRUE.
+      ELSE 
+          med_diag%MED_XPAR%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INTFLX_N")) THEN 
+          med_diag%INTFLX_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%INTFLX_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INTFLX_SI")) THEN 
+          med_diag%INTFLX_SI%dgsave = .TRUE.
+      ELSE 
+          med_diag%INTFLX_SI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INTFLX_FE")) THEN 
+          med_diag%INTFLX_FE%dgsave = .TRUE.
+      ELSE 
+          med_diag%INTFLX_FE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INT_PN")) THEN 
+          med_diag%INT_PN%dgsave = .TRUE.
+      ELSE 
+          med_diag%INT_PN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INT_PD")) THEN 
+          med_diag%INT_PD%dgsave = .TRUE.
+      ELSE 
+          med_diag%INT_PD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ML_PRN")) THEN 
+          med_diag%ML_PRN%dgsave = .TRUE.
+      ELSE 
+          med_diag%ML_PRN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ML_PRD")) THEN 
+          med_diag%ML_PRD%dgsave = .TRUE.
+      ELSE 
+          med_diag%ML_PRD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCAL_CCD")) THEN 
+          med_diag%OCAL_CCD%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCAL_CCD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCAL_LVL")) THEN 
+          med_diag%OCAL_LVL%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCAL_LVL%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FE_0000")) THEN 
+          med_diag%FE_0000%dgsave = .TRUE.
+      ELSE 
+          med_diag%FE_0000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FE_0100")) THEN 
+          med_diag%FE_0100%dgsave = .TRUE.
+      ELSE 
+          med_diag%FE_0100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FE_0200")) THEN 
+          med_diag%FE_0200%dgsave = .TRUE.
+      ELSE 
+          med_diag%FE_0200%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FE_0500")) THEN 
+          med_diag%FE_0500%dgsave = .TRUE.
+      ELSE 
+          med_diag%FE_0500%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FE_1000")) THEN 
+          med_diag%FE_1000%dgsave = .TRUE.
+      ELSE 
+          med_diag%FE_1000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MED_XZE")) THEN 
+          med_diag%MED_XZE%dgsave = .TRUE.
+      ELSE 
+          med_diag%MED_XZE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("WIND")) THEN 
+          med_diag%WIND%dgsave = .TRUE.
+      ELSE 
+          med_diag%WIND%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ATM_PCO2")) THEN 
+          med_diag%ATM_PCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%ATM_PCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_PH")) THEN 
+          med_diag%OCN_PH%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_PH%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_PCO2")) THEN 
+          med_diag%OCN_PCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_PCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCNH2CO3")) THEN 
+          med_diag%OCNH2CO3%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCNH2CO3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_HCO3")) THEN 
+          med_diag%OCN_HCO3%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_HCO3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_CO3")) THEN 
+          med_diag%OCN_CO3%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_CO3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("CO2FLUX")) THEN 
+          med_diag%CO2FLUX%dgsave = .TRUE.
+      ELSE 
+          med_diag%CO2FLUX%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OM_CAL")) THEN 
+          med_diag%OM_CAL%dgsave = .TRUE.
+      ELSE 
+          med_diag%OM_CAL%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OM_ARG")) THEN 
+          med_diag%OM_ARG%dgsave = .TRUE.
+      ELSE 
+          med_diag%OM_ARG%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("TCO2")) THEN 
+          med_diag%TCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%TCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("TALK")) THEN 
+          med_diag%TALK%dgsave = .TRUE.
+      ELSE 
+          med_diag%TALK%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("KW660")) THEN 
+          med_diag%KW660%dgsave = .TRUE.
+      ELSE 
+          med_diag%KW660%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ATM_PP0")) THEN 
+          med_diag%ATM_PP0%dgsave = .TRUE.
+      ELSE 
+          med_diag%ATM_PP0%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("O2FLUX")) THEN 
+          med_diag%O2FLUX%dgsave = .TRUE.
+      ELSE 
+          med_diag%O2FLUX%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("O2SAT")) THEN 
+          med_diag%O2SAT%dgsave = .TRUE.
+      ELSE 
+          med_diag%O2SAT%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("CAL_CCD")) THEN 
+          med_diag%CAL_CCD%dgsave = .TRUE.
+      ELSE 
+          med_diag%CAL_CCD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ARG_CCD")) THEN 
+          med_diag%ARG_CCD%dgsave = .TRUE.
+      ELSE 
+          med_diag%ARG_CCD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SFR_OCAL")) THEN 
+          med_diag%SFR_OCAL%dgsave = .TRUE.
+      ELSE 
+          med_diag%SFR_OCAL%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SFR_OARG")) THEN 
+          med_diag%SFR_OARG%dgsave = .TRUE.
+      ELSE 
+          med_diag%SFR_OARG%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("N_PROD")) THEN 
+          med_diag%N_PROD%dgsave = .TRUE.
+      ELSE 
+          med_diag%N_PROD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("N_CONS")) THEN 
+          med_diag%N_CONS%dgsave = .TRUE.
+      ELSE 
+          med_diag%N_CONS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("C_PROD")) THEN 
+          med_diag%C_PROD%dgsave = .TRUE.
+      ELSE 
+          med_diag%C_PROD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("C_CONS")) THEN 
+          med_diag%C_CONS%dgsave = .TRUE.
+      ELSE 
+          med_diag%C_CONS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("O2_PROD")) THEN 
+          med_diag%O2_PROD%dgsave = .TRUE.
+      ELSE 
+          med_diag%O2_PROD%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("O2_CONS")) THEN 
+          med_diag%O2_CONS%dgsave = .TRUE.
+      ELSE 
+          med_diag%O2_CONS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("O2_ANOX")) THEN 
+          med_diag%O2_ANOX%dgsave = .TRUE.
+      ELSE 
+          med_diag%O2_ANOX%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RR_0100")) THEN 
+          med_diag%RR_0100%dgsave = .TRUE.
+      ELSE 
+          med_diag%RR_0100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RR_0500")) THEN 
+          med_diag%RR_0500%dgsave = .TRUE.
+      ELSE 
+          med_diag%RR_0500%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RR_1000")) THEN 
+          med_diag%RR_1000%dgsave = .TRUE.
+      ELSE 
+          med_diag%RR_1000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("IBEN_N")) THEN 
+          med_diag%IBEN_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%IBEN_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("IBEN_FE")) THEN 
+          med_diag%IBEN_FE%dgsave = .TRUE.
+      ELSE 
+          med_diag%IBEN_FE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("IBEN_C")) THEN 
+          med_diag%IBEN_C%dgsave = .TRUE.
+      ELSE 
+          med_diag%IBEN_C%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("IBEN_SI")) THEN 
+          med_diag%IBEN_SI%dgsave = .TRUE.
+      ELSE 
+          med_diag%IBEN_SI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("IBEN_CA")) THEN 
+          med_diag%IBEN_CA%dgsave = .TRUE.
+      ELSE 
+          med_diag%IBEN_CA%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OBEN_N")) THEN 
+          med_diag%OBEN_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%OBEN_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OBEN_FE")) THEN 
+          med_diag%OBEN_FE%dgsave = .TRUE.
+      ELSE 
+          med_diag%OBEN_FE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OBEN_C")) THEN 
+          med_diag%OBEN_C%dgsave = .TRUE.
+      ELSE 
+          med_diag%OBEN_C%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OBEN_SI")) THEN 
+          med_diag%OBEN_SI%dgsave = .TRUE.
+      ELSE 
+          med_diag%OBEN_SI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OBEN_CA")) THEN 
+          med_diag%OBEN_CA%dgsave = .TRUE.
+      ELSE 
+          med_diag%OBEN_CA%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BEN_N")) THEN 
+          med_diag%BEN_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%BEN_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BEN_FE")) THEN 
+          med_diag%BEN_FE%dgsave = .TRUE.
+      ELSE 
+          med_diag%BEN_FE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BEN_C")) THEN 
+          med_diag%BEN_C%dgsave = .TRUE.
+      ELSE 
+          med_diag%BEN_C%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BEN_SI")) THEN 
+          med_diag%BEN_SI%dgsave = .TRUE.
+      ELSE 
+          med_diag%BEN_SI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BEN_CA")) THEN 
+          med_diag%BEN_CA%dgsave = .TRUE.
+      ELSE 
+          med_diag%BEN_CA%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RUNOFF")) THEN 
+          med_diag%RUNOFF%dgsave = .TRUE.
+      ELSE 
+          med_diag%RUNOFF%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RIV_N")) THEN 
+          med_diag%RIV_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%RIV_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RIV_SI")) THEN 
+          med_diag%RIV_SI%dgsave = .TRUE.
+      ELSE 
+          med_diag%RIV_SI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RIV_C")) THEN 
+          med_diag%RIV_C%dgsave = .TRUE.
+      ELSE 
+          med_diag%RIV_C%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("RIV_ALK")) THEN 
+          med_diag%RIV_ALK%dgsave = .TRUE.
+      ELSE 
+          med_diag%RIV_ALK%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DETC")) THEN 
+          med_diag%DETC%dgsave = .TRUE.
+      ELSE 
+          med_diag%DETC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDC__100")) THEN 
+          med_diag%SDC__100%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDC__100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDC__200")) THEN 
+          med_diag%SDC__200%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDC__200%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDC__500")) THEN 
+          med_diag%SDC__500%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDC__500%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("SDC_1000")) THEN 
+          med_diag%SDC_1000%dgsave = .TRUE.
+      ELSE 
+          med_diag%SDC_1000%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INVTC")) THEN 
+          med_diag%INVTC%dgsave = .TRUE.
+      ELSE 
+          med_diag%INVTC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INVTALK")) THEN 
+          med_diag%INVTALK%dgsave = .TRUE.
+      ELSE 
+          med_diag%INVTALK%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INVTO2")) THEN 
+          med_diag%INVTO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%INVTO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("LYSO_CA")) THEN 
+          med_diag%LYSO_CA%dgsave = .TRUE.
+      ELSE 
+          med_diag%LYSO_CA%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("COM_RESP")) THEN 
+          med_diag%COM_RESP%dgsave = .TRUE.
+      ELSE 
+          med_diag%COM_RESP%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PN_LLOSS")) THEN 
+          med_diag%PN_LLOSS%dgsave = .TRUE.
+      ELSE 
+          med_diag%PN_LLOSS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PD_LLOSS")) THEN 
+          med_diag%PD_LLOSS%dgsave = .TRUE.
+      ELSE 
+          med_diag%PD_LLOSS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_LLOSS")) THEN 
+          med_diag%ZI_LLOSS%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_LLOSS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_LLOSS")) THEN 
+          med_diag%ZE_LLOSS%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_LLOSS%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_MES_N")) THEN 
+          med_diag%ZI_MES_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_MES_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_MES_D")) THEN 
+          med_diag%ZI_MES_D%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_MES_D%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_MES_C")) THEN 
+          med_diag%ZI_MES_C%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_MES_C%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_MESDC")) THEN 
+          med_diag%ZI_MESDC%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_MESDC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_EXCR")) THEN 
+          med_diag%ZI_EXCR%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_EXCR%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_RESP")) THEN 
+          med_diag%ZI_RESP%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_RESP%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZI_GROW")) THEN 
+          med_diag%ZI_GROW%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZI_GROW%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_MES_N")) THEN 
+          med_diag%ZE_MES_N%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_MES_N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_MES_D")) THEN 
+          med_diag%ZE_MES_D%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_MES_D%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_MES_C")) THEN 
+          med_diag%ZE_MES_C%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_MES_C%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_MESDC")) THEN 
+          med_diag%ZE_MESDC%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_MESDC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_EXCR")) THEN 
+          med_diag%ZE_EXCR%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_EXCR%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_RESP")) THEN 
+          med_diag%ZE_RESP%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_RESP%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZE_GROW")) THEN 
+          med_diag%ZE_GROW%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZE_GROW%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MDETC")) THEN 
+          med_diag%MDETC%dgsave = .TRUE.
+      ELSE 
+          med_diag%MDETC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMIDC")) THEN 
+          med_diag%GMIDC%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMIDC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("GMEDC")) THEN 
+          med_diag%GMEDC%dgsave = .TRUE.
+      ELSE 
+          med_diag%GMEDC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INT_ZMI")) THEN 
+          med_diag%INT_ZMI%dgsave = .TRUE.
+      ELSE 
+          med_diag%INT_ZMI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INT_ZME")) THEN 
+          med_diag%INT_ZME%dgsave = .TRUE.
+      ELSE 
+          med_diag%INT_ZME%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INT_DET")) THEN 
+          med_diag%INT_DET%dgsave = .TRUE.
+      ELSE 
+          med_diag%INT_DET%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INT_DTC")) THEN 
+          med_diag%INT_DTC%dgsave = .TRUE.
+      ELSE 
+          med_diag%INT_DTC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DMS_SURF")) THEN 
+          med_diag%DMS_SURF%dgsave = .TRUE.
+      ELSE 
+          med_diag%DMS_SURF%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DMS_ANDR")) THEN 
+          med_diag%DMS_ANDR%dgsave = .TRUE.
+      ELSE 
+          med_diag%DMS_ANDR%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DMS_SIMO")) THEN 
+          med_diag%DMS_SIMO%dgsave = .TRUE.
+      ELSE 
+          med_diag%DMS_SIMO%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DMS_ARAN")) THEN 
+          med_diag%DMS_ARAN%dgsave = .TRUE.
+      ELSE 
+          med_diag%DMS_ARAN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DMS_HALL")) THEN 
+          med_diag%DMS_HALL%dgsave = .TRUE.
+      ELSE 
+          med_diag%DMS_HALL%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ATM_XCO2")) THEN 
+          med_diag%ATM_XCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%ATM_XCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_FCO2")) THEN 
+          med_diag%OCN_FCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_FCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ATM_FCO2")) THEN 
+          med_diag%ATM_FCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%ATM_FCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_RHOSW")) THEN 
+          med_diag%OCN_RHOSW%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_RHOSW%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_SCHCO2")) THEN 
+          med_diag%OCN_SCHCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_SCHCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_KWCO2")) THEN 
+          med_diag%OCN_KWCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_KWCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_K0")) THEN 
+          med_diag%OCN_K0%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_K0%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("CO2STARAIR")) THEN 
+          med_diag%CO2STARAIR%dgsave = .TRUE.
+      ELSE 
+          med_diag%CO2STARAIR%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OCN_DPCO2")) THEN 
+          med_diag%OCN_DPCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%OCN_DPCO2%dgsave = .FALSE.
+      ENDIF
+      !!
+      IF  (iom_use("TPP3")) THEN 
+          med_diag%TPP3%dgsave = .TRUE.
+      ELSE 
+          med_diag%TPP3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DETFLUX3")) THEN 
+          med_diag%DETFLUX3%dgsave = .TRUE.
+      ELSE 
+          med_diag%DETFLUX3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REMIN3N")) THEN 
+          med_diag%REMIN3N%dgsave = .TRUE.
+      ELSE 
+          med_diag%REMIN3N%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PH3")) THEN 
+          med_diag%PH3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PH3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("OM_CAL3")) THEN 
+          med_diag%OM_CAL3%dgsave = .TRUE.
+      ELSE 
+          med_diag%OM_CAL3%dgsave = .FALSE.
+      ENDIF
+      !!
+      !!----------------------------------------------------------------------
+      !! AXY (03/11/16): add in additional CMIP6 diagnostics
+      !!----------------------------------------------------------------------
+      !!
+      !! 2D fields
+      IF  (iom_use("epC100")) THEN 
+          med_diag%epC100%dgsave = .TRUE.
+      ELSE 
+          med_diag%epC100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("epCALC100")) THEN 
+          med_diag%epCALC100%dgsave = .TRUE.
+      ELSE 
+          med_diag%epCALC100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("epN100")) THEN 
+          med_diag%epN100%dgsave = .TRUE.
+      ELSE 
+          med_diag%epN100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("epSI100")) THEN 
+          med_diag%epSI100%dgsave = .TRUE.
+      ELSE 
+          med_diag%epSI100%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FGCO2")) THEN 
+          med_diag%FGCO2%dgsave = .TRUE.
+      ELSE 
+          med_diag%FGCO2%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INTDISSIC")) THEN 
+          med_diag%INTDISSIC%dgsave = .TRUE.
+      ELSE 
+          med_diag%INTDISSIC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INTDISSIN")) THEN 
+          med_diag%INTDISSIN%dgsave = .TRUE.
+      ELSE 
+          med_diag%INTDISSIN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INTDISSISI")) THEN 
+          med_diag%INTDISSISI%dgsave = .TRUE.
+      ELSE 
+          med_diag%INTDISSISI%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("INTTALK")) THEN 
+          med_diag%INTTALK%dgsave = .TRUE.
+      ELSE 
+          med_diag%INTTALK%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("O2min")) THEN 
+          med_diag%O2min%dgsave = .TRUE.
+      ELSE 
+          med_diag%O2min%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("ZO2min")) THEN 
+          med_diag%ZO2min%dgsave = .TRUE.
+      ELSE 
+          med_diag%ZO2min%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FBDDTALK")) THEN 
+          med_diag%FBDDTALK%dgsave = .TRUE.
+      ELSE 
+          med_diag%FBDDTALK%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FBDDTDIC")) THEN 
+          med_diag%FBDDTDIC%dgsave = .TRUE.
+      ELSE 
+          med_diag%FBDDTDIC%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FBDDTDIFE")) THEN 
+          med_diag%FBDDTDIFE%dgsave = .TRUE.
+      ELSE 
+          med_diag%FBDDTDIFE%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FBDDTDIN")) THEN 
+          med_diag%FBDDTDIN%dgsave = .TRUE.
+      ELSE 
+          med_diag%FBDDTDIN%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FBDDTDISI")) THEN 
+          med_diag%FBDDTDISI%dgsave = .TRUE.
+      ELSE 
+          med_diag%FBDDTDISI%dgsave = .FALSE.
+      ENDIF
+      !!
+      !! 3D
+      IF  (iom_use("TPPD3")) THEN 
+          med_diag%TPPD3%dgsave = .TRUE.
+      ELSE 
+          med_diag%TPPD3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BDDTALK3")) THEN 
+          med_diag%BDDTALK3%dgsave = .TRUE.
+      ELSE 
+          med_diag%BDDTALK3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BDDTDIC3")) THEN 
+          med_diag%BDDTDIC3%dgsave = .TRUE.
+      ELSE 
+          med_diag%BDDTDIC3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BDDTDIFE3")) THEN 
+          med_diag%BDDTDIFE3%dgsave = .TRUE.
+      ELSE 
+          med_diag%BDDTDIFE3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BDDTDIN3")) THEN 
+          med_diag%BDDTDIN3%dgsave = .TRUE.
+      ELSE 
+          med_diag%BDDTDIN3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BDDTDISI3")) THEN 
+          med_diag%BDDTDISI3%dgsave = .TRUE.
+      ELSE 
+          med_diag%BDDTDISI3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FD_NIT3")) THEN 
+          med_diag%FD_NIT3%dgsave = .TRUE.
+      ELSE 
+          med_diag%FD_NIT3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FD_SIL3")) THEN 
+          med_diag%FD_SIL3%dgsave = .TRUE.
+      ELSE 
+          med_diag%FD_SIL3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FD_CAR3")) THEN 
+          med_diag%FD_CAR3%dgsave = .TRUE.
+      ELSE 
+          med_diag%FD_CAR3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FD_CAL3")) THEN 
+          med_diag%FD_CAL3%dgsave = .TRUE.
+      ELSE 
+          med_diag%FD_CAL3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("CO33")) THEN 
+          med_diag%CO33%dgsave = .TRUE.
+      ELSE 
+          med_diag%CO33%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("CO3SATARAG3")) THEN 
+          med_diag%CO3SATARAG3%dgsave = .TRUE.
+      ELSE 
+          med_diag%CO3SATARAG3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("CO3SATCALC3")) THEN 
+          med_diag%CO3SATCALC3%dgsave = .TRUE.
+      ELSE 
+          med_diag%CO3SATCALC3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("DCALC3")) THEN 
+          med_diag%DCALC3%dgsave = .TRUE.
+      ELSE 
+          med_diag%DCALC3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("EXPC3")) THEN 
+          med_diag%EXPC3%dgsave = .TRUE.
+      ELSE 
+          med_diag%EXPC3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("EXPN3")) THEN 
+          med_diag%EXPN3%dgsave = .TRUE.
+      ELSE 
+          med_diag%EXPN3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FEDISS3")) THEN 
+          med_diag%FEDISS3%dgsave = .TRUE.
+      ELSE 
+          med_diag%FEDISS3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("FESCAV3")) THEN 
+          med_diag%FESCAV3%dgsave = .TRUE.
+      ELSE 
+          med_diag%FESCAV3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MIGRAZP3")) THEN 
+          med_diag%MIGRAZP3%dgsave = .TRUE.
+      ELSE 
+          med_diag%MIGRAZP3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MIGRAZD3")) THEN 
+          med_diag%MIGRAZD3%dgsave = .TRUE.
+      ELSE 
+          med_diag%MIGRAZD3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MEGRAZP3")) THEN 
+          med_diag%MEGRAZP3%dgsave = .TRUE.
+      ELSE 
+          med_diag%MEGRAZP3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MEGRAZD3")) THEN 
+          med_diag%MEGRAZD3%dgsave = .TRUE.
+      ELSE 
+          med_diag%MEGRAZD3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("MEGRAZZ3")) THEN 
+          med_diag%MEGRAZZ3%dgsave = .TRUE.
+      ELSE 
+          med_diag%MEGRAZZ3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("O2SAT3")) THEN 
+          med_diag%O2SAT3%dgsave = .TRUE.
+      ELSE 
+          med_diag%O2SAT3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PBSI3")) THEN 
+          med_diag%PBSI3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PBSI3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PCAL3")) THEN 
+          med_diag%PCAL3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PCAL3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("REMOC3")) THEN 
+          med_diag%REMOC3%dgsave = .TRUE.
+      ELSE 
+          med_diag%REMOC3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PNLIMJ3")) THEN 
+          med_diag%PNLIMJ3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PNLIMJ3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PNLIMN3")) THEN 
+          med_diag%PNLIMN3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PNLIMN3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PNLIMFE3")) THEN 
+          med_diag%PNLIMFE3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PNLIMFE3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PDLIMJ3")) THEN 
+          med_diag%PDLIMJ3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PDLIMJ3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PDLIMN3")) THEN 
+          med_diag%PDLIMN3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PDLIMN3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PDLIMFE3")) THEN 
+          med_diag%PDLIMFE3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PDLIMFE3%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("PDLIMSI3")) THEN 
+          med_diag%PDLIMSI3%dgsave = .TRUE.
+      ELSE 
+          med_diag%PDLIMSI3%dgsave = .FALSE.
+      ENDIF
+
+   END SUBROUTINE   trc_nam_iom_medusa
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                             No MEDUSA
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nam_medusa                      ! Empty routine
+   END  SUBROUTINE  trc_nam_medusa
+#endif  
+
+   !!======================================================================
+END MODULE trcnam_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90_save
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90_save	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90_save	(revision 7693)
@@ -0,0 +1,1096 @@
+MODULE trcnam_medusa
+   !!======================================================================
+   !!                      ***  MODULE trcnam_medusa  ***
+   !! TOP :   initialisation of some run parameters for MEDUSA bio-model
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!              -   !  2013-05  (A. Yool) renamed (from trclsm) for v3.5
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'   :                                       MEDUSA model
+   !!----------------------------------------------------------------------
+   !! trc_nam_medusa      : MEDUSA model initialisation
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE sms_medusa      ! sms trends
+   USE iom             ! I/O manager
+
+   !! AXY (04/02/14): necessary to find NaNs on HECTOR
+   USE, INTRINSIC :: ieee_arithmetic 
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_nam_medusa   ! called by trcnam.F90 module
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id: trcnam_medusa.F90 1162 2008-07-02 09:33:33Z cetlod $ 
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_nam_medusa
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_nam_medusa  ***  
+      !!
+      !! ** Purpose :   read MEDUSA namelist
+      !!
+      !! ** input   :   file 'namelist.trc.sms' containing the following
+      !!             namelist: natbio, natopt, and natdbi ("key_trc_diabio")
+      !!
+      !! ekp: namelist nabio contains ALL parameters of the ecosystem 
+      !!      point sourses and sinks PLUS sediment exchange
+      !!      dia_bio - used by Lobster to output all point terms 
+      !!                (sourses and sinks of bio)
+      !!      dia_add - additional diagnostics for biology such as 
+      !!                primary production (2d depth integrated field or 3d)
+      !!----------------------------------------------------------------------
+      !!
+      INTEGER            :: ji,jj,jk
+      REAL(wp)           :: fthk, fdep, fdep1
+      REAL(wp)           :: q1, q2, q3
+      !
+      NAMELIST/natbio/ xxi,xaln,xald,jphy,xvpn,xvpd,          &
+      &    xsin0,xnsi0,xuif,jliebig,                          &
+      &    xthetam,xthetamd,xnln,xnld,xsld,xfln,xfld,         &
+      &  xgmi,xgme,xkmi,xkme,xphi,xbetan,xbetac,xkc,          &
+      &    xpmipn,xpmid,xpmepn,xpmepd,xpmezmi,xpmed,          &
+      &  xmetapn,xmetapd,xmetazmi,xmetazme,                   &
+      &  jmpn,xmpn,xkphn,jmpd,xmpd,xkphd,jmzmi,xmzmi,xkzmi,   &
+      &    jmzme,xmzme,xkzme,jmd,jsfd,xmd,xmdc,               &
+      &  xthetapn,xthetapd,xthetazmi,xthetazme,xthetad,       &
+      &    xrfn,xrsn,vsed,xhr,                                &
+      &  jiron,xfe_mass,xfe_sol,xfe_sed,xLgT,xk_FeL,xk_sc_Fe, &
+      &  jexport,jfdfate,jrratio,jocalccd,xridg_r0,           &
+      &    xfdfrac1,xfdfrac2,xfdfrac3,                        &
+      &    xcaco3a,xcaco3b,xmassc,xmassca,xmasssi,xprotca,    &
+      &    xprotsi,xfastc,xfastca,xfastsi,                    &
+      &  jorgben,jinorgben,xsedn,xsedfe,xsedsi,xsedc,xsedca,  &
+      &    xburial,                                           &
+      &  jriver_n,jriver_si,jriver_c,jriver_alk,jriver_dep,   &
+      &    friver_dep,                                        &
+      &  xsdiss,                                              &
+      &  vsed,xhr,                                            &
+      &  sedlam,sedlostpoc,jpkb,jdms
+#if defined key_roam
+      NAMELIST/natroam/ xthetaphy,xthetazoo,xthetanit,        &
+      &    xthetarem,xo2min,                                  &
+      &    f3_pH,f3_h2co3,f3_hco3,f3_co3,f3_omcal,f3_omarg,   &
+      &    f2_ccd_cal,f2_ccd_arg
+#endif
+      NAMELIST/natopt/xkg0,xkr0,xkgp,xkrp,xlg,xlr,rpig
+      INTEGER :: jl, jn
+      TYPE(DIAG), DIMENSION(jp_medusa_2d)  :: meddia2d
+      TYPE(DIAG), DIMENSION(jp_medusa_3d)  :: meddia3d
+      TYPE(DIAG), DIMENSION(jp_medusa_trd) :: meddiabio
+      CHARACTER(LEN=32)   ::   clname
+      !!
+      NAMELIST/nammeddia/ meddia3d, meddia2d     ! additional diagnostics
+
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      clname = 'namelist_medusa'
+      IF(lwp) WRITE(numout,*) ' trc_nam_medusa: read MEDUSA namelist'
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+
+
+      CALL ctl_opn( numnatm, TRIM( clname ), 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
+
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'open namelist_medusa -- OK'
+      IF (lwp) write (numout,*) 'Now, read namilists inside :'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+!     IF( .NOT.lk_iomput .AND. ln_diatrc ) THEN
+! should be done via iom_put exclusively but there are a lot of them; this is the easy first attempt !
+         !
+         ! Namelist nammeddia
+         ! -------------------
+         DO jl = 1, jp_medusa_2d
+            WRITE(meddia2d(jl)%sname,'("2D_",I1)') jl                      ! short name
+            WRITE(meddia2d(jl)%lname,'("2D DIAGNOSTIC NUMBER ",I2)') jl    ! long name
+            meddia2d(jl)%units = ' '                                       ! units
+         END DO
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+         !                                 ! 3D output arrays
+         DO jl = 1, jp_medusa_3d
+            WRITE(meddia3d(jl)%sname,'("3D_",I1)') jl                      ! short name
+            WRITE(meddia3d(jl)%lname,'("3D DIAGNOSTIC NUMBER ",I2)') jl    ! long name
+            meddia3d(jl)%units = ' '                                       ! units
+         END DO
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Just before reading namelist_medusa :: nammeddia'
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+
+         REWIND( numnatm )               !
+         READ  ( numnatm, nammeddia )
+
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'reading namelist_medusa :: nammeddia OK'
+      IF (lwp) write (numout,*) 'Check number of variable in nammeddia:'
+      IF (lwp) write (numout,*) 'jp_medusa_2d: ',jp_medusa_2d ,'jp_medusa_3d: ',jp_medusa_3d
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+         DO jl = 1, jp_medusa_2d
+            jn = jp_msa0_2d + jl - 1
+            ctrc2d(jn) = meddia2d(jl)%sname
+            ctrc2l(jn) = meddia2d(jl)%lname
+            ctrc2u(jn) = meddia2d(jl)%units
+         END DO
+
+         DO jl = 1, jp_medusa_3d
+            jn = jp_msa0_3d + jl - 1
+            ctrc3d(jn) = meddia3d(jl)%sname
+            ctrc3l(jn) = meddia3d(jl)%lname
+            ctrc3u(jn) = meddia3d(jl)%units
+         END DO
+
+         IF(lwp) THEN                   ! control print
+# if defined key_debug_medusa
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Var name assignation OK'
+      IF (lwp) write (numout,*) 'next check var names'
+      IF (lwp) write (numout,*) ' '
+            CALL flush(numout)
+# endif
+            WRITE(numout,*)
+            WRITE(numout,*) ' Namelist : natadd'
+            DO jl = 1, jp_medusa_3d
+               jn = jp_msa0_3d + jl - 1
+               WRITE(numout,*) '  3d diag nb : ', jn, '    short name : ', ctrc3d(jn), &
+                 &             '  long name  : ', ctrc3l(jn), '   unit : ', ctrc3u(jn)
+            END DO
+            WRITE(numout,*) ' '
+
+            DO jl = 1, jp_medusa_2d
+               jn = jp_msa0_2d + jl - 1
+               WRITE(numout,*) '  2d diag nb : ', jn, '    short name : ', ctrc2d(jn), &
+                 &             '  long name  : ', ctrc2l(jn), '   unit : ', ctrc2u(jn)
+            END DO
+            WRITE(numout,*) ' '
+         ENDIF
+         !
+# if defined key_debug_medusa
+            CALL flush(numout)
+# endif
+
+!     ENDIF
+
+      ! 1.4 namelist natbio : biological parameters
+      ! -------------------------------------------
+      
+      xxi         = 0.
+      xaln        = 0.
+      xald        = 0.
+      jphy        = 0
+      xvpn        = 0.
+      xvpd        = 0.
+      xthetam     = 0.
+      xthetamd    = 0.
+!!
+      xsin0       = 0.
+      xnsi0       = 0.
+      xuif        = 0.
+!!
+      jliebig     = 0
+      xnln        = 0.
+      xnld        = 0.
+      xsld        = 0.
+      xfln        = 0.
+      xfld        = 0.
+!!
+      xgmi        = 0.
+      xgme        = 0.
+      xkmi        = 0.
+      xkme        = 0.
+      xphi	  = 0.
+      xbetan      = 0.
+      xbetac      = 0.
+      xkc         = 0.
+      xpmipn      = 0.
+      xpmid       = 0.
+      xpmepn      = 0.
+      xpmepd      = 0.
+      xpmezmi     = 0.
+      xpmed       = 0.
+!!
+      xmetapn     = 0.
+      xmetapd     = 0.
+      xmetazmi    = 0.
+      xmetazme    = 0.
+!!
+      jmpn        = 0
+      xmpn        = 0.
+      xkphn       = 0.
+      jmpd        = 0
+      xmpd        = 0.
+      xkphd       = 0.
+      jmzmi       = 0
+      xmzmi       = 0.
+      xkzmi       = 0.
+      jmzme       = 0
+      xmzme       = 0.
+      xkzme       = 0.
+!!
+      jmd         = 0
+      jsfd        = 0
+      xmd         = 0.
+      xmdc        = 0.
+!!
+      xthetapn    = 0.
+      xthetapd    = 0.
+      xthetazmi   = 0.
+      xthetazme   = 0.
+      xthetad     = 0.
+      xrfn        = 0.
+      xrsn        = 0.  !: (NOT USED HERE; RETAINED FOR LOBSTER)
+!!
+      jiron       = 0
+      xfe_mass    = 0.
+      xfe_sol     = 0.
+      xfe_sed     = 0.
+      xLgT        = 0.
+      xk_FeL	  = 0.
+      xk_sc_Fe    = 0.
+!!
+      jexport     = 0
+      jfdfate     = 0
+      jrratio     = 0
+      jocalccd    = 0
+      xridg_r0    = 0.
+      xfdfrac1	  = 0.
+      xfdfrac2	  = 0.
+      xfdfrac3	  = 0.
+      xcaco3a	  = 0.
+      xcaco3b	  = 0.
+      xmassc	  = 0.
+      xmassca	  = 0.
+      xmasssi	  = 0.
+      xprotca	  = 0.
+      xprotsi	  = 0.
+      xfastc	  = 0.
+      xfastca	  = 0.
+      xfastsi	  = 0.
+!!
+      jorgben     = 0
+      jinorgben   = 0
+      xsedn       = 0.
+      xsedfe      = 0.
+      xsedsi      = 0.
+      xsedc       = 0.
+      xsedca      = 0.
+      xburial     = 0.
+!!
+      jriver_n    = 0
+      jriver_si   = 0
+      jriver_c    = 0
+      jriver_alk  = 0
+      jriver_dep  = 1
+!!
+      xsdiss	  = 0.
+!!
+      vsed        = 0.
+      xhr         = 0.
+!!
+      sedlam	  = 0.
+      sedlostpoc  = 0.
+      jpkb	  = 0.
+      jdms        = 0
+            
+      REWIND(numnatm)
+      READ(numnatm,natbio)
+
+!! Primary production and chl related quantities
+!!       xxi         :  conversion factor from gC to mmolN 
+!!       xaln        :  Chl-a specific initial slope of P-I curve for non-diatoms 
+!!       xald        :  Chl-a specific initial slope of P-I curve for diatoms
+!!       jphy        :  phytoplankton T-dependent growth switch
+!!       xvpn        :  maximum growth rate for non-diatoms
+!!       xvpd        :  maximum growth rate for diatoms
+!!       xthetam     :  maximum Chl to C ratio for non-diatoms      
+!!       xthetamd    :  maximum Chl to C ratio for diatoms      
+!!
+!! Diatom silicon parameters
+!!       xsin0       :  minimum diatom Si:N ratio
+!!       xnsi0       :  minimum diatom N:Si ratio
+!!       xuif        :  hypothetical growth ratio at infinite Si:N ratio
+!!
+!! Nutrient limitation
+!!       jliebig     :  Liebig nutrient uptake switch
+!!       xnln        :  half-sat constant for DIN uptake by non-diatoms 
+!!       xnld        :  half-sat constant for DIN uptake by diatoms 
+!!       xsl         :  half-sat constant for Si uptake by diatoms 
+!!       xfld        :  half-sat constant for Fe uptake by diatoms  
+!!       xfln        :  half-sat constant for Fe uptake by non-datoms 
+!!
+!! Grazing
+!!       xgmi        :  microzoo maximum growth rate 
+!!       xgme        :  mesozoo maximum growth rate 
+!!       xkmi        :  microzoo grazing half-sat parameter
+!!       xkme        :  mesozoo grazing half-sat parameter
+!!       xphi        :  micro/mesozoo grazing inefficiency
+!!       xbetan      :  micro/mesozoo N assimilation efficiency
+!!       xbetac      :  micro/mesozoo C assimilation efficiency
+!!       xkc         :  micro/mesozoo net C growth efficiency
+!!       xpmipn      :  grazing preference of microzoo for non-diatoms
+!!       xpmid       :  grazing preference of microzoo for diatoms
+!!       xpmepn      :  grazing preference of mesozoo for non-diatoms 
+!!       xpmepd      :  grazing preference of mesozoo for diatoms
+!!       xpmezmi     :  grazing preference of mesozoo for microzoo
+!!       xpmed       :  grazing preference of mesozoo for detritus
+!!
+!! Metabolic losses
+!!       xmetapn     :  non-diatom metabolic loss rate
+!!       xmetapd     :  diatom     metabolic loss rate
+!!       xmetazmi    :  microzoo   metabolic loss rate
+!!       xmetazme    :  mesozoo    metabolic loss rate
+!!
+!! Mortality/Remineralisation
+!!       jmpn        :  non-diatom mortality functional form
+!!       xmpn        :  non-diatom mortality rate
+!!       xkphn       :  non-diatom mortality half-sat constant
+!!       jmpd        :  diatom     mortality functional form
+!!       xmpd        :  diatom mortality rate
+!!       xkphd       :  diatom mortality half-sat constant
+!!       jmzmi       :  microzoo   mortality functional form
+!!       xmzmi       :  microzoo mortality rate
+!!       xkzmi       :  microzoo mortality half-sat constant
+!!       jmzme       :  mesozoo    mortality functional form
+!!       xmzme       :  mesozoo mortality rate
+!!       xkzme       :  mesozoo mortality half-sat constant
+!!
+!! Remineralisation
+!!       jmd         :  detritus T-dependent remineralisation switch
+!!       jsfd        :  accelerate seafloor detritus remin. switch
+!!       xmd         :  detrital nitrogen remineralisation rate 
+!!       xmdc        :  detrital carbon remineralisation rate 
+!!
+!! Stochiometric ratios
+!!       xthetapn    :  non-diatom C:N ratio
+!!       xthetapd    :  diatom C:N ratio
+!!       xthetazmi   :  microzoo C:N ratio
+!!       xthetazme   :  mesozoo C:N ratio
+!!       xthetad     :  detritus C:N ratio
+!!       xrfn        :  phytoplankton Fe:N ratio
+!!	 xrsn        :  diatom Si:N ratio (*NOT* used)
+!!
+!! Iron parameters
+!!       jiron       :  iron scavenging submodel switch
+!!       xfe_mass    :  iron atomic mass
+!!	 xfe_sol     :  aeolian iron solubility
+!!	 xfe_sed     :  sediment iron input
+!!	 xLgT	     :  total ligand concentration (umol/m3)
+!!	 xk_FeL	     :  dissociation constant for (Fe + L)
+!!	 xk_sc_Fe    :  scavenging rate of "free" iron
+!!	 
+!! Fast-sinking detritus parameters
+!!       jexport     :  fast detritus remineralisation switch
+!!       jfdfate     :  fate of fast detritus at seafloor switch
+!!       jrratio     :  rain ratio switch
+!!       jocalccd    :  CCD switch
+!!       xridg_r0    :  Ridgwell rain ratio coefficient
+!!       xfdfrac1    :  fast-sinking fraction of diatom nat. mort. losses
+!!       xfdfrac2    :  fast-sinking fraction of meszooplankton mort. losses
+!!       xfdfrac3    :  fast-sinking fraction of diatom silicon grazing losses
+!!       xcaco3a     :  polar (high latitude) CaCO3 fraction
+!!       xcaco3b     :  equatorial (low latitude) CaCO3 fraction
+!!       xmassc      :  organic C mass:mole ratio, C106 H175 O40 N16 P1
+!!       xmassca     :  calcium carbonate mass:mole ratio, CaCO3
+!!       xmasssi     :  biogenic silicon mass:mole ratio, (H2SiO3)n
+!!       xprotca     :  calcium carbonate protection ratio
+!!       xprotsi     :  biogenic silicon protection ratio
+!!       xfastc      :  organic C remineralisation length scale
+!!       xfastca     :  calcium carbonate dissolution length scale
+!!       xfastsi     :  biogenic silicon dissolution length scale
+!!
+!! Benthic 
+!!       jorgben     :  does   organic detritus go to the benthos?
+!!       jinorgben   :  does inorganic detritus go to the benthos?
+!!       xsedn       :  organic   nitrogen sediment remineralisation rate 
+!!       xsedfe      :  organic   iron     sediment remineralisation rate 
+!!       xsedsi      :  inorganic silicon  sediment dissolution      rate 
+!!       xsedc       :  organic   carbon   sediment remineralisation rate 
+!!       xsedca      :  inorganic carbon   sediment dissolution      rate 
+!!       xburial     :  burial rate of seafloor detritus
+!!
+!! Riverine inputs
+!!       jriver_n    :  riverine N          input?
+!!       jriver_si   :  riverine Si         input?
+!!       jriver_c    :  riverine C          input?
+!!       jriver_alk  :  riverine alkalinity input?
+!!       jriver_dep  :  depth of riverine   input?
+!!
+!! Miscellaneous
+!!       xsdiss      :  diatom frustule dissolution rate
+!!
+!! Gravitational sinking      
+!!       vsed        :  detritus gravitational sinking rate 
+!!       xhr         :  coeff for Martin's remineralisation profile
+!!
+!! Additional parameters
+!!       sedlam      :  time coeff of POC in sediments
+!!      sedlostpoc   :  sediment geol loss for POC
+!!       jpkb        :  vertical layer for diagnostic of the vertical flux 
+!!                      NOTE that in LOBSTER it is a first vertical layers where 
+!!                      biology is active  
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+!!       jdms        :  include dms diagnostics
+!!
+!!
+!!
+
+      IF(lwp) THEN
+!!
+!! AXY (08/11/13): compilation key notification
+         WRITE(numout,*) '=== Compilation keys'
+#if defined key_roam
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_roam                                                               = INACTIVE'
+#endif        
+#if defined key_axy_carbchem
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_carbchem                                                       = INACTIVE'
+#endif        
+#if defined key_bs_axy_zforce
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_zforce                                                      = INACTIVE'
+#endif        
+#if defined key_bs_axy_yrlen
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_bs_axy_yrlen                                                       = INACTIVE'
+#endif        
+#if defined key_deep_fe_fix
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_deep_fe_fix                                                        = INACTIVE'
+#endif        
+#if defined key_axy_nancheck
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_nancheck                                                       = INACTIVE'
+#endif        
+# if defined key_axy_pi_co2
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = ACTIVE'
+#else
+         WRITE(numout,*)     &
+         &   ' key_axy_pi_co2                                                         = INACTIVE'
+# endif
+         WRITE(numout,*) ' '
+
+         WRITE(numout,*) 'natbio'
+         WRITE(numout,*) ' '
+!!
+!! Primary production and chl related quantities
+         WRITE(numout,*) '=== Primary production'
+         WRITE(numout,*)     &
+         &   ' conversion factor from gC to mmolN,                        xxi         =', xxi
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for non-diatoms, xaln        = ', xaln
+         WRITE(numout,*)     &
+         &   ' Chl-a specific initial slope of P-I curve for diatoms,     xald        = ', xald
+         if (jphy.eq.1) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-dependent*            jphy        = ', jphy
+         elseif (jphy.eq.0) then
+            WRITE(numout,*) &
+            &   ' phytoplankton growth is *temperature-independent*          jphy        = ', jphy
+         endif
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for non-diatoms,                       xvpn        = ', xvpn
+         WRITE(numout,*)     &
+         &   ' maximum growth rate for diatoms,                           xvpn        = ', xvpd
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for non-diatoms,                    xthetam     = ', xthetam
+         WRITE(numout,*)     &
+         &   ' maximum Chl to C ratio for diatoms,                        xthetamd    = ', xthetamd
+!!
+!! Diatom silicon parameters
+         WRITE(numout,*) '=== Diatom silicon parameters'
+         WRITE(numout,*)     &
+         &   ' minimum diatom Si:N ratio,                                 xsin0       = ', xsin0
+         WRITE(numout,*)     &
+         &   ' minimum diatom N:Si ratio,                                 xnsi0       = ', xnsi0
+         WRITE(numout,*)     &
+         &   ' hypothetical growth ratio at infinite Si:N ratio,          xuif        = ', xuif
+!!
+!! Nutrient limitation
+         WRITE(numout,*) '=== Nutrient limitation'
+         if (jliebig.eq.1) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a Liebig Law (= most limiting) function jliebig     = ', jliebig
+         elseif (jliebig.eq.0) then
+            WRITE(numout,*) &
+            &   ' nutrient uptake is a multiplicative function               jliebig     = ', jliebig
+         endif
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by non-diatoms,           xnln        = ', xnln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for DIN uptake by diatoms,               xnld        = ', xnld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Si uptake by diatoms,                xsld        = ', xsld
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by non-diatoms,            xfln        = ', xfln
+         WRITE(numout,*)     &
+         &   ' half-sat constant for Fe uptake by diatoms,                xfld        = ', xfld
+!!
+!! Grazing
+         WRITE(numout,*) '=== Zooplankton grazing'
+         WRITE(numout,*)     &
+         &   ' microzoo maximum growth rate,                              xgmi        = ', xgmi
+         WRITE(numout,*)     &
+         &   ' mesozoo maximum growth rate,                               xgme        = ', xgme
+         WRITE(numout,*)     &
+         &   ' microzoo grazing half-sat parameter,                       xkmi        = ', xkmi
+         WRITE(numout,*)     &
+         &   ' mesozoo grazing half-sat parameter,                        xkme        = ', xkme
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo grazing inefficiency,                        xphi        = ', xphi
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo N assimilation efficiency,                   xbetan      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo C assimilation efficiency,                   xbetac      = ', xbetan
+         WRITE(numout,*)     &
+         &   ' micro/mesozoo net C growth efficiency,                     xkc         = ', xkc
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for non-diatoms,            xpmipn      = ', xpmipn
+         WRITE(numout,*)     &
+         &   ' grazing preference of microzoo for detritus,               xpmid       = ', xpmid
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for non-diatoms,             xpmepn      = ', xpmepn
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for diatoms,                 xpmepd      = ', xpmepd
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for microzoo,                xpmezmi     = ', xpmezmi
+         WRITE(numout,*)     &
+         &   ' grazing preference of mesozoo for detritus,                xpmed       = ', xpmed
+!!
+!! Metabolic losses
+         WRITE(numout,*) '=== Metabolic losses'
+         WRITE(numout,*)     &
+         &   ' non-diatom metabolic loss rate,                            xmetapn     = ', xmetapn
+         WRITE(numout,*)     &
+         &   ' diatom     metabolic loss rate,                            xmetapd     = ', xmetapd
+         WRITE(numout,*)     &
+         &   ' microzoo   metabolic loss rate,                            xmetazmi    = ', xmetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo    metabolic loss rate,                            xmetazme    = ', xmetazme
+!!
+!! Mortality losses
+         WRITE(numout,*) '=== Mortality losses'
+         if (jmpn.eq.1) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,            LINEAR    jmpn        = ', jmpn
+         elseif (jmpn.eq.2) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,         QUADRATIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.3) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,        HYPERBOLIC    jmpn        = ', jmpn
+         elseif (jmpn.eq.4) then
+            WRITE(numout,*)     &
+            &   ' non-diatom mortality functional form,           SIGMOID    jmpn        = ', jmpn
+         endif
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality rate,                                 xmpn        = ', xmpn
+         WRITE(numout,*)     &
+         &   ' non-diatom mortality half-sat constant                     xkphn       = ', xkphn
+         if (jmpd.eq.1) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,                LINEAR    jmpd        = ', jmpd
+         elseif (jmpd.eq.2) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,             QUADRATIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.3) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,            HYPERBOLIC    jmpd        = ', jmpd
+         elseif (jmpd.eq.4) then
+            WRITE(numout,*)     &
+            &   ' diatom mortality functional form,               SIGMOID    jmpd        = ', jmpd
+         endif
+         WRITE(numout,*)     &
+         &   ' diatom mortality rate,                                     xmpd        = ', xmpd
+         WRITE(numout,*)     &
+         &   ' diatom mortality half-sat constant                         xkphd       = ', xkphd
+         if (jmzmi.eq.1) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,              LINEAR    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.2) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,           QUADRATIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.3) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,          HYPERBOLIC    jmzmi       = ', jmzmi
+         elseif (jmzmi.eq.4) then
+            WRITE(numout,*)     &
+            &   ' microzoo mortality functional form,             SIGMOID    jmzmi       = ', jmzmi
+         endif
+         WRITE(numout,*)     &
+         &   ' microzoo mortality rate,                                   xmzmi       = ', xmzmi
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzmi       = ', xkzmi
+         if (jmzme.eq.1) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,               LINEAR    jmzme       = ', jmzme
+         elseif (jmzme.eq.2) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,            QUADRATIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.3) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,           HYPERBOLIC    jmzme       = ', jmzme
+         elseif (jmzme.eq.4) then
+            WRITE(numout,*)     &
+            &   ' mesozoo mortality functional form,              SIGMOID    jmzme       = ', jmzme
+         endif
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality rate,                                    xmzme       = ', xmzme
+         WRITE(numout,*)     &
+         &   ' mesozoo mortality half-sat constant,                       xkzme       = ', xkzme
+!!
+!! Remineralisation
+         WRITE(numout,*) '=== Remineralisation'
+         if (jmd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-dependent*       jmd         = ', jmd
+         elseif (jmd.eq.0) then
+            WRITE(numout,*) &
+            &   ' detritus remineralisation is *temperature-independent*     jmd         = ', jmd
+         endif
+         if (jsfd.eq.1) then
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation is *accelerated*        jsfd        = ', jsfd
+         else
+            WRITE(numout,*) &
+            &   ' detritus seafloor remineralisation occurs at same rate     jsfd        = ', jsfd
+         endif
+         WRITE(numout,*)     &
+         &   ' detrital nitrogen remineralisation rate,                   xmd         = ', xmd
+         WRITE(numout,*)     &
+         &   ' detrital carbon remineralisation rate,                     xmdc        = ', xmdc
+!!
+!! Stochiometric ratios
+         WRITE(numout,*) '=== Stoichiometric ratios'
+         WRITE(numout,*)     &
+         &   ' non-diatom C:N ratio,                                      xthetapn    = ', xthetapn
+         WRITE(numout,*)     &
+         &   ' diatom C:N ratio,                                          xthetapd    = ', xthetapd
+         WRITE(numout,*)     &
+         &   ' microzoo C:N ratio,                                        xthetazmi   = ', xthetazmi
+         WRITE(numout,*)     &
+         &   ' mesozoo C:N ratio,                                         xthetazme   = ', xthetazme
+         WRITE(numout,*)     &
+         &   ' detritus C:N ratio,                                        xthetad     = ', xthetad
+         WRITE(numout,*)     &
+         &   ' phytoplankton Fe:N ratio,                                  xrfn        = ', xrfn
+         WRITE(numout,*)     &
+         &   ' diatom Si:N ratio,                                         xrsn        = ', xrsn
+!!	  
+!! Iron parameters
+         WRITE(numout,*) '=== Iron parameters'
+         if (jiron.eq.1) then
+            WRITE(numout,*)     &
+            &   ' Dutkiewicz et al. (2005) iron scavenging                   jiron       = ', jiron
+         elseif (jiron.eq.2) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2004) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.3) then
+            WRITE(numout,*)     &
+            &   ' Moore et al. (2008) iron scavenging                        jiron       = ', jiron
+         elseif (jiron.eq.4) then
+            WRITE(numout,*)     &
+            &   ' Galbraith et al. (2010) iron scavenging                    jiron       = ', jiron
+         else
+            WRITE(numout,*)     &
+            &   ' There is **no** iron scavenging                            jiron       = ', jiron
+         endif
+         WRITE(numout,*)     &
+         &   ' iron atomic mass,                                          xfe_mass    = ', xfe_mass
+         WRITE(numout,*)     &
+         &   ' aeolian iron solubility,                                   xfe_sol     = ', xfe_sol
+         WRITE(numout,*)     &
+         &   ' sediment iron input,                                       xfe_sed     = ', xfe_sed
+         WRITE(numout,*)     &
+         &   ' total ligand concentration (umol/m3),                      xLgT        = ', xLgT
+         WRITE(numout,*)     &
+         &   ' dissociation constant for (Fe + L),                        xk_FeL      = ', xk_FeL
+         WRITE(numout,*)     &
+         &   ' scavenging rate for free iron,                             xk_sc_Fe    = ', xk_sc_Fe
+!!
+!! Fast-sinking detritus parameters
+         WRITE(numout,*) '=== Fast-sinking detritus'
+         if (jexport.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Dunne et al. (2007; ballast)     jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Martin et al. (1987)             jexport     = ', jexport
+         elseif (jexport.eq.2) then
+            WRITE(numout,*) &
+            &   ' fast-detritus remin. uses Henson et al. (2011)             jexport     = ', jexport
+         endif
+         if (jfdfate.eq.1) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor becomes slow-detritus      jfdfate     = ', jfdfate
+         elseif (jfdfate.eq.0) then
+            WRITE(numout,*) &
+            &   ' fast-detritus reaching seafloor instantly remineralised    jfdfate     = ', jfdfate
+         endif
+#if defined key_roam
+         if (jrratio.eq.0) then
+            WRITE(numout,*) &
+            &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+         elseif (jrratio.eq.1) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (surface omega) jrratio     = ', jrratio
+         elseif (jrratio.eq.2) then
+            WRITE(numout,*) &
+            &   ' Ridgwell et al. (2007) rain ratio submodel (3D omega)      jrratio     = ', jrratio
+         endif
+#else          
+         jrratio = 0
+         WRITE(numout,*) &
+         &   ' Dunne et al. (2005) rain ratio submodel                    jrratio     = ', jrratio
+#endif          
+#if defined key_roam
+         if (jocalccd.eq.0) then
+            WRITE(numout,*) &
+            &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+         elseif (jocalccd.eq.1) then
+            WRITE(numout,*) &
+            &   ' Calculated, dynamic CCD used                               jocalccd    = ', jocalccd
+         endif
+#else          
+         jocalccd = 0
+         WRITE(numout,*) &
+         &   ' Default, fixed CCD used                                    jocalccd    = ', jocalccd
+#endif
+         WRITE(numout,*)     &
+         &   ' Ridgwell rain ratio coefficient,                           xridg_r0    = ', xridg_r0
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom nat. mort. losses,         xfdfrac1    = ', xfdfrac1
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of mesozooplankton mort. losses,     xfdfrac2    = ', xfdfrac2
+         WRITE(numout,*)     &
+         &   ' fast-sinking fraction of diatom silicon grazing losses,    xfdfrac3    = ', xfdfrac3
+         WRITE(numout,*)     &
+         &   ' polar (high latitude) CaCO3 fraction,                      xcaco3a     = ', xcaco3a
+         WRITE(numout,*)     &
+         &   ' equatorial (low latitude) CaCO3 fraction,                  xcaco3b     = ', xcaco3b
+         WRITE(numout,*)     &
+         &   ' organic C mass:mole ratio, C106 H175 O40 N16 P1,           xmassc      = ', xmassc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate mass:mole ratio, CaCO3,                  xmassca     = ', xmassca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon mass:mole ratio, (H2SiO3)n,               xmasssi     = ', xmasssi
+         WRITE(numout,*)     &
+         &   ' calcium carbonate protection ratio,                        xprotca     = ', xprotca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon protection ratio,                         xprotsi     = ', xprotsi
+         WRITE(numout,*)     &
+         &   ' organic C remineralisation length scale,                   xfastc      = ', xfastc
+         WRITE(numout,*)     &
+         &   ' calcium carbonate dissolution length scale,                xfastca     = ', xfastca
+         WRITE(numout,*)     &
+         &   ' biogenic silicon dissolution length scale,                 xfastsi     = ', xfastsi
+!!
+!! Benthos parameters
+         WRITE(numout,*) '=== Benthos parameters'
+         WRITE(numout,*)     &
+         &   ' does   organic detritus go to the benthos?,                jorgben     = ', jorgben
+         WRITE(numout,*)     &
+         &   ' does inorganic detritus go to the benthos?,                jinorgben   = ', jinorgben
+!!
+!! Some checks on parameters related to benthos parameters
+         if (jorgben.eq.1 .and. jsfd.eq.1) then
+            !! slow detritus going to benthos at an accelerated rate
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jsfd *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.1 .and. jfdfate.eq.1) then
+            !! fast detritus going to benthos but via slow detritus
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jfdfate *and* jorgben are active - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         if (jorgben.eq.0 .and. jinorgben.eq.1) then
+            !! inorganic fast detritus going to benthos but organic fast detritus is not
+            WRITE(numout,*) '  === WARNING! ==='
+            WRITE(numout,*) '  jinorgben is active but jorgben is not - please check that you wish this'
+            WRITE(numout,*) '  === WARNING! ==='
+         endif
+         WRITE(numout,*)     &
+         &   ' organic   nitrogen sediment remineralisation rate,         xsedn       = ', xsedn
+         WRITE(numout,*)     &
+         &   ' organic   iron     sediment remineralisation rate,         xsedfe      = ', xsedfe
+         WRITE(numout,*)     &
+         &   ' inorganic silicon  sediment remineralisation rate,         xsedsi      = ', xsedsi
+         WRITE(numout,*)     &
+         &   ' organic   carbon   sediment remineralisation rate,         xsedc       = ', xsedc
+         WRITE(numout,*)     &
+         &   ' inorganic carbon   sediment remineralisation rate,         xsedca      = ', xsedca
+         WRITE(numout,*)     &
+         &   ' burial rate of seafloor detritus,                          xburial     = ', xburial
+!!
+!! Riverine inputs
+         WRITE(numout,*) '=== Riverine inputs'
+         if (jriver_n.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine N input,                                     jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine N concentrations specified,                       jriver_n    = ', jriver_n
+         elseif (jriver_n.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine N inputs specified,                               jriver_n    = ', jriver_n
+         endif
+         if (jriver_si.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine Si input,                                    jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine Si concentrations specified,                      jriver_si   = ', jriver_si
+         elseif (jriver_si.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine Si inputs specified,                              jriver_si   = ', jriver_si
+         endif
+         if (jriver_c.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine C input,                                     jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine C concentrations specified,                       jriver_c    = ', jriver_c
+         elseif (jriver_c.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine C inputs specified,                               jriver_c    = ', jriver_c
+         endif
+         if (jriver_alk.eq.0) then
+            WRITE(numout,*)     &
+            &   ' *no* riverine alkalinity input,                            jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.1) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity concentrations specified,              jriver_alk  = ', jriver_alk
+         elseif (jriver_alk.eq.2) then
+            WRITE(numout,*)     &
+            &   ' riverine alkalinity inputs specified,                      jriver_alk  = ', jriver_alk
+         endif
+         !! AXY (19/07/12): prevent (gross) stupidity on part of user
+         if (jriver_dep.lt.1.or.jriver_dep.ge.jpk) then
+            jriver_dep = 1
+         endif
+         WRITE(numout,*)     &
+         &   ' riverine input applied to down to depth k = ...            jriver_dep  = ', jriver_dep
+!!
+!! Miscellaneous
+         WRITE(numout,*) '=== Miscellaneous'
+         WRITE(numout,*)     &
+         &   ' diatom frustule dissolution rate,                          xsdiss      = ', xsdiss
+!!
+!! Gravitational sinking      
+         WRITE(numout,*) '=== Gravitational sinking'
+         WRITE(numout,*)     &
+         &   ' detritus gravitational sinking rate,                       vsed        = ', vsed
+         WRITE(numout,*)     & 
+         &   ' coefficient for Martin et al. (1987) remineralisation,     xhr         = ', xhr
+!!
+!! Non-Medusa parameters
+         WRITE(numout,*) '=== Non-Medusa parameters'
+         WRITE(numout,*)     & 
+         &   ' time coeff of POC in sediments,                            sedlam      = ', sedlam
+         WRITE(numout,*)     &
+         &   ' Sediment geol loss for POC,                                sedlostpoc  = ', sedlostpoc
+         WRITE(numout,*)     &
+         &   ' Vert layer for diagnostic of vertical flux,                jpkp        = ', jpkb
+!!
+!! UKESM1 - new diagnostics  !! Jpalm
+         WRITE(numout,*) '=== UKESM1-related parameters'
+         WRITE(numout,*)     &
+         &   ' include DMS diagnostic?,                                   jdms        = ', jdms
+!!
+      ENDIF
+!!
+!! Key depth positions (with thanks to Andrew Coward for bug-fixing this bit)
+      DO jk = 1,jpk
+         !! level thickness
+         fthk  = e3t_1d(jk)
+         !! level depth (top of level)
+         fdep  = gdepw_1d(jk)
+         !! level depth (bottom of level)
+         fdep1 = fdep + fthk
+         !!
+         if (fdep.lt.100.0.AND.fdep1.gt.100.0) then        !  100 m
+            i0100 = jk
+         elseif (fdep.lt.150.0.AND.fdep1.gt.150.0) then    !  150 m (for BASIN)
+            i0150 = jk
+         elseif (fdep.lt.200.0.AND.fdep1.gt.200.0) then    !  200 m
+            i0200 = jk
+         elseif (fdep.lt.500.0.AND.fdep1.gt.500.0) then    !  500 m
+            i0500 = jk
+         elseif (fdep.lt.1000.0.AND.fdep1.gt.1000.0) then  ! 1000 m
+            i1000 = jk
+         elseif (fdep1.lt.1100.0) then                     ! 1100 m (for Moore et al. sedimentary iron)
+            i1100 = jk
+         endif
+      enddo
+      !!
+      IF(lwp) THEN
+          WRITE(numout,*) '=== Position of key depths'
+          WRITE(numout,*)     & 
+          &   ' jk position of  100 m horizon                              i0100       = ', i0100
+          WRITE(numout,*)     &
+          &   ' jk position of  150 m horizon                              i0150       = ', i0150
+          WRITE(numout,*)     & 
+          &   ' jk position of  200 m horizon                              i0200       = ', i0200
+          WRITE(numout,*)     & 
+          &   ' jk position of  500 m horizon                              i0500       = ', i0500
+          WRITE(numout,*)     & 
+          &   ' jk position of 1000 m horizon                              i1000       = ', i1000
+          WRITE(numout,*)     & 
+          &   ' jk position of 1100 m horizon [*]                          i1100       = ', i1100
+          WRITE(numout,*) 'Got here ' , SIZE(friver_dep)
+          CALL flush(numout)
+      ENDIF
+
+#if defined key_roam
+
+      ! 1.4b namelist natroam : ROAM parameters
+      ! ---------------------------------------
+      
+      xthetaphy = 0.
+      xthetazoo = 0.
+      xthetanit = 0.
+      xthetarem = 0.
+      xo2min    = 0.
+
+      READ(numnatm,natroam)
+
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+!!       xthetaphy :  oxygen evolution/consumption by phytoplankton
+!!       xthetazoo :  oxygen consumption by zooplankton
+!!       xthetanit :  oxygen consumption by nitrogen remineralisation
+!!       xthetarem :  oxygen consumption by carbon remineralisation
+!!       xo2min    :  oxygen minimum concentration
+
+      IF(lwp) THEN
+          WRITE(numout,*) 'natroam'
+          WRITE(numout,*) ' '
+!!
+!! ROAM carbon, alkalinity and oxygen cycle parameters
+          WRITE(numout,*) '=== ROAM carbon, alkalinity and oxygen cycle parameters'
+          WRITE(numout,*)     &
+          &   ' oxygen evolution/consumption by phytoplankton              xthetaphy   = ', xthetaphy
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by zooplankton                          xthetazoo   = ', xthetazoo
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by nitrogen remineralisation            xthetanit   = ', xthetanit
+          WRITE(numout,*)     &
+          &   ' oxygen consumption by carbon remineralisation              xthetarem   = ', xthetarem
+          WRITE(numout,*)     &
+          &   ' oxygen minimum concentration                               xo2min      = ', xo2min
+       ENDIF
+
+#endif
+
+      CALL flush(numout)
+
+      ! 1.5 namelist natopt : parameters for optic
+      ! ------------------------------------------
+
+      xkg0  = 0.
+      xkr0  = 0.
+      xkgp  = 0.
+      xkrp  = 0.
+      xlg   = 0.
+      xlr   = 0.
+      rpig  = 0.
+
+      READ(numnatm,natopt)
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'natopt'
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' green   water absorption coeff  xkg0  = ',xkg0
+         WRITE(numout,*) ' red water absorption coeff      xkr0  = ',xkr0
+         WRITE(numout,*) ' pigment red absorption coeff    xkrp  = ',xkrp
+         WRITE(numout,*) ' pigment green absorption coeff  xkgp  = ',xkgp
+         WRITE(numout,*) ' green chl exposant              xlg   = ',xlg
+         WRITE(numout,*) ' red   chl exposant              xlr   = ',xlr
+         WRITE(numout,*) ' chla/chla+phea ratio            rpig  = ',rpig
+         WRITE(numout,*) ' '
+
+      ENDIF
+
+      IF(lwp) THEN
+         WRITE(numout,*) 'NaN check'
+         WRITE(numout,*) ' '
+         q1 = -1.
+         q2 = 0.
+         q3 = log(q1)
+         write (numout,*) 'q3 = ', q3
+         if ( ieee_is_nan( q3 ) ) then
+            write (numout,*) 'NaN detected'
+         else
+            write (numout,*) 'NaN not detected'
+         endif
+         WRITE(numout,*) ' '
+       ENDIF
+
+   END SUBROUTINE trc_nam_medusa
+   
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                             No MEDUSA
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_nam_medusa                      ! Empty routine
+   END  SUBROUTINE  trc_nam_medusa
+#endif  
+
+   !!======================================================================
+END MODULE trcnam_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90	(revision 7693)
@@ -0,0 +1,184 @@
+MODULE trcopt_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcopt_medusa  ***
+   !! TOP :   MEDUSA Compute the light availability in the water column
+   !!======================================================================
+   !! History :    -   !  1995-05  (M. Levy) Original code
+   !!              -   !  1999-09  (J.-M. Andre, M. Levy) 
+   !!              -   !  1999-11  (C. Menkes, M.-A. Foujols) itabe initial
+   !!              -   !  2000-02  (M.A. Foujols) change x**y par exp(y*log(x))
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                      MEDUSA bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_opt_medusa        :   Compute the light availability in the water column
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trc
+   USE prtctl_trc      ! Print control for debbuging
+   USE sms_medusa
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_opt_medusa   ! called in trcprg.F90
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_opt_medusa( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_opt_medusa  ***
+      !!
+      !! ** Purpose :   computes the light propagation in the water column
+      !!              and the euphotic layer depth
+      !!
+      !! ** Method  :   local par is computed in w layers using light propagation
+      !!              mean par in t layers are computed by integration
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt   ! index of the time stepping
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   zpig                                    ! total pigment
+      REAL(wp) ::   zkr                                     ! total absorption coefficient in red
+      REAL(wp) ::   zkg                                     ! total absorption coefficient in green
+      REAL(wp) ::   totchl                                  ! total Chl concentreation
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zpar100         ! irradiance at euphotic layer depth
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zpar0m          ! irradiance just below the surface
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zparr, zparg    ! red and green compound of par
+
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+
+      !! AXY (20/11/14): alter this to report on first MEDUSA call
+      !! IF( kt == nit000 ) THEN
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_opt_medusa: MEDUSA optic-model'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+	 IF(lwp) WRITE(numout,*) ' kt =',kt
+      ENDIF
+
+      ! determination of surface irradiance
+      ! -----------------------------------
+      ! AXY (23/07/15): the inclusion of empirical DMS calculations requires
+      !                 daily averages of a series of properties that are
+      !                 used as inputs; these include surface irradiance; 
+      !                 here, this is taken advantage of to allow MEDUSA to
+      !                 base its submarine light field on daily average
+      !                 rather than "instantaneous" irradiance; largely
+      !                 because MEDUSA was originally formulated to work
+      !                 with diel average irradiance rather than a diel
+      !                 cycle; using key_avgqsr_medusa activates this
+      !                 functionality, while its absence gives default
+      !                 MEDUSA (which is whatever is supplied by NEMO)
+# if defined key_avgqsr_medusa
+      ! surface irradiance input is rolling average irradiance
+      zpar0m (:,:)   = zn_dms_qsr(:,:) * 0.43
+# else      
+      ! surface irradiance input is   instantaneous irradiance
+      zpar0m (:,:)   =        qsr(:,:) * 0.43
+# endif
+      ! AXY (22/08/14): when zpar0m = 0, zpar100 is also zero and calculating 
+      !                 euphotic depth is not possible (cf. the Arctic Octopus); 
+      !                 a "solution" to this is to set zpar0m to some minimal
+      !                 value such that zpar100 also has a non-zero value and
+      !                 euphotic depth can be calculated properly; note that,
+      !                 in older, non-diurnal versions of NEMO, this was much
+      !                 less of a problem; note also that, if pushed, I will
+      !                 claim that my minimal value of zpar0m refers to light
+      !                 from stars
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( zpar0m(ji,jj) <= 0.0 ) zpar0m(ji,jj) = 0.001  ! = 1 mW/m2
+         ENDDO
+      ENDDO
+      zpar100(:,:)   = zpar0m(:,:) * 0.01
+      xpar   (:,:,1) = zpar0m(:,:)
+      zparr  (:,:,1) = 0.5 * zpar0m(:,:)
+      zparg  (:,:,1) = 0.5 * zpar0m(:,:)
+
+      ! determination of xpar
+      ! ---------------------
+
+      DO jk = 2, jpk                     ! determination of local par in w levels
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               totchl =trn(ji,jj,jk-1,jpchn)+trn(ji,jj,jk-1,jpchd)
+               zpig = MAX( TINY(0.), totchl/rpig) 
+               zkr  = xkr0 + xkrp * EXP( xlr * LOG( zpig ) )
+               zkg  = xkg0 + xkgp * EXP( xlg * LOG( zpig ) )
+               zparr(ji,jj,jk) = zparr(ji,jj,jk-1) * EXP( -zkr * fse3t(ji,jj,jk-1) )
+               zparg(ji,jj,jk) = zparg(ji,jj,jk-1) * EXP( -zkg * fse3t(ji,jj,jk-1) )
+            END DO
+        END DO
+      END DO
+
+      DO jk = 1, jpkm1                   ! mean par in t levels
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               totchl =trn(ji,jj,jk  ,jpchn)+trn(ji,jj,jk  ,jpchd)
+               zpig = MAX( TINY(0.), totchl/rpig) 
+               zkr  = xkr0 + xkrp * EXP( xlr * LOG( zpig ) )
+               zkg  = xkg0 + xkgp * EXP( xlg * LOG( zpig ) )
+               zparr(ji,jj,jk)    = zparr(ji,jj,jk) / zkr / fse3t(ji,jj,jk) * ( 1 - EXP( -zkr*fse3t(ji,jj,jk) ) )
+               zparg(ji,jj,jk)    = zparg(ji,jj,jk) / zkg / fse3t(ji,jj,jk) * ( 1 - EXP( -zkg*fse3t(ji,jj,jk) ) )
+               xpar (ji,jj,jk) = MAX( zparr(ji,jj,jk) + zparg(ji,jj,jk), 1.e-15 )
+            END DO
+         END DO
+      END DO
+
+      ! 3. Determination of euphotic layer depth
+      ! ----------------------------------------
+
+      ! Euphotic layer bottom level
+      neln(:,:) = 1                                           ! initialisation of EL level
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+           DO ji = 1, jpi
+              IF( xpar(ji,jj,jk) >= zpar100(ji,jj) )   neln(ji,jj) = jk+1 ! 1rst T-level strictly below EL bottom
+              !                                                  ! nb. this is to ensure compatibility with
+              !                                                  ! nmld_trc definition in trd_mld_trc_zint
+           END DO
+         END DO
+      ENDDO
+
+      ! Euphotic layer depth
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            xze(ji,jj) = fsdepw( ji, jj, neln(ji,jj) )            ! exact EL depth
+         END DO
+      ENDDO 
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('opt')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
+      ENDIF
+
+   END SUBROUTINE trc_opt_medusa
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_opt_medusa( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_opt_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_opt_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcopt_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90	(revision 7693)
@@ -0,0 +1,280 @@
+MODULE trcoxy_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcoxy_medusa  ***
+   !! TOP :   MEDUSA
+   !!======================================================================
+   !! History :
+   !!  -   !  2011-07  (A. Yool)             added for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa && defined key_roam
+   !!----------------------------------------------------------------------
+   !!                                        MEDUSA oxygen cycle
+   !!----------------------------------------------------------------------
+   !!   trc_oxy_medusa        :  
+   !!----------------------------------------------------------------------
+      USE oce_trc
+      USE trc
+      USE sms_medusa
+      USE lbclnk
+      USE prtctl_trc      ! Print control for debugging
+
+      IMPLICIT NONE
+      PRIVATE
+      
+      PUBLIC   trc_oxy_medusa    ! called in trc_bio_medusa
+      PUBLIC   oxy_sato          ! called in trc_bio_medusa
+
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+! The following is a map of the subroutines contained within this module
+! - trc_oxy_medusa
+!      - CALLS oxy_schmidt
+!      - CALLS oxy_sato
+
+CONTAINS
+
+!=======================================================================
+!
+   SUBROUTINE trc_oxy_medusa( pt, ps, kw660, pp0, o2,  &  !! inputs
+      kwo2, o2flux, o2sat )                               !! outputs
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates O2 change due to air-sea gas exchange
+      !! Author : Andrew Yool
+      !! Date   : 15/10/04 (revised 08/07/11)
+      !!
+      !! This subroutine calculates oxygen air-sea gas exchange in the
+      !! surface layer of the ocean.  The formulation is taken from one 
+      !! written by Ray Najjar for the OCMIP-2 project.  The routine
+      !! calls two other subroutines, oxy_schmidt.f (calculates Schmidt 
+      !! number of oxygen) and oxy_sato.f (calculates oxygen saturation 
+      !! concentration at 1 atm).
+      !!
+      !! AXY (23/06/15): revised to allow common gas transfer velocity
+      !!                 to be used for CO2 and O2; outputs of this
+      !!                 routine amended to mmol/m3 from mol/m3
+      !! 
+      !! Function inputs are (in order) : 
+      !!     pt      temperature                     (degrees C)
+      !!     ps      salinity                        (PSU)
+      !!     kw660   gas transfer velocity           (m/s)
+      !!     pp0     surface pressure                (divided by 1 atm)
+      !!     o2      surface O2 concentration        (mmol/m3)
+      !! (+) kwo2    gas transfer velocity for O2    (m/s)
+      !! (*) o2flux  exchange rate of oxygen         (mmol/m2/s)
+      !! (+) o2sat   oxygen saturation concentration (mmol/m3)
+      !! 
+      !! Where (*) is the function output (note its units).  
+      !!
+!=======================================================================
+
+      implicit none
+!
+      REAL(wp), INTENT( in )    :: pt
+      REAL(wp), INTENT( in )    :: ps
+      REAL(wp), INTENT( in )    :: kw660
+      REAL(wp), INTENT( in )    :: pp0
+      REAL(wp), INTENT( in )    :: o2
+      REAL(wp), INTENT( out )   :: kwo2, o2flux, o2sat
+!
+      REAL(wp) :: o2schmidt, o2sato, mol_o2
+!
+! Oxygen to mol / m3
+!
+      mol_o2 = o2 / 1000.
+!
+! Calculate oxygen Schmidt number
+! 
+      call oxy_schmidt(pt, o2schmidt)
+!
+! Calculate the transfer velocity for O2 (m/s)
+!
+      kwo2 = kw660 * (660 / o2schmidt)**0.5
+!
+! Calculate the saturation concentration for oxygen (mol/m3)
+!
+      call oxy_sato(pt, ps, o2sato)
+      o2sat = o2sato * pp0
+!
+! Calculate time rate of change of O2 due to gas exchange (mol/m3/s)
+!
+      o2flux = kwo2 * (o2sat - mol_o2)
+!
+! Oxygen flux and saturation to mmol / m3
+!
+      o2sat  =  o2sat * 1000.
+      o2flux = o2flux * 1000.
+!
+      END SUBROUTINE trc_oxy_medusa
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+   SUBROUTINE oxy_schmidt( pt, &  !! input
+      o2_schmidt )                !! output
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates Schmidt number for ocean uptake of O2
+      !! Author : Andrew Yool
+      !! Date   : 14/10/04 (revised 08/07/11)
+      !! 
+      !! This subroutine calculates the Schmidt number for O2 using sea 
+      !! surface temperature.  The code is based upon that developed as 
+      !! part of the OCMIP-2 project (1998-2000).  The coefficients used 
+      !! are taken from Keeling et al. (1998, GBC, 12, 141-163).
+      !! 
+      !! AXY (23/06/2015)
+      !! UPDATED: revised formulation from Wanninkhof (2014) for
+      !! consistency with MOCSY
+      !!
+      !! Winninkhof, R. (2014). Relationship between wind speed and gas
+      !! exchange over the ocean revisited. LIMNOLOGY AND OCEANOGRAPHY-METHODS
+      !! 12, 351-362, doi:10.4319/lom.2014.12.351
+      !!
+      !! Function inputs are (in order) : 
+      !!     t           temperature (degrees C)
+      !! (*) o2_schmidt  oxygen Schmidt number
+      !! 
+      !! Where (*) is the function output.
+      !!
+!=======================================================================
+
+      implicit none
+!
+      REAL(wp) :: pt, o2_schmidt
+      REAL(wp) :: a0, a1, a2, a3, a4
+!
+! AXY (23/06/15): OCMIP-2 coefficients
+!     data a0 /    1638.0 /
+!     data a1 /    -81.83 /
+!     data a2 /     1.483 /
+!     data a3 / -0.008004 /
+!
+! AXY (23/06/15): Wanninkhof (2014) coefficients
+      data a0 /     1920.4 /
+      data a1 /     -135.6 /
+      data a2 /     5.2121 /
+      data a3 /   -0.10939 /
+      data a4 / 0.00093777 /
+!
+!     o2_schmidt = a0 + pt*(a1 + pt*(a2 + pt*a3))
+      o2_schmidt = a0 + pt*(a1 + pt*(a2 + pt*(a3 + pt*a4)))
+!
+      END SUBROUTINE oxy_schmidt
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+!=======================================================================
+!
+   SUBROUTINE oxy_sato( pt, ps, &  !! inputs 
+      o2_sato )                    !! output
+!      
+!=======================================================================
+      !!
+      !! Title  : Calculates O2 saturation at 1 atm pressure
+      !! Author : Andrew Yool
+      !! Date   : 14/10/04 (revised 08/07/11)
+      !! 
+      !! This subroutine calculates the oxygen saturation concentration
+      !! at 1 atmosphere pressure in mol/m3 given ambient temperature
+      !! and salinity.  This formulation is (ostensibly) taken from 
+      !! Garcia & Gordon (1992, L&O, 1307-1312).  The function works
+      !! in the range -1.9 <= T <= 40, 0 <= S <= 42.
+      !!
+      !! Function inputs are (in order) : 
+      !!     pt       temperature (degrees C)
+      !!     ps       salinity (PSU)
+      !! (*) o2_sato  oxygen saturation (mol/m3)
+      !!
+      !! Where (*) is the function output (note its units).  
+      !!
+      !! Check value : T = 10, S = 35, oxy_sato = 0.282015 mol/m3
+      !!
+!=======================================================================
+
+      implicit none
+!
+      REAL(wp) :: pt, ps, o2_sato
+!
+      REAL(wp) :: a0, a1, a2, a3, a4, a5
+      REAL(wp) :: b0, b1, b2, b3
+      REAL(wp) :: c0
+!
+      REAL(wp) :: tt, tk, ts, ts2, ts3, ts4, ts5
+      REAL(wp) :: ans1, ans2
+!
+      data a0 /  2.00907    /
+      data a1 /  3.22014    /
+      data a2 /  4.05010    /
+      data a3 /  4.94457    /
+      data a4 / -2.56847E-1 /
+      data a5 /  3.88767    /
+!
+      data b0 / -6.24523E-3 /
+      data b1 / -7.37614E-3 /
+      data b2 / -1.03410E-2 /
+      data b3 / -8.17083E-3 /
+!
+      data c0 / -4.88682E-7 /
+!     
+      tt   = 298.15 - pt
+      tk   = 273.15 + pt
+      ts   = log(tt / tk)
+      ts2  = ts**2
+      ts3  = ts**3
+      ts4  = ts**4
+      ts5  = ts**5
+      ans1 = a0 + a1*ts + a2*ts2 + a3*ts3 + a4*ts4 + a5*ts5  &
+           + ps*(b0 + b1*ts + b2*ts2 + b3*ts3)               &
+           + c0*(ps*ps)
+      ans2 = exp(ans1)
+!
+!  Convert from ml/l to mol/m3
+!
+      o2_sato = (ans2 / 22391.6) * 1000.0
+!
+      END SUBROUTINE oxy_sato
+
+!=======================================================================
+!=======================================================================
+!=======================================================================
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+
+CONTAINS
+
+   SUBROUTINE trc_oxy_medusa( pt, ps, kw660, pp0, o2,  &  !! inputs
+      o2flux, o2sat )                                     !! outputs
+      USE par_kind
+
+      REAL(wp), INTENT( in )    :: pt
+      REAL(wp), INTENT( in )    :: ps
+      REAL(wp), INTENT( in )    :: kw660
+      REAL(wp), INTENT( in )    :: pp0
+      REAL(wp), INTENT( in )    :: o2
+      REAL(wp), INTENT( inout ) :: o2flux, o2sat
+
+      WRITE(*,*) 'trc_oxy_medusa: You should not have seen this print! error?', kt
+
+   END SUBROUTINE trc_oxy_medusa
+#endif
+
+   !!======================================================================
+END MODULE  trcoxy_medusa
+  
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcrst_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcrst_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcrst_medusa.F90	(revision 7693)
@@ -0,0 +1,306 @@
+MODULE trcrst_medusa
+   !!======================================================================
+   !!                       ***  MODULE trcrst_medusa  ***
+   !! TOP :   create, write, read the restart files of MEDUSA tracer
+   !!======================================================================
+   !! History :   1.0  !  2010-01 (C. Ethe) Original
+   !!             1.1  !  2014-07 (A. Yool; J. Palmieri) converted for MEDUSA
+   !!             1.2  !  2015-07 (A. Yool) add averaged fields for DMS
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                               medusa tracers
+   !!----------------------------------------------------------------------
+   !!   trc_rst_read_medusa   : read  restart file
+   !!   trc_rst_wri_medusa    : write restart file
+   !!----------------------------------------------------------------------
+   USE oce_trc         ! Ocean variables
+   USE par_trc         ! TOP parameters
+   USE trc             ! TOP variables
+   USE trcsms_medusa   ! MEDUSA sms trends
+   USE sms_medusa      ! MEDUSA sms trends
+   USE iom
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC  trc_rst_read_medusa  ! called by trcini.F90 module (actually trcrst.F90)
+   PUBLIC  trc_rst_wri_medusa   ! called by trcini.F90 module (actually trcrst.F90)
+
+CONTAINS
+   
+   SUBROUTINE trc_rst_read_medusa( knum ) 
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_rst_read_medusa  ***  
+      !!
+      !! ** Purpose : Read in restart file specific variables from medusa model
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)  :: knum  ! unit of the restart file
+      !! AXY (07/07/14): temporary variables
+      REAL(wp) ::    fq0,fq1,fq2
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_rst_read_medusa : Read specific variables from medusa model '
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+
+      !! AXY (07/07/14): remove LOBSTER calls
+      !! CALL iom_get( knum, jpdom_autoglo, 'SEDB'//ctrcnm(jp_lob_det), sedpocb(:,:) ) 
+      !! CALL iom_get( knum, jpdom_autoglo, 'SEDN'//ctrcnm(jp_lob_det), sedpocn(:,:) ) 
+
+      !! AXY (07/07/14): as well as passive tracers, the restart files
+      !!                 contain 2D fields of sediments; these need to
+      !!                 be read in specially; hence this routine
+      !!
+      !! AXY (13/01/12): check if the restart contains sediment fields;
+      !!                 this is only relevant for simulations that include
+      !!                 biogeochemistry and are restarted from earlier runs
+      !!                 in which there was no sediment component
+      !!
+      IF( iom_varid( knum, 'B_SED_N', ldstop = .FALSE. ) > 0 ) THEN
+         !! YES; in which case read them
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields present - reading in ...'
+         CALL iom_get( knum, jpdom_autoglo, 'B_SED_N',  zb_sed_n(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'N_SED_N',  zn_sed_n(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'B_SED_FE', zb_sed_fe(:,:) )
+         CALL iom_get( knum, jpdom_autoglo, 'N_SED_FE', zn_sed_fe(:,:) )
+         CALL iom_get( knum, jpdom_autoglo, 'B_SED_SI', zb_sed_si(:,:) )
+         CALL iom_get( knum, jpdom_autoglo, 'N_SED_SI', zn_sed_si(:,:) )
+         CALL iom_get( knum, jpdom_autoglo, 'B_SED_C',  zb_sed_c(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'N_SED_C',  zn_sed_c(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'B_SED_CA', zb_sed_ca(:,:) )
+         CALL iom_get( knum, jpdom_autoglo, 'N_SED_CA', zn_sed_ca(:,:) )
+      ELSE
+         !! NO; in which case set them to zero
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields absent - setting to zero ...'
+         zb_sed_n(:,:)  = 0.0   !! organic N
+         zn_sed_n(:,:)  = 0.0
+         zb_sed_fe(:,:) = 0.0   !! organic Fe
+         zn_sed_fe(:,:) = 0.0
+         zb_sed_si(:,:) = 0.0   !! inorganic Si
+         zn_sed_si(:,:) = 0.0
+         zb_sed_c(:,:)  = 0.0   !! organic C
+         zn_sed_c(:,:)  = 0.0
+         zb_sed_ca(:,:) = 0.0   !! inorganic C
+         zn_sed_ca(:,:) = 0.0
+      ENDIF
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment field stats (min, max, sum) ...'
+      fq0 = MINVAL(zn_sed_n(:,:))
+      fq1 = MAXVAL(zn_sed_n(:,:))
+      fq2 = SUM(zn_sed_n(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  N ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_fe(:,:))
+      fq1 = MAXVAL(zn_sed_fe(:,:))
+      fq2 = SUM(zn_sed_fe(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Fe ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_si(:,:))
+      fq1 = MAXVAL(zn_sed_si(:,:))
+      fq2 = SUM(zn_sed_si(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Si ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_c(:,:))
+      fq1 = MAXVAL(zn_sed_c(:,:))
+      fq2 = SUM(zn_sed_c(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  C ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_ca(:,:))
+      fq1 = MAXVAL(zn_sed_ca(:,:))
+      fq2 = SUM(zn_sed_ca(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Ca ', &
+         &        fq0, fq1, fq2
+
+      !! AXY (07/07/15): read in temporally averaged fields for DMS
+      !!                 calculations
+      !!
+      IF( iom_varid( knum, 'B_DMS_CHN', ldstop = .FALSE. ) > 0 ) THEN
+         !! YES; in which case read them
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS present - reading in ...'
+         CALL iom_get( knum, jpdom_autoglo, 'B_DMS_CHN',  zb_dms_chn(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'N_DMS_CHN',  zn_dms_chn(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'B_DMS_CHD',  zb_dms_chd(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'N_DMS_CHD',  zn_dms_chd(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'B_DMS_MLD',  zb_dms_mld(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'N_DMS_MLD',  zn_dms_mld(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'B_DMS_QSR',  zb_dms_qsr(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'N_DMS_QSR',  zn_dms_qsr(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'B_DMS_DIN',  zb_dms_din(:,:)  )
+         CALL iom_get( knum, jpdom_autoglo, 'N_DMS_DIN',  zn_dms_din(:,:)  )
+      ELSE
+         !! NO; in which case set them to zero
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS absent - setting to zero ...'
+         zb_dms_chn(:,:)  = 0.0   !! CHN
+         zn_dms_chn(:,:)  = 0.0
+         zb_dms_chd(:,:)  = 0.0   !! CHD
+         zn_dms_chd(:,:)  = 0.0
+         zb_dms_mld(:,:)  = 0.0   !! MLD
+         zn_dms_mld(:,:)  = 0.0
+         zb_dms_qsr(:,:)  = 0.0   !! QSR
+         zn_dms_qsr(:,:)  = 0.0
+         zb_dms_din(:,:)  = 0.0   !! DIN
+         zn_dms_din(:,:)  = 0.0
+      ENDIF
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS stats (min, max, sum) ...'
+      fq0 = MINVAL(zn_dms_chn(:,:))
+      fq1 = MAXVAL(zn_dms_chn(:,:))
+      fq2 = SUM(zn_dms_chn(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, CHN ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_chd(:,:))
+      fq1 = MAXVAL(zn_dms_chd(:,:))
+      fq2 = SUM(zn_dms_chd(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, CHD ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_mld(:,:))
+      fq1 = MAXVAL(zn_dms_mld(:,:))
+      fq2 = SUM(zn_dms_mld(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, MLD ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_qsr(:,:))
+      fq1 = MAXVAL(zn_dms_qsr(:,:))
+      fq2 = SUM(zn_dms_qsr(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, QSR ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_din(:,:))
+      fq1 = MAXVAL(zn_dms_din(:,:))
+      fq2 = SUM(zn_dms_din(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, DIN ', fq0, fq1, fq2
+
+   END SUBROUTINE trc_rst_read_medusa
+
+   SUBROUTINE trc_rst_wri_medusa( kt, kitrst, knum )
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_rst_read_medusa  ***
+      !!
+      !! ** Purpose : Read in restart file specific variables from medusa model
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)  :: kt      ! time step
+      INTEGER, INTENT(in)  :: kitrst  ! time step of restart write
+      INTEGER, INTENT(in)  :: knum    ! unit of the restart file
+      !! AXY (07/07/14): temporary variables
+      REAL(wp) ::    fq0,fq1,fq2
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) ' trc_rst_wri_medusa : Write specific variables from medusa model '
+      IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+
+      !! AXY (07/07/14): remove LOBSTER calls
+      !! CALL iom_rstput( kt, kitrst, knum, 'SEDB'//ctrcnm(jp_lob_det), sedpocb(:,:) )
+      !! CALL iom_rstput( kt, kitrst, knum, 'SEDN'//ctrcnm(jp_lob_det), sedpocn(:,:) )
+
+      !! AXY (07/07/14): as well as passive tracers, the restart files
+      !!                 contain 2D fields of sediments; these need to
+      !!                 be written out specially; hence this routine
+      !!
+      !! AXY (13/01/12): write out "before" and "now" state of seafloor
+      !!                 sediment pools into restart; this happens
+      !!                 whether or not the pools are to be used by
+      !!                 MEDUSA (which is controlled by a switch in the
+      !!                 namelist_top file)
+      !!
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields - writing out ...'
+      CALL iom_rstput( kt, kitrst, knum, 'B_SED_N',  zb_sed_n(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'N_SED_N',  zn_sed_n(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'B_SED_FE', zb_sed_fe(:,:) )
+      CALL iom_rstput( kt, kitrst, knum, 'N_SED_FE', zn_sed_fe(:,:) )
+      CALL iom_rstput( kt, kitrst, knum, 'B_SED_SI', zb_sed_si(:,:) )
+      CALL iom_rstput( kt, kitrst, knum, 'N_SED_SI', zn_sed_si(:,:) )
+      CALL iom_rstput( kt, kitrst, knum, 'B_SED_C',  zb_sed_c(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'N_SED_C',  zn_sed_c(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'B_SED_CA', zb_sed_ca(:,:) )
+      CALL iom_rstput( kt, kitrst, knum, 'N_SED_CA', zn_sed_ca(:,:) )
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment field stats (min, max, sum) ...'
+      fq0 = MINVAL(zn_sed_n(:,:))
+      fq1 = MAXVAL(zn_sed_n(:,:))
+      fq2 = SUM(zn_sed_n(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  N ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_fe(:,:))
+      fq1 = MAXVAL(zn_sed_fe(:,:))
+      fq2 = SUM(zn_sed_fe(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Fe ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_si(:,:))
+      fq1 = MAXVAL(zn_sed_si(:,:))
+      fq2 = SUM(zn_sed_si(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Si ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_c(:,:))
+      fq1 = MAXVAL(zn_sed_c(:,:))
+      fq2 = SUM(zn_sed_c(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment  C ', &
+         &        fq0, fq1, fq2
+      fq0 = MINVAL(zn_sed_ca(:,:))
+      fq1 = MAXVAL(zn_sed_ca(:,:))
+      fq2 = SUM(zn_sed_ca(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'Sediment Ca ', &
+         &        fq0, fq1, fq2
+
+      !! AXY (07/07/15): write out temporally averaged fields for DMS
+      !!                 calculations
+      !!
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS - writing out ...'
+      CALL iom_rstput( kt, kitrst, knum, 'B_DMS_CHN',  zb_dms_chn(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'N_DMS_CHN',  zn_dms_chn(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'B_DMS_CHD',  zb_dms_chd(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'N_DMS_CHD',  zn_dms_chd(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'B_DMS_MLD',  zb_dms_mld(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'N_DMS_MLD',  zn_dms_mld(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'B_DMS_QSR',  zb_dms_qsr(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'N_DMS_QSR',  zn_dms_qsr(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'B_DMS_DIN',  zb_dms_din(:,:)  )
+      CALL iom_rstput( kt, kitrst, knum, 'N_DMS_DIN',  zn_dms_din(:,:)  )
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS stats (min, max, sum) ...'
+      fq0 = MINVAL(zn_dms_chn(:,:))
+      fq1 = MAXVAL(zn_dms_chn(:,:))
+      fq2 = SUM(zn_dms_chn(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, CHN ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_chd(:,:))
+      fq1 = MAXVAL(zn_dms_chd(:,:))
+      fq2 = SUM(zn_dms_chd(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, CHD ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_mld(:,:))
+      fq1 = MAXVAL(zn_dms_mld(:,:))
+      fq2 = SUM(zn_dms_mld(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, MLD ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_qsr(:,:))
+      fq1 = MAXVAL(zn_dms_qsr(:,:))
+      fq2 = SUM(zn_dms_qsr(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, QSR ', fq0, fq1, fq2
+      fq0 = MINVAL(zn_dms_din(:,:))
+      fq1 = MAXVAL(zn_dms_din(:,:))
+      fq2 = SUM(zn_dms_din(:,:))
+      if (lwp) write (numout,'(a,3f15.5)') 'DMS, DIN ', fq0, fq1, fq2
+
+   END SUBROUTINE trc_rst_wri_medusa
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_rst_read_medusa( knum )
+     INTEGER, INTENT(in)  :: knum
+     WRITE(*,*) 'trc_rst_wri_medusa: You should not have seen this print! error?',knum
+   END SUBROUTINE trc_rst_read_medusa
+
+   SUBROUTINE trc_rst_wri_medusa( kt, kitrst, knum )
+     INTEGER, INTENT(in)  :: kt, kitrst, knum
+     WRITE(*,*) 'trc_rst_wri_medusa: You should not have seen this print! error?', kt, kitrst, knum
+   END SUBROUTINE trc_rst_wri_medusa
+#endif
+
+   !!======================================================================
+END MODULE trcrst_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90	(revision 7693)
@@ -0,0 +1,426 @@
+MODULE trcsed_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcsed_medusa  ***
+   !! TOP :   MEDUSA Compute loss of organic matter in the sediments
+   !!======================================================================
+   !! History :    -   !  1995-06 (M. Levy)  original code
+   !!              -   !  2000-12 (E. Kestenare)  clean up
+   !!             2.0  !  2007-12  (C. Deltel, G. Madec)  F90 + simplifications
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!              -   !  2011-04  (A. Yool) updated for ROAM project
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                      MEDUSA bio-model
+   !!----------------------------------------------------------------------
+   !!   trc_sed_medusa        :  Compute loss of organic matter in the sediments
+   !!----------------------------------------------------------------------
+   USE oce_trc         !
+   USE trc
+   USE sms_medusa
+   !! AXY (10/02/09)
+   USE iom
+   !! USE trc_nam_dia                   ! JPALM 13-11-2015 -- if iom_use for diag
+   !! USE trc_nam_iom_medusa            ! JPALM 13-11-2015 -- if iom_use for diag
+   USE fldread                          !  time interpolation
+   USE lbclnk
+   USE prtctl_trc                       ! Print control for debbuging
+   !! JPALM (27-06-2016): add lk_oasis for CO2 and DMS coupling with atm
+   USE sbc_oce, ONLY: lk_oasis
+   USE oce,     ONLY: Dust_in_cpl
+   !! Check Dust dep
+# if defined key_debug_medusa   
+   !! USE trcrst, ONLY: trc_rst_dia_stat   !! variable stat
+# endif
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sed_medusa     ! called in ???
+   PUBLIC   trc_sed_medusa_sbc      
+
+   !! * Module variables
+   INTEGER ::                   &
+     ryyss,                     &  !: number of seconds per year
+     rmtss                         !: number of seconds per month
+
+   !! AXY (10/02/09)
+   LOGICAL, PUBLIC  ::   bdustfer  !: boolean for dust input from the atmosphere
+   REAL(wp), PUBLIC ::                 &
+      sedfeinput = 1.e-9_wp  ,         &
+      dustsolub  = 0.014_wp
+   REAL(wp), PARAMETER :: Fe_dust_mratio = 0.035   !! Fe:dust mass ratio = 0.035
+   INTEGER , PARAMETER ::        nbtimes = 365     !: maximum number of times record in a file
+   INTEGER  :: ntimes_dust                         ! number of time steps in a file
+
+   INTEGER ::                          &
+      numdust,                         &
+      nflx1,  nflx2,                   &
+      nflx11, nflx12
+   
+   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf_dust      ! structure of input dust
+
+   
+   !!* Substitution
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sed_medusa( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_sed_medusa  ***
+      !!
+      !! ** Purpose :   compute the now trend due to the vertical sedimentation of
+      !!              detritus and add it to the general trend of detritus equations
+      !!
+      !! ** Method  :   this ROUTINE compute not exactly the advection but the
+      !!              transport term, i.e.  dz(wt) and dz(ws)., dz(wtr)
+      !!              using an upstream scheme
+      !!              the now vertical advection of tracers is given by:
+      !!                      dz(trn wn) = 1/bt dk+1( e1t e2t vsed (trn) )
+      !!              add this trend now to the general trend of tracer (ta,sa,tra):
+      !!                             tra = tra + dz(trn wn)
+      !!        
+      !!              IF 'key_trc_diabio' is defined, the now vertical advection
+      !!              trend of passive tracers is saved for futher diagnostics.
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !! AXY (10/02/09)
+      INTEGER  ::   jnt
+      !!
+      INTEGER  ::   ji, jj, jk
+      REAL(wp) ::   ztra
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwork
+
+      !! AXY (10/02/09)
+      REAL(wp) ::   rfact2
+
+      CHARACTER (len=25) :: charout
+      
+      !! JPALM - 26-11-2015 -add iom_use for diagnostic
+       REAL(wp), POINTER, DIMENSION(:,:  ) :: zw2d
+      !!---------------------------------------------------------------------
+      !!
+      IF( lk_iomput) THEN  
+           IF( med_diag%DSED%dgsave ) THEN
+               CALL wrk_alloc( jpi, jpj,      zw2d )
+                zw2d(:,:)      = 0.0      !!
+           ENDIF
+      ENDIF
+      
+      !! AXY (10/02/09)
+      jnt = 1
+      rfact2 = 1.0
+
+      ! Number of seconds per year and per month
+      ryyss = nyear_len(1) * rday
+      rmtss = ryyss / raamo
+
+      !! AXY (20/11/14): alter this to report on first MEDUSA call
+      !! IF( kt == nit000 ) THEN
+      IF( kt == nittrc000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' trc_sed_medusa: MEDUSA sedimentation'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~'
+	 IF(lwp) WRITE(numout,*) ' kt =',kt
+      ENDIF
+
+      !! AXY (04/11/13): replace this with a call in trc_ini_medusa
+      !! AXY (25/02/10)
+      !! call routine for populating CCD array if this is the first time-step
+      !! IF( kt == nittrc000 ) CALL medusa_ccd( kt )
+
+      !! AXY (04/11/13): replace this with a call in trc_ini_medusa
+      !! AXY (26/01/12)
+      !! call routine for populating river arrays if this is the first time-step
+      !! IF( kt == nittrc000 ) CALL medusa_river( kt )
+
+      !! AXY (10/02/09)
+      !!IF( (jnt == 1) .and. (bdustfer) )  CALL trc_sed_medusa_sbc( kt )
+
+      !! JPALM -- 31-03-2016 -- rewrite trc_sed_medusa_sbc.
+      !! IF (kt == nittrc000 ) CALL trc_sed_medusa_sbc 
+
+      !! JPALM -- 20-07-2016 -- adapt dust forcing fields reading and conversion
+      !!                     To read dust dep in kg-dust/m2/s instead of g-Fe/m2/month 
+      !!                     So all forcings and coupling dust dep are in the same SI units
+      !!                     and then convert in mmol-Fe/m2/day
+
+      IF( bdustfer ) THEN
+        !! IF( kt == nittrc000 .OR. ( kt /= nittrc000 .AND. ntimes_dust > 1 ) ) THEN
+            CALL fld_read( kt, 1, sf_dust )
+            dust(:,:) = sf_dust(1)%fnow(:,:,1)
+         !! ENDIF
+      ELSEIF (lk_oasis) THEN
+         dust = Dust_in_cpl
+      ELSE
+         dust(:,:) = 0.0
+      ENDIF
+      !!
+      zirondep(:,:) = 0.e0     !! Initialisation of deposition variables
+      zirondep(:,:) = dust(:,:) * Fe_dust_mratio / xfe_mass * 1.e6 * 86400.  !! mmol-Fe/m2/d
+      
+      !! JPALM -- 20-07-2016 -- Zirondep and zsidep are not used.
+      !!                     So comment out the following lines. but keep them
+      !!                     as we may want to used them later on
+      !!================================================     
+      !!
+      !! zirondep(:,:,:) = 0.e0     !! Initialisation of deposition variables
+      !! zsidep  (:,:)   = 0.e0
+      !!
+      !! Iron and Si deposition at the surface
+      !! -------------------------------------
+      !!
+      !! DO jj = 1, jpj
+      !!    DO ji = 1, jpi
+      !!       zirondep(ji,jj,1) = (dustsolub * dust(ji,jj) / (55.85 * rmtss) + 3.e-10 / ryyss) &
+      !!       & * rfact2 / fse3t(ji,jj,1)
+      !!       zsidep  (ji,jj)   = 8.8 * 0.075 * dust(ji,jj) * rfact2 / &
+      !!       & (fse3t(ji,jj,1) * 28.1 * rmtss)
+      !!    END DO
+      !! END DO
+
+      ! sedimentation of detrital nitrogen : upstream scheme
+      ! ----------------------------------------------------
+      !
+      zwork(:,:,:) = 0.e0        ! initialisation of sinking variable
+      ! for detrital nitrogen sedimentation only - jpdet
+      zwork(:,:,1  ) = 0.e0      ! surface value set to zero
+      !!    DO ji = 1, jpi
+      !!       zirondep(ji,jj,1) = (dustsolub * dust(ji,jj) / (55.85 * rmtss) + 3.e-10 / ryyss) &
+      !!       & * rfact2 / fse3t(ji,jj,1)
+      !!       zsidep  (ji,jj)   = 8.8 * 0.075 * dust(ji,jj) * rfact2 / &
+      !!       & (fse3t(ji,jj,1) * 28.1 * rmtss)
+      !!    END DO
+      !! END DO
+
+      ! sedimentation of detrital nitrogen : upstream scheme
+      ! ----------------------------------------------------
+      !
+      zwork(:,:,:) = 0.e0        ! initialisation of sinking variable
+      ! for detrital nitrogen sedimentation only - jpdet
+      zwork(:,:,1  ) = 0.e0      ! surface value set to zero
+      zwork(:,:,jpk) = 0.e0      ! bottom value  set to zero
+      !
+      ! tracer flux at w-point: we use -vsed (downward flux)  with simplification : no e1*e2
+      DO jk = 2, jpk
+         ! AXY (17/07/14): change "0.d0" to "0."
+         ! zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdet),0.d0) * tmask(:,:,jk-1)
+         zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdet),0.) * tmask(:,:,jk-1)
+         !
+         ! AXY (16/01/14): stop sinking in upper 10m to reduce model instability 
+         !                 in shallower grid cells
+         ! if ( jk .lt. 9 ) zwork(:,:,jk) = 0.e0
+      END DO
+      !
+      ! tracer flux divergence at t-point added to the general trend
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               ztra  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+               tra(ji,jj,jk,jpdet) = tra(ji,jj,jk,jpdet) + ztra
+# if defined key_trc_diabio
+               trbio(ji,jj,jk,8) = ztra
+# endif
+               IF (lk_iomput .AND. .NOT. ln_diatrc) THEN
+                     IF( med_diag%DSED%dgsave ) THEN
+                         zw2d(ji,jj) = zw2d(ji,jj) + ztra * fse3t(ji,jj,jk) * 86400.
+                      ENDIF   
+               ELSE IF( ln_diatrc )  THEN
+                    trc2d(ji,jj,8) = trc2d(ji,jj,8) + ztra * fse3t(ji,jj,jk) * 86400.
+               ENDIF    
+                
+            END DO
+         END DO
+      END DO
+      !
+# if defined key_trc_diabio
+      CALL lbc_lnk (trbio(:,:,1,8), 'T', 1. )                    ! Lateral boundary conditions on trcbio
+# endif
+      IF( ln_diatrc ) CALL lbc_lnk( trc2d(:,:,8), 'T', 1. )      ! Lateral boundary conditions on trc2d
+      !!
+      IF (lk_iomput .AND. .NOT. ln_diatrc) THEN
+           IF( med_diag%DSED%dgsave ) THEN
+                CALL iom_put( "DSED"  ,  zw2d)
+                CALL wrk_dealloc( jpi, jpj,    zw2d  )
+            ENDIF
+      ELSE IF (lk_iomput .AND. ln_diatrc)  THEN    
+          CALL iom_put( "DSED",trc2d(:,:,8) )
+      ENDIF
+      !!
+# if defined key_roam
+
+      ! sedimentation of detrital carbon : upstream scheme
+      ! --------------------------------------------------
+      !
+      zwork(:,:,:) = 0.e0        ! initialisation of sinking variable
+      ! for detrital carbon sedimentation only - jpdtc
+      zwork(:,:,1  ) = 0.e0      ! surface value set to zero
+      zwork(:,:,jpk) = 0.e0      ! bottom value  set to zero
+      !
+      ! tracer flux at w-point: we use -vsed (downward flux)  with simplification : no e1*e2
+      DO jk = 2, jpk
+         ! AXY (17/07/14): change "0.d0" to "0."
+         ! zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdtc),0.d0) * tmask(:,:,jk-1)
+         zwork(:,:,jk) = -vsed * max(trn(:,:,jk-1,jpdtc),0.) * tmask(:,:,jk-1)
+         !
+         ! AXY (16/01/14): stop sinking in upper 10m to reduce model instability 
+         !                 in shallower grid cells
+         ! if ( jk .lt. 9 ) zwork(:,:,jk) = 0.e0
+      END DO
+      !
+      ! tracer flux divergence at t-point added to the general trend
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1,jpi
+               ztra  = - ( zwork(ji,jj,jk) - zwork(ji,jj,jk+1) ) / fse3t(ji,jj,jk)
+               tra(ji,jj,jk,jpdtc) = tra(ji,jj,jk,jpdtc) + ztra
+!! #  if defined key_trc_diabio
+!!                trbio(ji,jj,jk,8) = ztra
+!! #  endif
+!!             IF( ln_diatrc ) &
+!!                &  trc2d(ji,jj,8) = trc2d(ji,jj,8) + ztra * fse3t(ji,jj,jk) * 86400.
+            END DO
+         END DO
+      END DO
+      !
+!! #  if defined key_trc_diabio
+!!       CALL lbc_lnk (trbio(:,:,1,8), 'T', 1. )                    ! Lateral boundary conditions on trcbio
+!! #  endif
+!!       IF( ln_diatrc ) CALL lbc_lnk( trc2d(:,:,8), 'T', 1. )      ! Lateral boundary conditions on trc2d
+!! #  if defined key_iomput
+!!       CALL iom_put( "DSED",trc2d(:,:,8) )
+!! #  endif
+
+# endif
+
+      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
+         WRITE(charout, FMT="('sed')")
+         CALL prt_ctl_trc_info(charout)
+         CALL prt_ctl_trc(tab4d=tra, mask=tmask, clinfo=ctrcnm)
+      ENDIF
+
+   END SUBROUTINE trc_sed_medusa
+
+   !! ======================================================================
+   !! ======================================================================
+   !! ======================================================================
+
+   !! AXY (10/02/09)
+   !! JPALM -- 31-03-2016 -- Completely change trc_sed_medusa_sbc.
+   !!                     -- We now need to read dust file through a namelist.
+   !!                     To be able to use time varying dust depositions from
+   !!                     -- copy and adapt the PISCES p4z_sbc_ini subroutine
+   !!                     -- Only use the dust related part.      
+   SUBROUTINE trc_sed_medusa_sbc(kt)
+
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE trc_sed_medusa_sbc  ***
+      !!
+      !! ** Purpose :   Read and dust namelist and files.
+      !!                The interpolation is done in trc_sed through 
+      !!                "CALL fld_read( kt, 1, sf_dust )"
+      !!
+      !! ** Method  :   Read the sbc namelist, and the adapted dust file, if required
+      !!                called at the first timestep (nittrc000)
+      !!
+      !! ** input   :   -- namelist sbc ref and cfg
+      !!                -- external netcdf files
+      !!
+      !!----------------------------------------------------------------------
+      !! * arguments
+      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
+      INTEGER  :: ji, jj, jk, jm, ifpr
+      INTEGER  :: ii0, ii1, ij0, ij1
+      INTEGER  :: numdust
+      INTEGER  :: ierr 
+      INTEGER  :: jfld                ! dummy loop arguments
+      INTEGER  :: ios                 ! Local integer output status for namelist read
+      INTEGER  :: isrow               ! index for ORCA1 starting row
+      REAL(wp) :: ztimes_dust
+      REAL(wp), DIMENSION(nbtimes) :: zsteps                 ! times records
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zdust
+      !
+      CHARACTER(len=100)         ::  cn_dir       ! Root directory for location of ssr files
+      TYPE(FLD_N), DIMENSION(1)  ::   slf_d       ! array of namelist informations on the fields to read
+      TYPE(FLD_N)                ::   sn_dust     ! informations about the fields to be read
+      !
+      NAMELIST/nammedsbc/cn_dir, sn_dust, bdustfer 
+
+      !!---------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('trc_sed_medusa_sbc')
+      !
+      !                            !* set file information
+      REWIND( numnatp_ref )        ! Namelist nammedsbc in reference namelist : MEDUSA external sources of Dust
+      READ  ( numnatp_ref, nammedsbc, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammedsbc in reference namelist', lwp )
+
+      REWIND( numnatp_cfg )        ! Namelist nammedsbc in configuration namelist : MEDUSA external sources of Dust
+      READ  ( numnatp_cfg, nammedsbc, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammedsbc in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonp, nammedsbc )
+
+      IF(lwp) THEN
+          WRITE(numout,*) ' '
+          WRITE(numout,*) ' namelist : nammedsbc '
+          WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~ '
+          WRITE(numout,*) '    dust input from the atmosphere bdustfer     = ', bdustfer
+      END IF
+
+      ! dust input from the atmosphere
+      ! ------------------------------
+      IF( bdustfer ) THEN
+         !
+         IF(lwp) WRITE(numout,*) '    initialize dust input from atmosphere '
+         IF(lwp) WRITE(numout,*) '    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         !
+         !! already allocated in sms_medusa
+         !!ALLOCATE( dust(jpi,jpj) )    ! allocation
+         !
+         slf_d(1) = sn_dust                          ! store namelist information in an array
+         !
+         ALLOCATE( sf_dust(1), STAT=ierr )           !* allocate and fill sf_sst (forcing structure) with sn_sst
+         IF( ierr > 0 )   CALL ctl_stop( 'STOP', 'trc_sed_medusa_sbc: unable to allocate sf_dust structure' )
+         ALLOCATE( sf_dust(1)%fnow(jpi,jpj,1))
+         IF( slf_d(1)%ln_tint )     ALLOCATE( sf_dust(1)%fdta(jpi,jpj,1,2) )
+         !
+         CALL fld_fill( sf_dust, slf_d, cn_dir, 'trc_sed_medusa_sbc', 'Atmospheric dust deposition', 'nammedsed' )
+         !
+         CALL fld_read( kt, 1, sf_dust )
+         dust(:,:) = sf_dust(1)%fnow(:,:,1)
+         !
+      ELSEIF (lk_oasis) THEN
+         dust = Dust_in_cpl
+      ELSE
+         dust(:,:) = 0.0
+      END IF
+      !
+      zirondep(:,:) = 0.e0     !! Initialisation of deposition variables
+      zirondep(:,:) = dust(:,:) * Fe_dust_mratio / xfe_mass * 1.e6 * 86400.      !! mmol-Fe/m2/d
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('trc_sed_medusa_sbc')
+      !
+   END SUBROUTINE trc_sed_medusa_sbc
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No MEDUSA bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE trc_sed_medusa( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_sed_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sed_medusa
+#endif 
+
+   !!======================================================================
+END MODULE  trcsed_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90	(revision 7693)
@@ -0,0 +1,104 @@
+MODULE trcsms_medusa
+   !!======================================================================
+   !!                         ***  MODULE trcsms_medusa  ***
+   !! TOP :   Main module of the MEDUSA tracers
+   !!======================================================================
+   !! History :   2.0  !  2007-12  (C. Ethe, G. Madec) Original code
+   !!              -   !  2008-08  (K. Popova) adaptation for MEDUSA
+   !!              -   !  2008-11  (A. Yool) continuing adaptation for MEDUSA
+   !!              -   !  2010-03  (A. Yool) updated for branch inclusion
+   !!----------------------------------------------------------------------
+#if defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                       bio tracers
+   !!----------------------------------------------------------------------
+   !! trc_sms_medusa   : MEDUSA_TRC model main routine 
+   !!----------------------------------------------------------------------
+   USE par_trc         ! TOP parameters
+   USE oce_trc
+   USE trc
+   USE trcbio_medusa
+   USE trcopt_medusa
+   USE trcsed_medusa
+   USE trcavg_medusa
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   trc_sms_medusa   ! called by trcsms.F90 module
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 2.0 , LOCEAN-IPSL (2007) 
+   !! $Id$
+   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE trc_sms_medusa( kt )
+      !!----------------------------------------------------------------------
+      !!                     ***  trc_sms_medusa  ***  
+      !!
+      !! ** Purpose :   main routine of MEDUSA_TRC model
+      !!
+      !! ** Method  : - 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) :: kt   ! ocean time-step index
+
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA inside trc_sms_medusa'
+         CALL flush(numout)
+# endif
+
+      IF( kt == nittrc000 ) THEN
+       IF(lwp) WRITE(numout,*)
+       IF(lwp) WRITE(numout,*) ' trc_sms_medusa:  MEDUSA model'
+       IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+      ENDIF
+
+      CALL trc_avg_medusa( kt )   ! rolling average module
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA done trc_avg_medusa'
+         CALL flush(numout)
+# endif
+
+      CALL trc_opt_medusa( kt )   ! optical model
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA done trc_opt_medusa'
+         CALL flush(numout)
+# endif
+
+# if defined key_kill_medusa
+      !! MEDUSA skipped
+      IF(lwp) WRITE(numout,*) ' MEDUSA killed at kt =', kt
+      CALL flush(numout)
+# else
+      CALL trc_bio_medusa( kt )   ! biological model
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA done trc_bio_medusa'
+         CALL flush(numout)
+# endif
+
+      CALL trc_sed_medusa( kt )   ! sedimentation model
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA done trc_sed_medusa'
+         CALL flush(numout)
+# endif
+# endif
+
+   END SUBROUTINE trc_sms_medusa
+   
+#else
+   !!----------------------------------------------------------------------
+   !!   Dummy module                                        No MEDUSA model
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE trc_sms_medusa( kt )             ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'trc_sms_medusa: You should not have seen this print! error?', kt
+   END SUBROUTINE trc_sms_medusa
+#endif
+
+   !!======================================================================
+END MODULE trcsms_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcwri_medusa.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcwri_medusa.F90	(revision 7693)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcwri_medusa.F90	(revision 7693)
@@ -0,0 +1,60 @@
+MODULE trcwri_medusa
+   !!======================================================================
+   !!                       *** MODULE trcwri ***
+   !!    MEDUSA :   Output of MEDUSA tracers
+   !!======================================================================
+   !! History :   1.0  !  2009-05 (C. Ethe)  Original code
+   !!             1.1  !  2013-05 (A. Yool)  converted for MEDUSA
+   !!----------------------------------------------------------------------
+#if defined key_top && defined key_iomput && defined key_medusa
+   !!----------------------------------------------------------------------
+   !!   'key_medusa'                                           MEDUSA model
+   !!----------------------------------------------------------------------
+   !! trc_wri_medusa   :  outputs of concentration fields
+   !!----------------------------------------------------------------------
+   USE trc         ! passive tracers common variables 
+   USE sms_medusa  ! MEDUSA variables
+   USE iom         ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC trc_wri_medusa 
+
+CONTAINS
+
+   SUBROUTINE trc_wri_medusa
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE trc_wri_trc  ***
+      !!
+      !! ** Purpose :   output passive tracers fields 
+      !!---------------------------------------------------------------------
+      CHARACTER (len=20)   :: cltra
+      INTEGER              :: jn
+      !!---------------------------------------------------------------------
+ 
+      ! write the tracer concentrations in the file
+      ! ---------------------------------------
+      DO jn = jp_msa0, jp_msa1
+         cltra = TRIM( ctrcnm(jn) )                  ! short title for tracer
+         CALL iom_put( cltra, trn(:,:,:,jn) )
+      END DO
+      !
+   END SUBROUTINE trc_wri_medusa
+
+#else
+   !!----------------------------------------------------------------------
+   !!  Dummy module :                                     No passive tracer
+   !!----------------------------------------------------------------------
+   PUBLIC trc_wri_medusa
+CONTAINS
+   SUBROUTINE trc_wri_medusa                     ! Empty routine  
+   END SUBROUTINE trc_wri_medusa
+#endif
+
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id$
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!======================================================================
+END MODULE trcwri_medusa
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 7693)
@@ -27,4 +27,5 @@
    USE ldftra_oce      ! lateral diffusion coefficient on tracers
    USE prtctl_trc      ! Print control
+   !! USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
 
    IMPLICIT NONE
@@ -71,5 +72,5 @@
       INTEGER, INTENT(in) ::   kt   ! ocean time-step index
       !
-      INTEGER ::   jk 
+      INTEGER ::   jk, jn 
       CHARACTER (len=22) ::   charout
       REAL(wp), POINTER, DIMENSION(:,:,:) :: zun, zvn, zwn  ! effective velocity
@@ -105,4 +106,11 @@
       zvn(:,:,jpk) = 0._wp                                                     ! no transport trough the bottom
       zwn(:,:,jpk) = 0._wp                                                     ! no transport trough the bottom
+      ! 
+      !! Jpalm -- 14-01-2016 -- restart and proc pb - try this... 
+      !! DO jn = 1, jptra
+      !!   CALL lbc_lnk( trn(:,:,:,jn), 'T', 1. )
+      !!   CALL lbc_lnk( trb(:,:,:,jn), 'T', 1. )
+      !! END DO
+      !
 
       IF( lk_traldf_eiv .AND. .NOT. ln_traldf_grif )   &  ! add the eiv transport (if necessary)
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 7693)
@@ -102,15 +102,18 @@
          IF(lwp) WRITE(numout,*) '~~~~~~~ '
 
-         IF( ln_rsttr .AND.    &                     ! Restart: read in restart  file
-            iom_varid( numrtr, 'sbc_'//TRIM(ctrcnm(1))//'_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nittrc000-nn_dttrc surface tracer content forcing fields red in the restart file'
-            zfact = 0.5_wp
-            DO jn = 1, jptra
-               CALL iom_get( numrtr, jpdom_autoglo, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc_b(:,:,jn) )   ! before tracer content sbc
-            END DO
-         ELSE                                         ! No restart or restart not found: Euler forward time stepping
+         !! JPALM -- 12-01-2016 -- problem after restart, maybe because of this...
+         !!                     -- set sbc_trc_b to 0 after restart, first, to check.
+         !!------------------------------------------------------------------------------
+        ! IF( ln_rsttr .AND.    &                     ! Restart: read in restart  file
+        !    iom_varid( numrtr, 'sbc_'//TRIM(ctrcnm(1))//'_b', ldstop = .FALSE. ) > 0 ) THEN
+        !    IF(lwp) WRITE(numout,*) '          nittrc000-nn_dttrc surface tracer content forcing fields red in the restart file'
+        !    zfact = 0.5_wp
+        !    DO jn = 1, jptra
+        !       CALL iom_get( numrtr, jpdom_autoglo, 'sbc_'//TRIM(ctrcnm(jn))//'_b', sbc_trc_b(:,:,jn) )   ! before tracer content sbc
+        !    END DO
+        ! ELSE                                         ! No restart or restart not found: Euler forward time stepping
            zfact = 1._wp
            sbc_trc_b(:,:,:) = 0._wp
-         ENDIF
+        ! ENDIF
       ELSE                                         ! Swap of forcing fields
          IF( ln_top_euler ) THEN
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 7693)
@@ -27,4 +27,8 @@
    USE trcsbc          ! surface boundary condition          (trc_sbc routine)
    USE zpshde          ! partial step: hor. derivative       (zps_hde routine)
+# if defined key_debug_medusa
+   USE trcrst
+# endif
+
 
 #if defined key_agrif
@@ -65,8 +69,18 @@
          !
                                 CALL trc_sbc( kstp )            ! surface boundary condition
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_trp after trc_sbc at kt =', kstp
+         CALL trc_rst_tra_stat
+         CALL flush(numout)
+# endif
          IF( lk_trabbl )        CALL trc_bbl( kstp )            ! advective (and/or diffusive) bottom boundary layer scheme
          IF( ln_trcdmp )        CALL trc_dmp( kstp )            ! internal damping trends
          IF( ln_trcdmp_clo )    CALL trc_dmp_clo( kstp )        ! internal damping trends on closed seas only
                                 CALL trc_adv( kstp )            ! horizontal & vertical advection 
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_trp after trc_adv at kt =', kstp
+         CALL trc_rst_tra_stat
+         CALL flush(numout)
+# endif
                                 CALL trc_ldf( kstp )            ! lateral mixing
          IF( .NOT. lk_offline .AND. lk_zdfkpp )    &
@@ -76,5 +90,15 @@
 #endif
                                 CALL trc_zdf( kstp )            ! vertical mixing and after tracer fields
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_trp after trc_zdf at kt =', kstp
+         CALL trc_rst_tra_stat
+         CALL flush(numout)
+# endif
                                 CALL trc_nxt( kstp )            ! tracer fields at next time step     
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_trp after trc_nxt at kt =', kstp
+         CALL trc_rst_tra_stat
+         CALL flush(numout)
+# endif
          IF( ln_trcrad )        CALL trc_rad( kstp )            ! Correct artificial negative concentrations
 
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/par_trc.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/par_trc.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/par_trc.F90	(revision 7693)
@@ -8,4 +8,5 @@
    !!             1.0  !  2004-03  (C. Ethe) Free form and module
    !!             2.0  !  2007-12  (C. Ethe, G. Madec)  revised architecture
+   !!              -   !  2014-06  (A. Yool, J. Palmieri) adding MEDUSA-2
    !!----------------------------------------------------------------------
    USE par_kind          ! kind parameters
@@ -15,4 +16,7 @@
    USE par_cfc       ! CFC 11 and 12 tracers
    USE par_my_trc    ! user defined passive tracers
+   USE par_medusa    ! MEDUSA model
+   USE par_idtra     ! Idealize tracer
+   USE par_age       ! AGE  tracer
 
    IMPLICIT NONE
@@ -24,9 +28,9 @@
    ! Passive tracers : Total size
    ! ---------------               ! total number of passive tracers, of 2d and 3d output and trend arrays
-   INTEGER, PUBLIC,  PARAMETER ::   jptra    =  jp_pisces     + jp_cfc     + jp_c14b    + jp_my_trc
-   INTEGER, PUBLIC,  PARAMETER ::   jpdia2d  =  jp_pisces_2d  + jp_cfc_2d  + jp_c14b_2d + jp_my_trc_2d
-   INTEGER, PUBLIC,  PARAMETER ::   jpdia3d  =  jp_pisces_3d  + jp_cfc_3d  + jp_c14b_3d + jp_my_trc_3d
+   INTEGER, PUBLIC,  PARAMETER ::   jptra    =  jp_pisces     + jp_cfc     + jp_c14b    + jp_my_trc    + jp_medusa    + jp_idtra     + jp_age
+   INTEGER, PUBLIC,  PARAMETER ::   jpdia2d  =  jp_pisces_2d  + jp_cfc_2d  + jp_c14b_2d + jp_my_trc_2d + jp_medusa_2d + jp_idtra_2d  + jp_age_2d
+   INTEGER, PUBLIC,  PARAMETER ::   jpdia3d  =  jp_pisces_3d  + jp_cfc_3d  + jp_c14b_3d + jp_my_trc_3d + jp_medusa_3d + jp_idtra_3d  + jp_age_3d
    !                     ! total number of sms diagnostic arrays
-   INTEGER, PUBLIC,  PARAMETER ::   jpdiabio =  jp_pisces_trd + jp_cfc_trd + jp_c14b_trd + jp_my_trc_trd
+   INTEGER, PUBLIC,  PARAMETER ::   jpdiabio =  jp_pisces_trd + jp_cfc_trd + jp_c14b_trd + jp_my_trc_trd + jp_medusa_trd + jp_idtra_trd + jp_age_trd
    
    !  1D configuration ("key_c1d")
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 7693)
@@ -7,4 +7,5 @@
    !!              -   !  2000-04  (O. Aumont, M.A. Foujols)  HAMOCC3 and P3ZD
    !!   NEMO      1.0  !  2004-03  (C. Ethe)  Free form and module
+   !!             3.6  !  2016-11  (A. Yool)  Updated diags for CMIP6
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -104,4 +105,54 @@
    END TYPE DIAG
 
+#if defined key_medusa && defined key_iomput
+   TYPE, PUBLIC :: BDIAG
+      LOGICAL              :: dgsave
+   END TYPE BDIAG
+   
+   TYPE, PUBLIC :: DIAG_IOM
+      TYPE(BDIAG) INVTN, INVTSI, INVTFE, PRN, MPN, PRD, MPD, DSED, OPAL, OPALDISS, GMIPn,            &
+                  GMID, MZMI, GMEPN, GMEPD, GMEZMI, GMED, MZME, DEXP, DETN, MDET, AEOLIAN, BENTHIC,  &
+                  SCAVENGE, PN_JLIM, PN_NLIM, PN_FELIM, PD_JLIM, PD_NLIM, PD_FELIM, PD_SILIM,        &
+                  PDSILIM2, SDT__100, SDT__200, SDT__500, SDT_1000, TOTREG_N, TOTRG_SI, REG__100,    &
+                  REG__200, REG__500, REG_1000, FASTN, FASTSI, FASTFE, FASTC, FASTCA, FDT__100,      &
+                  FDT__200, FDT__500, FDT_1000, RG__100F, RG__200F, RG__500F, RG_1000F, FDS__100,    &
+                  FDS__200, FDS__500, FDS_1000, RGS_100F, RGS_200F, RGS_500F, RGS1000F, REMINN,      &
+                  REMINSI, REMINFE, REMINC, REMINCA, SEAFLRN, SEAFLRSI, SEAFLRFE, SEAFLRC, SEAFLRCA, &
+                  MED_QSR, MED_XPAR, INTFLX_N, INTFLX_SI, INTFLX_FE, INT_PN, INT_PD, ML_PRN, ML_PRD, &
+                  OCAL_CCD, OCAL_LVL, FE_0000, FE_0100, FE_0200, FE_0500, FE_1000, MED_XZE, WIND,    &
+                  ATM_PCO2, OCN_PH, OCN_PCO2, OCNH2CO3, OCN_HCO3, OCN_CO3, CO2FLUX, OM_CAL, OM_ARG,  &
+                  TCO2, TALK, KW660, ATM_PP0, O2FLUX, O2SAT, CAL_CCD, ARG_CCD, SFR_OCAL, SFR_OARG,   &
+                  N_PROD, N_CONS, C_PROD, C_CONS, O2_PROD, O2_CONS, O2_ANOX, RR_0100, RR_0500,       &
+                  RR_1000, IBEN_N, IBEN_FE, IBEN_C, IBEN_SI, IBEN_CA, OBEN_N, OBEN_FE, OBEN_C,       &
+                  OBEN_SI, OBEN_CA, BEN_N, BEN_FE, BEN_C, BEN_SI, BEN_CA, RUNOFF, RIV_N, RIV_SI,     &
+                  RIV_C, RIV_ALK, DETC, SDC__100, SDC__200, SDC__500, SDC_1000, INVTC, INVTALK,      &
+                  INVTO2, LYSO_CA, COM_RESP, PN_LLOSS, PD_LLOSS, ZI_LLOSS, ZE_LLOSS, ZI_MES_N,       &
+                  ZI_MES_D, ZI_MES_C, ZI_MESDC, ZI_EXCR, ZI_RESP, ZI_GROW, ZE_MES_N, ZE_MES_D,       &
+                  ZE_MES_C, ZE_MESDC, ZE_EXCR, ZE_RESP, ZE_GROW, MDETC, GMIDC, GMEDC,                &
+                  INT_ZMI, INT_ZME, INT_DET, INT_DTC, DMS_SURF, DMS_ANDR, DMS_SIMO, DMS_ARAN,        &
+                  DMS_HALL, ATM_XCO2, OCN_FCO2, ATM_FCO2, OCN_RHOSW, OCN_SCHCO2, OCN_KWCO2,          &
+                  OCN_K0, CO2STARAIR, OCN_DPCO2,                                                     & ! end of regular 2D
+                  TPP3, DETFLUX3, REMIN3N, PH3, OM_CAL3,                                             & ! end of regular 3D
+! AXY (11/11/16): additional CMIP6 2D diagnostics
+                  epC100, epCALC100, epN100, epSI100,                                                &
+                  FGCO2, INTDISSIC, INTDISSIN, INTDISSISI, INTTALK, O2min, ZO2min,                   &
+                  FBDDTALK, FBDDTDIC, FBDDTDIFE, FBDDTDIN, FBDDTDISI,                                & 
+! AXY (11/11/16): additional CMIP6 3D diagnostics
+                  TPPD3,                                                                             &
+                  BDDTALK3, BDDTDIC3, BDDTDIFE3, BDDTDIN3, BDDTDISI3,                                & 
+                  FD_NIT3, FD_SIL3, FD_CAR3, FD_CAL3,                                                & 
+                  CO33, CO3SATARAG3, CO3SATCALC3, DCALC3,                                            &
+                  EXPC3, EXPN3, EXPCALC3, EXPSI3,                                                    &
+                  FEDISS3, FESCAV3,                                                                  &
+                  MIGRAZP3, MIGRAZD3, MEGRAZP3, MEGRAZD3, MEGRAZZ3,                                  &
+                  O2SAT3, PBSI3, PCAL3, REMOC3,                                                      &
+                  PNLIMJ3, PNLIMN3, PNLIMFE3, PDLIMJ3, PDLIMN3, PDLIMFE3, PDLIMSI3       
+                  !!
+                  !! list of all MEDUSA diagnostics that could be called by iom_use
+   END TYPE DIAG_IOM  
+   !!
+   TYPE(DIAG_IOM), PUBLIC :: med_diag  ! define which diagnostics are asked in outputs
+# endif                   
+
    !! information for inputs
    !! --------------------------------------------------
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 7693)
@@ -8,4 +8,5 @@
    !!            2.0  ! 2005-10 (C. Ethe, G. Madec) revised architecture
    !!            4.0  ! 2011-01 (A. R. Porter, STFC Daresbury) dynamical allocation
+   !!             -   ! 2014-06 (A. Yool, J. Palmieri) adding MEDUSA-2
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -24,4 +25,7 @@
    USE trcini_c14b     ! C14 bomb initialisation
    USE trcini_my_trc   ! MY_TRC   initialisation
+   USE trcini_medusa   ! MEDUSA   initialisation
+   USE trcini_idtra    ! idealize tracer initialisation
+   USE trcini_age      ! AGE      initialisation
    USE trcdta          ! initialisation from files
    USE daymod          ! calendar manager
@@ -77,5 +81,7 @@
          &   CALL ctl_warn(' Coupling with passive tracers and used of diurnal cycle. &
          & Computation of a daily mean shortwave for some biogeochemical models) ')
-
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+          !!!!! CHECK For MEDUSA
+          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       IF( nn_cla == 1 )   &
          &  CALL ctl_stop( ' Cross Land Advection not yet implemented with passive tracer ; nn_cla must be 0' )
@@ -98,9 +104,22 @@
 
       IF( lk_pisces  )       CALL trc_ini_pisces       ! PISCES  bio-model
+      IF( lk_medusa  )       CALL trc_ini_medusa       ! MEDUSA  tracers
+      IF( lk_idtra   )       CALL trc_ini_idtra        ! Idealize tracers
       IF( lk_cfc     )       CALL trc_ini_cfc          ! CFC     tracers
       IF( lk_c14b    )       CALL trc_ini_c14b         ! C14 bomb  tracer
+      IF( lk_age     )       CALL trc_ini_age          ! AGE       tracer
       IF( lk_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
 
       CALL trc_ice_ini                                 ! Tracers in sea ice
+
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' sms init OK'
+         IF (lwp) write (numout,*) ' next: open tracer.stat'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
 
       IF( lwp ) THEN
@@ -110,9 +129,28 @@
       ENDIF
 
-      IF( ln_trcdta )      CALL trc_dta_init(jptra)
-
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) 'open tracer.stat -- OK'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+
+
+      IF( ln_trcdta ) THEN
+#if defined key_medusa
+         IF(lwp) WRITE(numout,*) 'AXY: calling trc_dta_init'
+         IF(lwp) CALL flush(numout)
+#endif
+         CALL trc_dta_init(jptra)
+      ENDIF
 
       IF( ln_rsttr ) THEN
         !
+#if defined key_medusa
+        IF(lwp) WRITE(numout,*) 'AXY: calling trc_rst_read'
+        IF(lwp) CALL flush(numout)
+#endif
         CALL trc_rst_read              ! restart from a file
         !
@@ -141,5 +179,23 @@
         ENDIF
         !
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' before trb = trn'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+        !
         trb(:,:,:,:) = trn(:,:,:,:)
+        ! 
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' trb = trn -- OK'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
         ! 
       ENDIF
@@ -150,10 +206,25 @@
       IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav )   &
         &    CALL zps_hde_isf( nit000, jptra, trn, pgtu=gtru, pgtv=gtrv, pgtui=gtrui, pgtvi=gtrvi )       ! tracers at the bottom ocean level
-
-
+      !
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' partial step -- OK'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
       !
       IF( nn_dttrc /= 1 )        CALL trc_sub_ini      ! Initialize variables for substepping passive tracers
       !
-
+# if defined key_debug_medusa
+         IF (lwp) write (numout,*) '------------------------------'
+         IF (lwp) write (numout,*) 'Jpalm - debug'
+         IF (lwp) write (numout,*) ' in trc_init'
+         IF (lwp) write (numout,*) ' before initiate tracer contents'
+         IF (lwp) write (numout,*) ' '
+         CALL flush(numout)
+# endif
+      !
       trai(:) = 0._wp                                                   ! initial content of all tracers
       DO jn = 1, jptra
@@ -168,4 +239,12 @@
          WRITE(numout,*) '          *** Total inital content of all tracers '
          WRITE(numout,*)
+# if defined key_debug_medusa
+         CALL flush(numout)
+# endif
+         !
+# if defined key_debug_medusa
+         WRITE(numout,*) ' litle check :  ', ctrcnm(1)
+         CALL flush(numout)
+# endif
          DO jn = 1, jptra
             WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), trai(jn)
@@ -180,4 +259,14 @@
          CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
       ENDIF
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'trc_init : passive tracer set up completed'
+      IF(lwp) WRITE(numout,*) '~~~~~~~'
+      IF(lwp) CALL flush(numout)
+# if defined key_debug_medusa
+         CALL trc_rst_stat
+         CALL flush(numout)
+# endif
+
 9000  FORMAT(' tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
       !
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcnam.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 7693)
@@ -11,4 +11,5 @@
    !!              -   !  2001-01 (E Kestenare) suppress ndttrc=1 for CEN2 and TVD schemes
    !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
+   !!              -   !  2014-06  (A. Yool, J. Palmieri) adding MEDUSA-2
    !!----------------------------------------------------------------------
 #if defined key_top
@@ -25,4 +26,7 @@
    USE trcnam_c14b       ! C14 SMS namelist
    USE trcnam_my_trc     ! MY_TRC SMS namelist
+   USE trcnam_medusa     ! MEDUSA namelist
+   USE trcnam_idtra      ! Idealise tracer namelist
+   USE trcnam_age        ! AGE SMS namelist
    USE trd_oce       
    USE trdtrc_oce
@@ -54,18 +58,56 @@
       !! ** Method  : - read passive tracer namelist 
       !!              - read namelist of each defined SMS model
-      !!                ( (PISCES, CFC, MY_TRC )
-      !!---------------------------------------------------------------------
-      INTEGER  ::   jn                  ! dummy loop indice
+      !!                ( (PISCES, CFC, MY_TRC, MEDUSA, IDTRA, Age )
+      !!---------------------------------------------------------------------
+      INTEGER  ::   jn, jk                     ! dummy loop indice
       !                                        !   Parameters of the run 
       IF( .NOT. lk_offline ) CALL trc_nam_run
       
       !                                        !  passive tracer informations
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_trc'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       CALL trc_nam_trc
       
       !                                        !   Parameters of additional diagnostics
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_trc -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_dia'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+
       CALL trc_nam_dia
 
       !                                        !   namelist of transport
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_dia -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_trp'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       CALL trc_nam_trp
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_trp -- OK'
+      IF (lwp) write (numout,*) 'continue trc_nam '
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
+      !
 
 
@@ -89,4 +131,7 @@
          END DO
          WRITE(numout,*) ' '
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
       ENDIF
 
@@ -107,6 +152,15 @@
             WRITE(numout,*)
          ENDIF
-      ENDIF
-
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
+      ENDIF
+
+# if defined key_debug_medusa
+       DO jk = 1, jpk
+          WRITE(numout,*) '  level number: ', jk, 'rdttrc: ',rdttrc(jk),'rdttra: ', rdttra(jk),'nn_dttrc: ', nn_dttrc
+       END DO
+      CALL flush(numout)
+# endif
       
       rdttrc(:) = rdttra(:) * FLOAT( nn_dttrc )   ! vertical profile of passive tracer time-step
@@ -116,4 +170,7 @@
         WRITE(numout,*) '    Passive Tracer  time step    rdttrc  = ', rdttrc(1)
         WRITE(numout,*) 
+# if defined key_debug_medusa
+      CALL flush(numout)
+# endif
       ENDIF
 
@@ -143,11 +200,30 @@
                IF( ln_trdtrc(jn) ) WRITE(numout,*) '    compute ML trends for tracer number :', jn
             END DO
+         WRITE(numout,*) ' '
+         CALL flush(numout)
          ENDIF
 #endif
 
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'just before ice module for tracers call : '
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
 
       ! Call the ice module for tracers
       ! -------------------------------
       CALL trc_nam_ice
+
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'Will now read SMS namelists : '
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
 
       ! namelist of SMS
@@ -156,17 +232,84 @@
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          PISCES not used'
       ENDIF
-
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_pisces  -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_medusa'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+      IF( lk_medusa  ) THEN   ;   CALL trc_nam_medusa      ! MEDUSA  tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          MEDUSA not used'
+      ENDIF
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_medusa -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_idtra'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+      IF( lk_idtra   ) THEN   ;   CALL trc_nam_idtra       ! Idealize tracers
+      ELSE                    ;   IF(lwp) WRITE(numout,*) '          Idealize tracers not used'
+      ENDIF
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_idtra -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_cfc'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       IF( lk_cfc     ) THEN   ;   CALL trc_nam_cfc         ! CFC     tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          CFC not used'
       ENDIF
-
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_cfc -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_c14'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       IF( lk_c14b     ) THEN   ;   CALL trc_nam_c14b         ! C14 bomb     tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          C14 not used'
       ENDIF
-
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_c14 -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - just before CALL trc_nam_age'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
+      IF( lk_age     ) THEN  ;   CALL trc_nam_age         ! AGE     tracer
+      ELSE                   ;   IF(lwp) WRITE(numout,*) '          AGE not used'
+      ENDIF
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_nam_age -- OK'
+      IF (lwp) write (numout,*) 'in trc_nam - CALL trc_nam -- OK'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       IF( lk_my_trc  ) THEN   ;   CALL trc_nam_my_trc      ! MY_TRC  tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          MY_TRC not used'
       ENDIF
-      !
+       
+      IF(lwp)   CALL flush(numout)
    END SUBROUTINE trc_nam
 
@@ -216,4 +359,5 @@
          WRITE(numout,*) '   Use euler integration for TRC (y/n)          ln_top_euler  = ', ln_top_euler
          WRITE(numout,*) ' '
+        CALL flush(numout)
       ENDIF
       !
@@ -306,5 +450,6 @@
          ln_trc_wri(jn) =       sn_tracer(jn)%llsave
       END DO
-      
+      IF(lwp)  CALL flush(numout)      
+
     END SUBROUTINE trc_nam_trc
 
@@ -357,7 +502,16 @@
          WRITE(numout,*) '    frequency of outputs for biological trends  nn_writebio = ', nn_writebio
          WRITE(numout,*) ' '
-      ENDIF
-
-      IF( ln_diatrc .AND. .NOT. lk_iomput ) THEN 
+         CALL flush(numout)
+      ENDIF
+!!
+!! JPALM -- 17-07-2015 --
+!! MEDUSA is not yet up-to-date with the iom server.
+!! we use it for the main tracer, but not fully with diagnostics.
+!! will have to adapt it properly when visiting Christian Ethee
+!! for now, we change 
+!! IF( ln_diatrc .AND. .NOT. lk_iomput ) THEN
+!! to :
+!!
+      IF( ( ln_diatrc .AND. .NOT. lk_iomput ) .OR. ( ln_diatrc .AND. lk_medusa ) ) THEN 
          ALLOCATE( trc2d(jpi,jpj,jpdia2d), trc3d(jpi,jpj,jpk,jpdia3d),  &
            &       ctrc2d(jpdia2d), ctrc2l(jpdia2d), ctrc2u(jpdia2d) ,  & 
@@ -368,4 +522,6 @@
          trc3d(:,:,:,:) = 0._wp  ;   ctrc3d(:) = ' '   ;   ctrc3l(:) = ' '    ;    ctrc3u(:) = ' ' 
          !
+      !! ELSE IF  ( lk_iomput .AND. lk_medusa .AND. .NOT. ln_diatrc) THEN
+      !!    CALL trc_nam_iom_medusa
       ENDIF
 
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 7693)
@@ -27,5 +27,21 @@
    USE trcnam_trp
    USE iom
+   USE ioipsl, ONLY : ju2ymds    ! for calendar
    USE daymod
+   !! AXY (05/11/13): need these for MEDUSA to input/output benthic reservoirs
+   USE sms_medusa
+   USE trcsms_medusa
+   !!
+#if defined key_idtra
+   USE trcsms_idtra
+#endif
+   !!
+#if defined key_cfc
+   USE trcsms_cfc
+#endif
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE sbc_oce, ONLY: lk_oasis 
+   USE oce,     ONLY: CO2Flux_out_cpl, DMS_out_cpl  !! Coupling variable
+
    IMPLICIT NONE
    PRIVATE
@@ -35,4 +51,7 @@
    PUBLIC   trc_rst_wri       ! called by ???
    PUBLIC   trc_rst_cal
+   PUBLIC   trc_rst_stat
+   PUBLIC   trc_rst_dia_stat
+   PUBLIC   trc_rst_tra_stat
 
    !! * Substitutions
@@ -48,4 +67,7 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt       ! number of iteration
+      INTEGER             ::   iyear, imonth, iday
+      REAL (wp)           ::   zsec
+      REAL (wp)           ::   zfjulday
       !
       CHARACTER(LEN=20)   ::   clkt     ! ocean time-step define as a character
@@ -78,7 +100,26 @@
       ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1
       IF( kt == nitrst - 2*nn_dttrc .OR. nstock == nn_dttrc .OR. ( kt == nitend - nn_dttrc .AND. .NOT. lrst_trc ) ) THEN
-         ! beware of the format used to write kt (default is i8.8, that should be large enough)
-         IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
-         ELSE                        ;   WRITE(clkt,'(i8.8)') nitrst
+         IF ( ln_rstdate ) THEN
+            !! JPALM -- 22-12-2015 -- modif to get the good date on restart trc file name
+            !!                     -- the condition to open the rst file is not the same than for the dynamic rst.
+            !!                     -- here it - for an obscure reason - is open 2 time-step before the restart writing process
+            !!                     instead of 1.
+            !!                     -- i am not sure if someone forgot +1 in the if loop condition as
+            !!                     it is writen in all comments nitrst -2*nn_dttrc + 1 and the condition is 
+            !!                     nitrst - 2*nn_dttrc
+            !!                     -- nevertheless we didn't wanted to broke something already working 
+            !!                     and just adapted the part we added.
+            !!                     -- So instead of calling ju2ymds( fjulday + (rdttra(1)) 
+            !!                     we call ju2ymds( fjulday + (2*rdttra(1)) 
+            !!--------------------------------------------------------------------      
+            zfjulday = fjulday + (2*rdttra(1)) / rday
+            IF( ABS(zfjulday - REAL(NINT(zfjulday),wp)) < 0.1 / rday )   zfjulday = REAL(NINT(zfjulday),wp)   ! avoid truncation error
+            CALL ju2ymds( zfjulday + (2*rdttra(1)) / rday, iyear, imonth, iday, zsec )
+            WRITE(clkt, '(i4.4,2i2.2)') iyear, imonth, iday
+         ELSE
+            ! beware of the format used to write kt (default is i8.8, that should be large enough)
+            IF( nitrst > 1.0e9 ) THEN   ;   WRITE(clkt,*       ) nitrst
+            ELSE                        ;   WRITE(clkt,'(i8.8)') nitrst
+            ENDIF
          ENDIF
          ! create the file
@@ -101,5 +142,7 @@
       !! ** purpose  :   read passive tracer fields in restart files
       !!----------------------------------------------------------------------
-      INTEGER  ::  jn     
+      INTEGER  ::  jn, jl     
+      !! AXY (05/11/13): temporary variables
+      REAL(wp) ::    fq0,fq1,fq2
 
       !!----------------------------------------------------------------------
@@ -112,9 +155,210 @@
       DO jn = 1, jptra
          CALL iom_get( numrtr, jpdom_autoglo, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) )
+         trn(:,:,:,jn) = trn(:,:,:,jn) * tmask(:,:,:)
       END DO
 
       DO jn = 1, jptra
          CALL iom_get( numrtr, jpdom_autoglo, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
-      END DO
+         trb(:,:,:,jn) = trb(:,:,:,jn) * tmask(:,:,:)
+      END DO
+      !
+      !! AXY (09/06/14): the ARCHER version of MEDUSA-2 does not include an equivalent
+      !!                 call to MEDUSA-2 at this point; this suggests that the FCM
+      !!                 version of NEMO date significantly earlier than the current
+      !!                 version
+
+#if defined key_medusa
+      !! AXY (13/01/12): check if the restart contains sediment fields;
+      !!                 this is only relevant for simulations that include
+      !!                 biogeochemistry and are restarted from earlier runs
+      !!                 in which there was no sediment component
+      !!
+      IF( iom_varid( numrtr, 'B_SED_N', ldstop = .FALSE. ) > 0 ) THEN
+         !! YES; in which case read them
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields present - reading in ...'
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_N',  zb_sed_n(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_N',  zn_sed_n(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_FE', zb_sed_fe(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_FE', zn_sed_fe(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_SI', zb_sed_si(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_SI', zn_sed_si(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_C',  zb_sed_c(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_C',  zn_sed_c(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_SED_CA', zb_sed_ca(:,:) )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_SED_CA', zn_sed_ca(:,:) )
+      ELSE
+         !! NO; in which case set them to zero
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields absent - setting to zero ...'
+         zb_sed_n(:,:)  = 0.0   !! organic N
+         zn_sed_n(:,:)  = 0.0
+         zb_sed_fe(:,:) = 0.0   !! organic Fe
+         zn_sed_fe(:,:) = 0.0
+         zb_sed_si(:,:) = 0.0   !! inorganic Si
+         zn_sed_si(:,:) = 0.0
+         zb_sed_c(:,:)  = 0.0   !! organic C
+         zn_sed_c(:,:)  = 0.0
+         zb_sed_ca(:,:) = 0.0   !! inorganic C
+         zn_sed_ca(:,:) = 0.0
+      ENDIF
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment field stats (min, max, sum) ...'
+      call trc_rst_dia_stat(zn_sed_n(:,:), 'Sediment  N')
+      call trc_rst_dia_stat(zn_sed_fe(:,:), 'Sediment Fe')
+      call trc_rst_dia_stat(zn_sed_si(:,:), 'Sediment Si')
+      call trc_rst_dia_stat(zn_sed_c(:,:), 'Sediment C')
+      call trc_rst_dia_stat(zn_sed_ca(:,:), 'Sediment Ca')
+      !!
+      !! AXY (07/07/15): read in temporally averaged fields for DMS
+      !!                 calculations
+      !!
+      IF( iom_varid( numrtr, 'B_DMS_CHN', ldstop = .FALSE. ) > 0 ) THEN
+         !! YES; in which case read them
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS present - reading in ...'
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_DMS_CHN',  zb_dms_chn(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_DMS_CHN',  zn_dms_chn(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_DMS_CHD',  zb_dms_chd(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_DMS_CHD',  zn_dms_chd(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_DMS_MLD',  zb_dms_mld(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_DMS_MLD',  zn_dms_mld(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_DMS_QSR',  zb_dms_qsr(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_DMS_QSR',  zn_dms_qsr(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_DMS_DIN',  zb_dms_din(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_DMS_DIN',  zn_dms_din(:,:)  )
+      ELSE
+         !! NO; in which case set them to zero
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS absent - setting to zero ...'
+         zb_dms_chn(:,:)  = 0.0   !! CHN
+         zn_dms_chn(:,:)  = 0.0
+         zb_dms_chd(:,:)  = 0.0   !! CHD
+         zn_dms_chd(:,:)  = 0.0
+         zb_dms_mld(:,:)  = 0.0   !! MLD
+         zn_dms_mld(:,:)  = 0.0
+         zb_dms_qsr(:,:)  = 0.0   !! QSR
+         zn_dms_qsr(:,:)  = 0.0
+         zb_dms_din(:,:)  = 0.0   !! DIN
+         zn_dms_din(:,:)  = 0.0
+      ENDIF
+      !!  
+      !! JPALM 14-06-2016 -- add CO2 flux and DMS surf through the restart
+      !!                  -- needed for the coupling with atm
+      IF( iom_varid( numrtr, 'B_DMS_srf', ldstop = .FALSE. ) > 0 ) THEN
+         IF(lwp) WRITE(numout,*) 'DMS surf concentration - reading in ...'
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_DMS_srf',  zb_dms_srf(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_DMS_srf',  zn_dms_srf(:,:)  )
+      ELSE
+         IF(lwp) WRITE(numout,*) 'DMS surf concentration - setting to zero ...'
+         zb_dms_srf(:,:)  = 0.0   !! DMS
+         zn_dms_srf(:,:)  = 0.0
+      ENDIF
+      IF (lk_oasis) THEN
+         DMS_out_cpl(:,:) = zn_dms_srf(:,:)        !! Coupling variable
+      END IF
+      !!
+      IF( iom_varid( numrtr, 'B_CO2_flx', ldstop = .FALSE. ) > 0 ) THEN
+         IF(lwp) WRITE(numout,*) 'CO2 air-sea flux - reading in ...'
+         CALL iom_get( numrtr, jpdom_autoglo, 'B_CO2_flx',  zb_co2_flx(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'N_CO2_flx',  zn_co2_flx(:,:)  )
+      ELSE
+         IF(lwp) WRITE(numout,*) 'CO2 air-sea flux - setting to zero ...'
+         zb_co2_flx(:,:)  = 0.0   !! CO2 flx
+         zn_co2_flx(:,:)  = 0.0
+      ENDIF
+      IF (lk_oasis) THEN
+         CO2Flux_out_cpl(:,:) =  zn_co2_flx(:,:)   !! Coupling variable
+      END IF
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS stats (min, max, sum) ...'
+      call trc_rst_dia_stat(zn_dms_chn(:,:), 'DMS, CHN')
+      call trc_rst_dia_stat(zn_dms_chd(:,:), 'DMS, CHD')
+      call trc_rst_dia_stat(zn_dms_mld(:,:), 'DMS, MLD')
+      call trc_rst_dia_stat(zn_dms_qsr(:,:), 'DMS, QSR')
+      call trc_rst_dia_stat(zn_dms_din(:,:), 'DMS, DIN')
+      call trc_rst_dia_stat(zn_dms_srf(:,:), 'DMS surf')
+      call trc_rst_dia_stat(zn_co2_flx(:,:), 'CO2 flux')
+      !!  
+      !! JPALM 14-06-2016 -- add Carbonate chenistry variables through the restart
+      !!                  -- needed for monthly call of carb-chem routine and better reproducibility
+# if defined key_roam
+      IF( iom_varid( numrtr, 'pH_3D', ldstop = .FALSE. ) > 0 ) THEN
+         IF(lwp) WRITE(numout,*) 'Carbonate chem variable - reading in ...'
+         CALL iom_get( numrtr, jpdom_autoglo, 'pH_3D'   ,  f3_pH(:,:,:)     )
+         CALL iom_get( numrtr, jpdom_autoglo, 'h2CO3_3D',  f3_h2co3(:,:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'hCO3_3D' ,  f3_hco3(:,:,:)   )
+         CALL iom_get( numrtr, jpdom_autoglo, 'CO3_3D'  ,  f3_co3(:,:,:)    )
+         CALL iom_get( numrtr, jpdom_autoglo, 'omcal_3D',  f3_omcal(:,:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'omarg_3D',  f3_omarg(:,:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'CCD_CAL' ,  f2_ccd_cal(:,:)  )
+         CALL iom_get( numrtr, jpdom_autoglo, 'CCD_ARG' ,  f2_ccd_arg(:,:)  )
+         !!
+         IF(lwp) WRITE(numout,*) ' MEDUSA averaged Carb-chem stats (min, max, sum) ...'
+      call trc_rst_dia_stat( f3_pH(:,:,1)   ,'pH 3D surf')
+      call trc_rst_dia_stat( f3_h2co3(:,:,1),'h2CO3 3D surf')
+      call trc_rst_dia_stat( f3_hco3(:,:,1) ,'hCO3 3D surf' )
+      call trc_rst_dia_stat( f3_co3(:,:,1)  ,'CO3 3D surf' )
+      call trc_rst_dia_stat( f3_omcal(:,:,1),'omcal 3D surf')
+      call trc_rst_dia_stat( f3_omarg(:,:,1),'omarg 3D surf')
+      call trc_rst_dia_stat( f2_ccd_cal(:,:),'CCD_CAL')
+      call trc_rst_dia_stat( f2_ccd_arg(:,:),'CCD_ARG')
+
+      ELSE
+         IF(lwp) WRITE(numout,*) 'WARNING : No Carbonate-chem variable in the restart.... '
+         IF(lwp) WRITE(numout,*) 'Is not a problem if start a month, but may be very problematic if not '
+         IF(lwp) WRITE(numout,*) 'Check if   mod(kt*rdt,2592000) == rdt' 
+         IF(lwp) WRITE(numout,*) 'Or don t start from uncomplete restart...' 
+      ENDIF
+# endif
+
+
+#endif
+      !
+#if defined key_idtra
+      !! JPALM -- 05-01-2016 -- mv idtra and CFC restart reading and 
+      !!                        writting here undre their key.
+      !!                        problems in CFC restart, maybe because of this...
+      !!                        and pb in idtra diag or diad-restart writing.
+      !!----------------------------------------------------------------------
+      IF( iom_varid( numrtr, 'qint_IDTRA', ldstop = .FALSE. ) > 0 ) THEN
+         !! YES; in which case read them
+         !!
+         IF(lwp) WRITE(numout,*) ' IDTRA averaged properties present - reading in ...'
+         CALL iom_get( numrtr, jpdom_autoglo, 'qint_IDTRA',  qint_idtra(:,:,1)  )
+      ELSE
+         !! NO; in which case set them to zero
+         !!
+         IF(lwp) WRITE(numout,*) ' IDTRA averaged properties absent - setting to zero ...'
+         qint_idtra(:,:,1)  = 0.0   !! CHN
+      ENDIF
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' IDTRA averaged properties stats (min, max, sum) ...'
+      call trc_rst_dia_stat(qint_idtra(:,:,1), 'qint_IDTRA')
+#endif
+      !
+#if defined key_cfc
+      DO jl = 1, jp_cfc
+         jn = jp_cfc0 + jl - 1
+         IF( iom_varid( numrtr, 'qint_'//ctrcnm(jn), ldstop = .FALSE. ) > 0 ) THEN
+            !! YES; in which case read them
+            !!
+            IF(lwp) WRITE(numout,*) ' CFC averaged properties present - reading in ...'
+            CALL iom_get( numrtr, jpdom_autoglo, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jl) )
+         ELSE
+            !! NO; in which case set them to zero
+            !!
+            IF(lwp) WRITE(numout,*) ' CFC averaged properties absent - setting to zero ...'
+            qint_cfc(:,:,jn)  = 0.0   !! CHN
+         ENDIF
+         !!
+         !! calculate stats on these fields
+         IF(lwp) WRITE(numout,*) ' CFC averaged properties stats (min, max, sum) ...'
+         call trc_rst_dia_stat(qint_cfc(:,:,jl), 'qint_'//ctrcnm(jn))
+      END DO
+#endif
       !
    END SUBROUTINE trc_rst_read
@@ -128,6 +372,8 @@
       INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
       !!
-      INTEGER  :: jn
+      INTEGER  :: jn, jl
       REAL(wp) :: zarak0
+      !! AXY (05/11/13): temporary variables
+      REAL(wp) ::    fq0,fq1,fq2
       !!----------------------------------------------------------------------
       !
@@ -142,5 +388,127 @@
          CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) )
       END DO
-      !
+
+      !! AXY (09/06/14): the ARCHER version of MEDUSA-2 does not include an equivalent
+      !!                 call to MEDUSA-2 at this point; this suggests that the FCM
+      !!                 version of NEMO date significantly earlier than the current
+      !!                 version
+
+#if defined key_medusa
+      !! AXY (13/01/12): write out "before" and "now" state of seafloor
+      !!                 sediment pools into restart; this happens
+      !!                 whether or not the pools are to be used by
+      !!                 MEDUSA (which is controlled by a switch in the
+      !!                 namelist_top file)
+      !!
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment fields - writing out ...'
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_N',  zb_sed_n(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_N',  zn_sed_n(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_FE', zb_sed_fe(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_FE', zn_sed_fe(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_SI', zb_sed_si(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_SI', zn_sed_si(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_C',  zb_sed_c(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_C',  zn_sed_c(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_SED_CA', zb_sed_ca(:,:) )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_SED_CA', zn_sed_ca(:,:) )
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA sediment field stats (min, max, sum) ...'
+      call trc_rst_dia_stat(zn_sed_n(:,:), 'Sediment  N')
+      call trc_rst_dia_stat(zn_sed_fe(:,:), 'Sediment Fe')
+      call trc_rst_dia_stat(zn_sed_si(:,:), 'Sediment Si')
+      call trc_rst_dia_stat(zn_sed_c(:,:), 'Sediment C')
+      call trc_rst_dia_stat(zn_sed_ca(:,:), 'Sediment Ca')
+      !!
+      !! AXY (07/07/15): write out temporally averaged fields for DMS
+      !!                 calculations
+      !!
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS - writing out ...'
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_DMS_CHN',  zb_dms_chn(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_DMS_CHN',  zn_dms_chn(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_DMS_CHD',  zb_dms_chd(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_DMS_CHD',  zn_dms_chd(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_DMS_MLD',  zb_dms_mld(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_DMS_MLD',  zn_dms_mld(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_DMS_QSR',  zb_dms_qsr(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_DMS_QSR',  zn_dms_qsr(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_DMS_DIN',  zb_dms_din(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_DMS_DIN',  zn_dms_din(:,:)  )
+         !! JPALM 14-06-2016 -- add CO2 flux and DMS surf through the restart
+         !!                  -- needed for the coupling with atm
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_DMS_srf',  zb_dms_srf(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_DMS_srf',  zn_dms_srf(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'B_CO2_flx',  zb_co2_flx(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'N_CO2_flx',  zn_co2_flx(:,:)  )
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged properties for DMS stats (min, max, sum) ...'
+      call trc_rst_dia_stat(zn_dms_chn(:,:), 'DMS, CHN')
+      call trc_rst_dia_stat(zn_dms_chd(:,:), 'DMS, CHD')
+      call trc_rst_dia_stat(zn_dms_mld(:,:), 'DMS, MLD')
+      call trc_rst_dia_stat(zn_dms_qsr(:,:), 'DMS, QSR')
+      call trc_rst_dia_stat(zn_dms_din(:,:), 'DMS, DIN')
+      call trc_rst_dia_stat(zn_dms_srf(:,:), 'DMS surf')
+      call trc_rst_dia_stat(zn_co2_flx(:,:), 'CO2 flux')
+      !!
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged prop. for dust and iron dep.'
+      call trc_rst_dia_stat(dust(:,:), 'Dust dep')
+      call trc_rst_dia_stat(zirondep(:,:), 'Iron dep')
+      !! 
+      !!  
+      !! JPALM 14-06-2016 -- add Carbonate chenistry variables through the restart
+      !!                  -- needed for monthly call of carb-chem routine and better reproducibility
+# if defined key_roam
+      IF(lwp) WRITE(numout,*) 'Carbonate chem variable - writing out ...'
+      CALL iom_rstput( kt, nitrst, numrtw, 'pH_3D'   ,  f3_pH(:,:,:)     )
+      CALL iom_rstput( kt, nitrst, numrtw, 'h2CO3_3D',  f3_h2co3(:,:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'hCO3_3D' ,  f3_hco3(:,:,:)   )
+      CALL iom_rstput( kt, nitrst, numrtw, 'CO3_3D'  ,  f3_co3(:,:,:)    )
+      CALL iom_rstput( kt, nitrst, numrtw, 'omcal_3D',  f3_omcal(:,:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'omarg_3D',  f3_omarg(:,:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'CCD_CAL' ,  f2_ccd_cal(:,:)  )
+      CALL iom_rstput( kt, nitrst, numrtw, 'CCD_ARG' ,  f2_ccd_arg(:,:)  )
+      !!
+      IF(lwp) WRITE(numout,*) ' MEDUSA averaged Carb-chem stats (min, max, sum) ...'
+      call trc_rst_dia_stat( f3_pH(:,:,1)   ,'pH 3D surf')
+      call trc_rst_dia_stat( f3_h2co3(:,:,1),'h2CO3 3D surf')
+      call trc_rst_dia_stat( f3_hco3(:,:,1) ,'hCO3 3D surf' )
+      call trc_rst_dia_stat( f3_co3(:,:,1)  ,'CO3 3D surf' )
+      call trc_rst_dia_stat( f3_omcal(:,:,1),'omcal 3D surf')
+      call trc_rst_dia_stat( f3_omarg(:,:,1),'omarg 3D surf')
+      call trc_rst_dia_stat( f2_ccd_cal(:,:),'CCD_CAL')
+      call trc_rst_dia_stat( f2_ccd_arg(:,:),'CCD_ARG')
+      !!
+# endif
+!!
+#endif
+      !
+#if defined key_idtra
+      !! JPALM -- 05-01-2016 -- mv idtra and CFC restart reading and 
+      !!                        writting here undre their key.
+      !!                        problems in CFC restart, maybe because of this...
+      !!                        and pb in idtra diag or diad-restart writing.
+      !!----------------------------------------------------------------------
+      IF(lwp) WRITE(numout,*) ' IDTRA averaged properties - writing out ...'
+      CALL iom_rstput( kt, nitrst, numrtw, 'qint_IDTRA',  qint_idtra(:,:,1) )
+      !!
+      !! calculate stats on these fields
+      IF(lwp) WRITE(numout,*) ' IDTRA averaged properties stats (min, max, sum) ...'
+      call trc_rst_dia_stat(qint_idtra(:,:,1), 'qint_IDTRA')
+#endif
+      !
+#if defined key_cfc
+      DO jl = 1, jp_cfc
+         jn = jp_cfc0 + jl - 1
+         IF(lwp) WRITE(numout,*) ' CFC averaged properties - writing out ...'
+         CALL iom_rstput( kt, nitrst, numrtw, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jl) )
+         !!
+         !! calculate stats on these fields
+         IF(lwp) WRITE(numout,*) ' CFC averaged properties stats (min, max, sum) ...'
+         call trc_rst_dia_stat(qint_cfc(:,:,jl), 'qint_'//ctrcnm(jn))
+      END DO
+#endif
+      !
+
       IF( kt == nitrst ) THEN
           CALL trc_rst_stat            ! statistics
@@ -304,9 +672,82 @@
          IF(lwp) WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), zmean, zmin, zmax, zdrift
       END DO
-      WRITE(numout,*) 
+      IF(lwp) WRITE(numout,*) 
 9000  FORMAT(' tracer nb :',i2,'    name :',a10,'    mean :',e18.10,'    min :',e18.10, &
       &      '    max :',e18.10,'    drift :',e18.10, ' %')
       !
    END SUBROUTINE trc_rst_stat
+
+
+   SUBROUTINE trc_rst_tra_stat
+      !!----------------------------------------------------------------------
+      !!                    ***  trc_rst_tra_stat  ***
+      !!
+      !! ** purpose  :   Compute tracers statistics - check where crazy values appears
+      !!----------------------------------------------------------------------
+      INTEGER  :: jk, jn
+      REAL(wp) :: ztraf, zmin, zmax, zmean, zdrift
+      REAL(wp), DIMENSION(jpi,jpj) :: zvol
+      !!----------------------------------------------------------------------
+
+      IF( lwp ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '           ----SURFACE TRA STAT----             '
+         WRITE(numout,*)
+      ENDIF
+      !
+         zvol(:,:) = e1e2t(:,:) * fse3t_a(:,:,1) * tmask(:,:,1)
+      DO jn = 1, jptra
+         ztraf = glob_sum( tra(:,:,1,jn) * zvol(:,:) )
+         zmin  = MINVAL( tra(:,:,1,jn), mask= ((tmask(:,:,1).NE.0.)) )
+         zmax  = MAXVAL( tra(:,:,1,jn), mask= ((tmask(:,:,1).NE.0.)) )
+         IF( lk_mpp ) THEN
+            CALL mpp_min( zmin )      ! min over the global domain
+            CALL mpp_max( zmax )      ! max over the global domain
+         END IF
+         zmean  = ztraf / areatot
+         IF(lwp) WRITE(numout,9001) jn, TRIM( ctrcnm(jn) ), zmean, zmin, zmax
+      END DO
+      IF(lwp) WRITE(numout,*)
+9001  FORMAT(' tracer nb :',i2,'    name :',a10,'    mean :',e18.10,'    min :',e18.10, &
+      &      '    max :',e18.10)
+      !
+   END SUBROUTINE trc_rst_tra_stat
+
+
+
+   SUBROUTINE trc_rst_dia_stat( dgtr, names)
+      !!----------------------------------------------------------------------
+      !!                    ***  trc_rst_dia_stat  ***
+      !!
+      !! ** purpose  :   Compute tracers statistics
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj) , INTENT(in) ::   dgtr      ! 2D diag var
+      CHARACTER(len=*)             , INTENT(in) ::   names     ! 2D diag name
+      !!---------------------------------------------------------------------
+      INTEGER  :: jk, jn
+      REAL(wp) :: ztraf, zmin, zmax, zmean, areasf
+      REAL(wp), DIMENSION(jpi,jpj) :: zvol
+      !!----------------------------------------------------------------------
+
+      IF( lwp )  WRITE(numout,*) 'STAT- ', names
+      !
+      zvol(:,:) = e1e2t(:,:) * fse3t_a(:,:,1) * tmask(:,:,1)
+      ztraf = glob_sum( dgtr(:,:) * zvol(:,:) )
+      areasf = glob_sum(e1e2t(:,:) * tmask(:,:,1) )
+      zmin  = MINVAL( dgtr(:,:), mask= ((tmask(:,:,1).NE.0.)) )
+      zmax  = MAXVAL( dgtr(:,:), mask= ((tmask(:,:,1).NE.0.)) )
+      IF( lk_mpp ) THEN
+         CALL mpp_min( zmin )      ! min over the global domain
+         CALL mpp_max( zmax )      ! max over the global domain
+      END IF
+      zmean  = ztraf / areatot
+      IF(lwp) WRITE(numout,9002) TRIM( names ), zmean, zmin, zmax
+      !
+      IF(lwp) WRITE(numout,*)
+9002  FORMAT(' tracer name :',a10,'    mean :',e18.10,'    min :',e18.10, &
+      &      '    max :',e18.10 )
+      !
+   END SUBROUTINE trc_rst_dia_stat
+
 
 #else
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcsms.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcsms.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcsms.F90	(revision 7693)
@@ -16,6 +16,9 @@
    USE trc                !
    USE trcsms_pisces      ! PISCES biogeo-model
+   USE trcsms_medusa      ! MEDUSA tracers
+   USE trcsms_idtra       ! Idealize Tracer
    USE trcsms_cfc         ! CFC 11 & 12
    USE trcsms_c14b        ! C14b tracer 
+   USE trcsms_age         ! AGE tracer 
    USE trcsms_my_trc      ! MY_TRC  tracers
    USE prtctl_trc         ! Print control for debbuging
@@ -43,4 +46,5 @@
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
       !!
+      INTEGER            ::  jn
       CHARACTER (len=25) :: charout
       !!---------------------------------------------------------------------
@@ -49,6 +53,29 @@
       !
       IF( lk_pisces  )   CALL trc_sms_pisces ( kt )    ! main program of PISCES 
+      IF( lk_medusa  )   CALL trc_sms_medusa ( kt )    ! MEDUSA  tracers
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '--trcsms : MEDUSA OK --  next IDTRA -- '
+      CALL flush(numout)
+# endif
+      IF( lk_idtra   )   CALL trc_sms_idtra  ( kt )    ! radioactive decay of Id. tracer
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '--trcsms : IDTRA OK --  next CFC -- '
+      CALL flush(numout)
+# endif
       IF( lk_cfc     )   CALL trc_sms_cfc    ( kt )    ! surface fluxes of CFC
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '--trcsms : CFC OK --  next C14 -- '
+      CALL flush(numout)
+# endif
       IF( lk_c14b    )   CALL trc_sms_c14b   ( kt )    ! surface fluxes of C14
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '--trcsms : C14 OK --  next C14 -- '
+      CALL flush(numout)
+# endif
+      IF( lk_age     )   CALL trc_sms_age    ( kt )    ! AGE tracer
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) '--trcsms : Age OK --  Continue  -- '
+      CALL flush(numout)
+# endif
       IF( lk_my_trc  )   CALL trc_sms_my_trc ( kt )    ! MY_TRC  tracers
 
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 7693)
@@ -87,5 +87,13 @@
          tra(:,:,:,:) = 0.e0
          !
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp begins at kt =', kt
+         CALL flush(numout)
+# endif
                                    CALL trc_rst_opn  ( kt )       ! Open tracer restart file 
+# if defined key_debug_medusa
+                                   CALL trc_rst_stat 
+                                   CALL trc_rst_tra_stat
+# endif
          IF( lrst_trc )            CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
          IF( lk_iomput ) THEN  ;   CALL trc_wri      ( kt )       ! output of passive tracers with iom I/O manager
@@ -93,5 +101,17 @@
          ENDIF
                                    CALL trc_sms      ( kt )       ! tracers: sinks and sources
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp SMS complete at kt =', kt
+         CALL trc_rst_stat
+         CALL trc_rst_tra_stat
+         CALL flush(numout)
+# endif
                                    CALL trc_trp      ( kt )       ! transport of passive tracers
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp transport complete at kt =', kt
+         CALL trc_rst_stat
+         CALL trc_rst_tra_stat
+         CALL flush(numout)
+# endif
          IF( kt == nittrc000 ) THEN
             CALL iom_close( numrtr )       ! close input tracer restart file
@@ -102,4 +122,8 @@
          !
          IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt )       ! resetting physical variables when sub-stepping
+# if defined key_debug_medusa
+         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp ends at kt =', kt
+         CALL flush(numout)
+# endif
          !
       ENDIF
Index: /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcwri.F90
===================================================================
--- /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcwri.F90	(revision 7692)
+++ /branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/trcwri.F90	(revision 7693)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History :   1.0  !  2009-05 (C. Ethe)  Original code
+   !!              -   !  2014-06 (A. Yool, J. Palmieri) adding MEDUSA-2
    !!----------------------------------------------------------------------
 #if defined key_top && defined key_iomput
@@ -21,4 +22,7 @@
    USE trcwri_c14b
    USE trcwri_my_trc
+   USE trcwri_medusa
+   USE trcwri_idtra
+   USE trcwri_age
 
    IMPLICIT NONE
@@ -57,6 +61,9 @@
       ! ---------------------------------------
       IF( lk_pisces  )   CALL trc_wri_pisces     ! PISCES 
+      IF( lk_medusa  )   CALL trc_wri_medusa     ! MESDUSA
+      IF( lk_idtra   )   CALL trc_wri_idtra       ! Idealize tracers
       IF( lk_cfc     )   CALL trc_wri_cfc        ! surface fluxes of CFC
       IF( lk_c14b    )   CALL trc_wri_c14b       ! surface fluxes of C14
+      IF( lk_age     )   CALL trc_wri_age        ! AGE tracer
       IF( lk_my_trc  )   CALL trc_wri_my_trc     ! MY_TRC  tracers
       !
