Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/field_def_bgc.xml	(revision 6639)
@@ -0,0 +1,769 @@
+<!--
+<?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 -->
+
+    <!-- 
+============================================================================================================
+                                     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 >
+     </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="mol/m3"      />
+       <field id= "DMS_ANDR"   long_name="DMS Surface Concentration, Anderson"       unit="mol/m3"      />
+       <field id= "DMS_SIMO"   long_name="DMS Surface Concentration, SimoDach"       unit="mol/m3"      />
+       <field id= "DMS_ARAN"   long_name="DMS Surface Concentration, AranamiT"       unit="mol/m3"      />
+       <field id= "DMS_HALL"   long_name="DMS Surface Concentration, Halloran"       unit="mol/m3"      />
+
+       <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="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_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/field_def_dyn.xml
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/field_def_dyn.xml	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/field_def_dyn.xml	(revision 6639)
@@ -0,0 +1,813 @@
+<!--
+<?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="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="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="bn2"          long_name="squared Brunt-Vaisala frequency"                                           unit="s-1"    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="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="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="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="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="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="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="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" />
+
+        <!-- woce_eiv: available with key_trabbl_adv -->
+        <field id="avt"          long_name="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" />
+
+        <!-- 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_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" />
+      </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="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" domain_ref="grid_T"  > 
+        <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_definition>
+
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/iodef_medusa_idtra.xml
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/iodef_medusa_idtra.xml	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/iodef_medusa_idtra.xml	(revision 6639)
@@ -0,0 +1,115 @@
+<?xml version="1.0"?>
+<simulation> 
+
+ <context id="nemo" time_origin="1900-01-01 00:00:00" >
+    
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                  definition of all existing variables                                    =
+=                                            DO NOT CHANGE                                                 =
+============================================================================================================
+    -->
+    <field_definition src="./field_def_dyn.xml"/>
+    <field_definition src="./field_def_bgc.xml"/>
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+
+   <file_definition type="one_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=".TRUE."/> <!-- 6h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->   
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
+        <file id="file1" 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="file2" 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="groupMEDUSA_bas" /> 
+          <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"  long_name="Vertical T levels"  unit="m" positive="down" />
+      <axis id="depthu"  long_name="Vertical U levels"  unit="m" positive="down" />
+      <axis id="depthv"  long_name="Vertical V levels"  unit="m" positive="down" />
+      <axis id="depthw"  long_name="Vertical W levels"  unit="m" positive="down" />
+      <axis id="nfloat"  long_name="Float number"       unit="1"                 />
+      <axis id="icbcla"  long_name="Iceberg class"      unit="1"                 />
+      <axis id="ncatice" long_name="Ice category"       unit="1"                 />
+      <axis id="iax_20C" long_name="20 degC isotherm"   unit="degC"              />
+      <axis id="iax_28C" long_name="28 degC isotherm"   unit="degC"              />
+   </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_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">50000000</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">false</variable>
+	  <variable id="using_oasis"               type="boolean">false</variable>
+	  <variable id="oasis_codes_id"            type="string" >oceanx</variable>
+	
+      </variable_definition>
+               
+  </context>
+  
+</simulation>
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_idtra_cfg
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_idtra_cfg	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_idtra_cfg	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_idtra_ref
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_idtra_ref	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_idtra_ref	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_medusa_cfg
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_medusa_cfg	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_medusa_cfg	(revision 6639)
@@ -0,0 +1,39 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+! BIO namelist :  MEDUSA biological model option and parameter input
+! -------------
+!
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natbio   Shared parameters for dynamics/advection/thermo
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!!
+&natbio
+!
+      jdms      = 1         !! include dms diagnostics
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natroam
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+&natroam
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natopt
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+&natopt
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       natdbi used if key_trc_diabio is set
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+!
+!  nwritebio : frequency of biological model output [timesteps]
+&natdbi
+   nwritebio = 10
+/
+!=================================================
+! nammeddia    Passive tracers additional diagnostics
+!=================================================
+&nammeddia
+/
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_medusa_ref
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_medusa_ref	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_medusa_ref	(revision 6639)
@@ -0,0 +1,359 @@
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+! 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
+!!
+!! 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
+!!
+!!
+&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
+      xvpn      = 1.060     !! EKP (05/03/09)
+      xvpd      = 1.000     !! EKP (05/03/09)
+      xthetam   = 0.05      !! EKP (05/03/09)
+      xthetamd  = 0.05      !! EKP (05/03/09)
+!!
+!! 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       = 1         !! 0 = T-independent; 1 = T-dependent
+      jsfd      = 0         !! 0 = unchanged seafloor remin.; 1 = accelerated seafloor remin.
+      xmd       = 0.0158    !! T-dependent; 0.05 at 18C (Yool et al., 2010)
+      xmdc      = 0.0127    !! T-dependent; 0.04 at 18C (Yool et al., 2010)
+!!
+!! 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        !!
+!!
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+!       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
+/
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_top_medusa_idtra_cfg
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_top_medusa_idtra_cfg	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/SHARED/namelist_top_medusa_idtra_cfg	(revision 6639)
@@ -0,0 +1,82 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/TOP1 : ORCA2_OFF_PISCES configuration namelist used to overwrite SHARED/namelist_top
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!-----------------------------------------------------------------------
+&namtrc_run     !   run information
+!-----------------------------------------------------------------------
+   nn_writetrc   =  1460     !  time step frequency for sn_tracer outputs
+/
+!-----------------------------------------------------------------------
+&namtrc     !   tracers definition
+!-----------------------------------------------------------------------
+   ln_trcdta     =   .false.  !  Initialisation from data input file (T) or not (F)
+!
+!              !    name   !           title of the field              !   units    ! initial data ! save   !
+!              !           !                                           !            ! from file    ! or not ! 
+!              !           !                                           !            ! or not       !        !
+   sn_tracer(1)   = 'CHN' , 'Chl-a concentration in non-diatom phytoplankton ',  'mg Chl/m3' ,  .false. ,  .true.
+   sn_tracer(2)   = 'CHD' , 'Chl-a concentration in     diatom phytoplankton ',  'mg Chl/m3' ,  .false. ,  .true.
+   sn_tracer(3)   = 'PHN' , 'non-diatom phytoplankton                        ',  'mmol-N/m3' ,  .false. ,  .true.
+   sn_tracer(4)   = 'PHD' , 'diatom phytoplankton                            ',  'mmol-N/m3' ,  .false. ,  .true.
+   sn_tracer(5)   = 'ZMI' , 'micro zooplankton                               ',  'mmol-N/m3' ,  .false. ,  .true.
+   sn_tracer(6)   = 'ZME' , 'meso  zooplankton                               ',  'mmol-N/m3' ,  .false. ,  .true.
+   sn_tracer(7)   = 'DIN' , 'dissolved inorganic nitrogen                    ',  'mmol-N/m3' ,  .false. ,  .true.
+   sn_tracer(8)   = 'SIL' , 'silicate                                        ',  'mmolSi/m3' ,  .false. ,  .true.
+   sn_tracer(9)   = 'FER' , 'dissolved iron                                  ',  'mmolFe/m3' ,  .false. ,  .true.
+   sn_tracer(10)  = 'DET' , 'detrital nitrogen                               ',  'mmol-N/m3' ,  .false. ,  .true.
+   sn_tracer(11)  = 'PDS' , 'biogenic silicon in diatom phytoplankton        ',  'mmolSi/m3' ,  .false. ,  .true.
+   sn_tracer(12)  = 'DTC' , 'detrital carbon                                 ',  'mmol-C/m3' ,  .false. ,  .true.
+   sn_tracer(13)  = 'DiC' , 'dissolved inorganic carbon                      ',  'mmol-C/m3' ,  .false. ,  .true.
+   sn_tracer(14)  = 'ALK' , 'alkalinity                                      ',  'meq/m3'    ,  .false. ,  .true.
+   sn_tracer(15)  = 'OXY' , 'dissolved oxygen                                ',  'mmolO2/m3' ,  .false. ,  .true.
+   sn_tracer(16)  = 'IDTRA','Ideal traceur concentration                     ',  'mmol/m3'   ,  .false. ,  .true.
+   sn_tracer(17)  = 'CFC11','CFC-11 Concentration                            ',  'umol/m3'   ,  .false. ,  .true.
+/
+!-----------------------------------------------------------------------
+&namtrc_dta      !    Initialisation from data input file
+!-----------------------------------------------------------------------
+!
+!          !  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_trcdta(7)  = 'data_NO3_nomask'       ,   -1   ,  'NO3'      ,    .false.   , .true. , 'yearly'  , ''    , ''    , ''
+   sn_trcdta(8)  = 'data_Si_nomask'        ,   -1   ,  'Si'       ,    .false.   , .true. , 'yearly'  , ''    , ''    , ''
+   sn_trcdta(9)  = 'data_Fer_nomask'       ,   -12  ,  'Fer'      ,    .false.   , .true. , 'yearly'  , ''    , ''    , ''
+   sn_trcdta(13) = 'data_DIC_nomask'       ,   -12  ,  'DIC'      ,    .false.   , .true. , 'yearly'  , ''    , ''    , ''
+   sn_trcdta(14) = 'data_Alkalini_nomask'  ,   -12  ,  'Alkalini' ,    .false.   , .true. , 'yearly'  , ''    , ''    , ''
+   sn_trcdta(15) = 'data_O2_nomask'        ,   -1   ,  'O2'       ,    .false.   , .true. , 'yearly'  , ''    , ''    , ''
+!
+   cn_dir        =  './'      !  root directory for the location of the data files
+   rn_trfac(7)   =   1.0      !  multiplicative factor
+   rn_trfac(8)   =   1.0      !  multiplicative factor
+   rn_trfac(9)   =   1.0e6    !  multiplicative factor
+   rn_trfac(13)  =   1.028    !  multiplicative factor
+   rn_trfac(14)  =   1.028    !  multiplicative factor
+   rn_trfac(15)  =   44.6     !  multiplicative factor
+/
+!-----------------------------------------------------------------------
+&namtrc_adv    !   advection scheme for passive tracer 
+!-----------------------------------------------------------------------
+   ln_trcadv_tvd     =  .false.  !  TVD scheme
+   ln_trcadv_muscl   =  .true.   !  MUSCL scheme
+/
+!-----------------------------------------------------------------------
+&namtrc_ldf    !   lateral diffusion scheme for passive tracer 
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtrc_zdf        !   vertical physics
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtrc_rad        !  treatment of negative concentrations 
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtrc_dia       !   parameters for passive tracer additional diagnostics
+!----------------------------------------------------------------------
+   nn_writedia   =  1460     !  time step frequency for diagnostics
+/
+!----------------------------------------------------------------------
+&namtrc_bc        !   data for boundary conditions
+!-----------------------------------------------------------------------
+/
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/cfg.txt
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/cfg.txt	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/CONFIG/cfg.txt	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90	(revision 6639)
@@ -445,20 +445,64 @@
       !                                     ! Passive tracers
                             CALL     trc_init
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : trc_init OK --  next DIAGNOSTICS -- '
+      CALL flush(numout)
+# endif
 #endif
       !                                     ! Diagnostics
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : Begins Diag inits --  next flo_init if lk_floats -- '
+      CALL flush(numout)
+# endif
       IF( lk_floats     )   CALL     flo_init   ! drifting Floats
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : flo_init OK --  next dia_ar5_init if lk_diaar5 -- '
+      CALL flush(numout)
+# endif
       IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : dia_ar5_init OK --  next dia_ptr_init -- '
+      CALL flush(numout)
+# endif
                             CALL dia_ptr_init   ! Poleward TRansports initialization
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : dia_ptr_init OK --  next dia_dct_init if lk_diadct -- '
+      CALL flush(numout)
+# endif
       IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : dia_dct_init OK --  next dia_hsb_init -- '
+      CALL flush(numout)
+# endif
                             CALL dia_hsb_init   ! heat content, salt content and volume budgets
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : dia_hsb_init OK --  next trd_init -- '
+      CALL flush(numout)
+# endif
                             CALL     trd_init   ! Mixed-layer/Vorticity/Integral constraints trends
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : trd_init OK --  next dia_obs_init if lk_diaobs -- '
+      CALL flush(numout)
+# endif
       IF( lk_diaobs     ) THEN                  ! Observation & model comparison
                             CALL dia_obs_init            ! Initialize observational data
+# if defined key_debug_medusa
+           IF(lwp) WRITE(numout,*) '--nemo_init : dia_obs_init OK -- dia_obs if lk_diaobs -- '
+           CALL flush(numout)
+# endif
                             CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
       ENDIF
-
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init : dia_obs OK --  next asm_inc_init if lk_asminc -- '
+      CALL flush(numout)
+# endif
       !                                     ! Assimilation increments
       IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
       IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
+      !
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '--nemo_init - Done - OK  -- '
+      CALL flush(numout)
+# endif
       !
    END SUBROUTINE nemo_init
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/C14b/par_c14b.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/C14b/par_c14b.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/C14b/par_c14b.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/CFC/par_cfc.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/CFC/par_cfc.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/CFC/par_cfc.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 6639)
@@ -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
@@ -176,14 +177,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 +231,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')
       !
@@ -254,13 +286,13 @@
       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
-      ENDIF
+      !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
+      !ENDIF
       IF(lwp) WRITE(numout,*)
       !
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/par_idtra.F90	(revision 6639)
@@ -21,12 +21,10 @@
    USE par_medusa , ONLY : jp_medusa_trd   !: number of biological diag in MEDUSA
 
+   IMPLICIT NONE
 
-   IMPLICIT NONE
-   PUBLIC
-
-   INTEGER, PUBLIC, PARAMETER ::   jp_lp      =  jp_pisces     + jp_medusa     !: cumulative number of passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_lp_2d   =  jp_pisces_2d  + jp_medusa_2d  !:
-   INTEGER, PUBLIC, PARAMETER ::   jp_lp_3d   =  jp_pisces_3d  + jp_medusa_3d  !:
-   INTEGER, PUBLIC, PARAMETER ::   jp_lp_trd  =  jp_pisces_trd + jp_medusa_trd !:
+   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
@@ -36,5 +34,5 @@
    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  =  0          !: additional 2d output arrays ('key_trc_diaadd')
+   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
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcctl_idtra.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcctl_idtra.F90	(revision 6638)
+++ 	(revision )
@@ -1,105 +1,0 @@
-MODULE trcctl_idtra
-   !!======================================================================
-   !!                         ***  trcctl.idtra.F90  ***
-   !! TOP :                Control of IDEAL-TRA chemical model
-   !!======================================================================
-   !!----------------------------------------------------------------------
-   !! History :   1.0  !  2005-10 (C. Ethe) assign a parameter to name individual tracers
-   !!----------------------------------------------------------------------
-
-#if defined key_idtra
-
-   USE oce_trc
-   USE trc
-
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC trc_ctl_idtra      ! 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_idtra
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE trc_ctl_idtra  ***
-      !!
-      !! ** Purpose :   control the cpp options, namelist and files
-      !!----------------------------------------------------------------------
-      INTEGER :: jl, jn
-
-      IF(lwp) THEN
-          WRITE(numout,*) ' IDEAL-TRA Model '
-          WRITE(numout,*) ' '
-      ENDIF
-
-      ! Check number of tracers
-      ! -----------------------
-      IF( jp_idtra > 5) THEN
-          IF(lwp) THEN
-              WRITE (numout,*) ' ===>>>> : w a r n i n g '
-              WRITE (numout,*) ' =======   ============= '
-              WRITE (numout,*)                             &
-              &   ' STOP, change jp_idtra to 1 in par_IDEAL-TRA module '
-          END IF
-          STOP 'TRC_CTL'
-      END IF
-
-      ! Check tracer names
-      ! ------------------
-      IF ( ctrcnm(jpidtra) /= 'Ideal-Tracer' ) THEN
-            ctrcnm(jpidtra) = 'Ideal-Tracer'
-            ctrcln(jpidtra) = 'Ideal-Tracer concentration'
-      ENDIF
-
-      IF(lwp) THEN
-         WRITE (numout,*) ' ===>>>> : w a r n i n g '
-         WRITE (numout,*) ' =======   ============= '
-         WRITE (numout,*) ' we force tracer names'
-         DO jl = 1, jp_idtra
-            jn = jp_idtra0 + jl - 1
-            WRITE(numout,*) ' tracer nb: ',jn,' name = ',ctrcnm(jn), ctrcln(jn)
-         END DO
-         WRITE(numout,*) ' '
-      ENDIF
-
-
-      ! Check tracer units
-      ! ------------------
-      DO jl = 1, jp_idtra
-         jn = jp_idtra0 + jl - 1
-        IF( ctrcun(jn) /= 'unit' ) THEN
-            ctrcun(jn) = 'unit'
-            IF(lwp) THEN
-               WRITE (numout,*) ' ===>>>> : w a r n i n g '
-               WRITE (numout,*) ' =======   ============= '
-               WRITE (numout,*) ' we force tracer unit'
-               WRITE(numout,*) ' tracer  ',ctrcnm(jn), 'UNIT= ',ctrcun(jn)
-               WRITE(numout,*) ' '
-            ENDIF
-         ENDIF
-      END DO
-      !
-   END SUBROUTINE trc_ctl_idtra
-
-#else
-   !!----------------------------------------------------------------------
-   !!  Empty module :                                                No IDEAL-TRA
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE trc_ctl_idtra                      ! Dummy routine
-   END SUBROUTINE trc_ctl_idtra
-#endif
-
-   !!======================================================================
-END MODULE trcctl_idtra
-
-
-
-
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcice_idtra.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcice_idtra.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcice_idtra.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcini_idtra.F90	(revision 6639)
@@ -16,8 +16,8 @@
    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
+   ! USE par_idtra       ! IDEAL-TRACER parameters
+   ! USE in_out_manager  ! I/O manager
+   ! USE lib_mpp
+   ! USE iom
 
    IMPLICIT NONE
@@ -46,13 +46,23 @@
       !!----------------------------------------------------------------------
 
+      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 de id-tracers ; No restart : '
+            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
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcnam_idtra.F90	(revision 6639)
@@ -15,6 +15,6 @@
    USE par_trc         ! TOP parameters
    USE trc             ! TOP variables
-   USE trcsms_idtra      ! IDEAL-TRACER specific variable
-   USE in_out_manager  ! I/O manager
+   USE trcsms_idtra    ! IDEAL-TRACER specific variable
+   USE iom             ! I/O manager
 
    IMPLICIT NONE
@@ -42,28 +42,21 @@
       !! ** input   :   Namelist namidtra
       !!----------------------------------------------------------------------
-      REAL(wp) ::   tmp_decay          !! Years ; half time decay of our idealize tracer
-      REAL(wp) ::   TDECyr, TDEC   
-      CHARACTER(LEN=32)   ::   clname
-      !! 
+      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
-!! #if defined key_trc_diaadd
-!!      ! definition of additional diagnostic as a structure
-!!      INTEGER :: jl, jn
-!!
-!! #endif
-      !!
-
-!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-!! 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.
-!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
+      !!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+      !! 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,*)
-      clname = 'namelist_idtra'
       IF(lwp) WRITE(numout,*) ' trc_nam_idtra: read IDEAL-TRACER namelist'
       IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
@@ -71,6 +64,7 @@
       !! Open the namelist file :
       !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-      CALL ctl_opn( numnatm, TRIM( clname ), 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-
+      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 :
       !!~~~~~~~~~~~~~~~~~~~~~~~
@@ -79,5 +73,13 @@
       !! tmp_decay = 1y ; 10y ; 100y or 1000y depending of which water mass you want to track
       !!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-      READ(numnatm,namidtra)
+
+      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
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcsms_idtra.F90	(revision 6639)
@@ -18,5 +18,5 @@
    USE par_trc      ! TOP parameters
    USE trc          ! TOP variables
-   USE trdtrc_oce
+   USE trd_oce
    USE trdtrc
    USE iom
@@ -25,10 +25,15 @@
    PRIVATE
 
-   PUBLIC   trc_sms_idtra       ! called in ???
-
+   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
@@ -69,28 +74,53 @@
       !!              
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
-      !!
-      INTEGER ::   ji, jj, jn, jl, jk
-
-
-
-      !!----------------------------------------------------------------------
-      IF(lwp) WRITE(numout,*) '   - JPALM - verif :'
-      IF(lwp) WRITE(numout,*) '   ~~~~~~~~~~~~~~~~~'
-      IF(lwp) WRITE(numout,*) '   - idtra decay factor : ', FDEC
-
+      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
 
          !
-DO jn = jp_idtra0, jp_idtra1
-
-        ! DO jj = 1, jpj
-        !    DO ji = 1, jpi
-               ! Surface concentrarion fixed to 1 (ideal tracer concentration unit)
-               trn(:,:,1,jn) = 1.
-               trb(:,:,1,jn) = 1.
-               !
-        !    ENDDO
-        ! ENDDO
-
+      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
@@ -98,9 +128,13 @@
 
          DO  jk =1,jpk
-            DO jj=1,jpj
-              DO  ji =1,jpi
+      !!      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
+                    tra(ji,jj,jk,jn) = (tra(ji,jj,jk,jn) - WTEMP/rdt ) * &
+                                     tmask(ji,jj,jk)
                !  ENDIF 
               ENDDO 
@@ -108,32 +142,104 @@
          ENDDO
 
-ENDDO
+      ENDDO
     !! jn loop
 !
-
-!!!!!! No added diagnostics to save here for idealize tracers...
-!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-!! #if defined key_trc_diaadd
-!!       ! Save diagnostics , just for TRI111
-!! # if ! defined key_iomput
-!!       trc2d(:,:,jp_idtra0_2d    ) = zpp_idtra(:,:)
-!! # else
-!! !           WRITE(NUMOUT,*) 'Iomput idtrasurf '
-!!       CALL iom_put( "TRISURF"  , zpp_idtra(:,:) )
-!! !      CALL iom_put( "TRISURF"  , xphem(:,:) )
-!! !           WRITE(NUMOUT,*) 'Iomputage '
-!!        CALL iom_put( "AGE"  , zage(:,:,:) )
-!! # endif
-!! #endif
-!!
-
-!!      IF( l_trdtrc ) THEN
-!!          DO jn = jp_idtra0, jp_idtra1
-!!            zidtradtra(:,:,:) = tra(:,:,:,jn)
-!!            CALL trd_mod_trc( zidtradtra, jn, jptrc_trd_sms, kt )   ! save trends
-!!          END DO
-!!      END IF
-
+# 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
    !!----------------------------------------------------------------------
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/IDTRA/trcwri_idtra.F90	(revision 6639)
@@ -13,8 +13,8 @@
    !! trc_wri_idtra   :  outputs of concentration fields
    !!----------------------------------------------------------------------
-   USE oce_trc         ! Ocean variables
-   USE par_trc         ! TOP parameters
+   ! USE oce_trc         ! Ocean variables
+   ! USE par_trc         ! TOP parameters
    USE trc             ! passive tracers common variables
-   USE trcsms_idtra    ! IDEALIZE TRACER sms trends
+   ! USE trcsms_idtra    ! IDEALIZE TRACER sms trends
    USE iom             ! I/O manager
 
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/gas_transfer.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/gas_transfer.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/gas_transfer.F90	(revision 6639)
@@ -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: trcbio.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! 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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_gasflux.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_gasflux.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_gasflux.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_mainmod.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_mainmod.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_mainmod.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_phsolvers.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_phsolvers.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_phsolvers.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_singledouble.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_singledouble.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_singledouble.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_wrapper.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_wrapper.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/mocsy_wrapper.F90	(revision 6639)
@@ -0,0 +1,335 @@
+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: trcbio.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! 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
+
+!> ======================================================================
+!  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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/par_medusa.F90	(revision 6639)
@@ -15,6 +15,15 @@
    !! 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
@@ -36,20 +45,20 @@
 
    ! assign an index in trc arrays for each PTS prognostic variables
-   INTEGER, PUBLIC, PARAMETER ::   jpchn  =  1              !: non-diatom chlorophyll concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpchd  =  2              !: diatom     chlorophyll concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpphn  =  3              !: non-diatom concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpphd  =  4              !: diatom     concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpzmi  =  5              !: microzooplankton concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpzme  =  6              !: mesozooplankton  concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpdin  =  7              !: dissolved inorganic nitrogen concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpsil  =  8              !: silicic acid concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpfer  =  9              !: total iron concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpdet  = 10              !: slow-sinking detritus concentration
-   INTEGER, PUBLIC, PARAMETER ::   jppds  = 11              !: diatom silicon concentration
+   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  = 12              !: slow-sinking detritus carbon concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpdic  = 13              !: dissolved inorganic carbon concentration
-   INTEGER, PUBLIC, PARAMETER ::   jpalk  = 14              !: alkalinity
-   INTEGER, PUBLIC, PARAMETER ::   jpoxy  = 15              !: dissolved oxygen concentration
+   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
 
@@ -66,12 +75,12 @@
 
    ! 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     = 1              !: First index of MEDUSA passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_msa1     = jp_medusa      !: Last  index of MEDUSA passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_2d  = 1              !: First index of MEDUSA passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_2d  = jp_medusa_2d   !: Last  index of MEDUSA passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_3d  = 1              !: First index of MEDUSA passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_3d  = jp_medusa_3d   !: Last  index of MEDUSA passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_msa0_trd = 1              !: First index of MEDUSA passive tracers
-   INTEGER, PUBLIC, PARAMETER ::   jp_msa1_trd = jp_medusa_trd  !: Last  index of MEDUSA passive tracers
+   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
 
    !!======================================================================
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 6639)
@@ -172,5 +172,8 @@
 !!
 !! UKESM diagnostics
-   INTEGER  ::  jdms      !:  include DMS diagnostics ? Jpalm (27-08-2014) 
+   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
 !!
 !!
@@ -217,4 +220,21 @@
    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)
 #endif
 
@@ -230,5 +250,4 @@
 !!
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dust      !: dust parameter 1
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dustmo    !: dust parameter 2
 
 !!----------------------------------------------------------------------
@@ -415,5 +434,5 @@
       !!----------------------------------------------------------------------
       USE lib_mpp , ONLY: ctl_warn
-      INTEGER ::   ierr(6)        ! Local variables
+      INTEGER ::   ierr(7)        ! Local variables
       !!----------------------------------------------------------------------
       ierr(:) = 0
@@ -439,13 +458,24 @@
          &      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) )
 # endif
       !* 2D fields of miscellaneous parameters
       ALLOCATE( ocal_ccd(jpi,jpj)    , dust(jpi,jpj)        ,       &
-         &      dustmo(jpi,jpj,2)    , riv_n(jpi,jpj)       ,       &
+         &      riv_n(jpi,jpj)                              ,       &
          &      riv_si(jpi,jpj)      , riv_c(jpi,jpj)       ,       &
-         &      riv_alk(jpi,jpj)     , friver_dep(jpk,jpk)  ,    STAT=ierr(4) )
+         &      riv_alk(jpi,jpj)     , friver_dep(jpk,jpk)  ,    STAT=ierr(5) )
       !* 2D and 3D fields of light parameters
       ALLOCATE( neln(jpi,jpj)        , xze(jpi,jpj)         ,       &
-         &      xpar(jpi,jpj,jpk)    ,                           STAT=ierr(5) )
+         &      xpar(jpi,jpj,jpk)    ,                           STAT=ierr(6) )
       !* 2D and 3D fields of sediment-associated parameters
       ALLOCATE( dminl(jpi,jpj)       , dmin3(jpi,jpj,jpk)   ,       &
@@ -454,5 +484,5 @@
          &      fbodf(jpi,jpj)       , fbods(jpi,jpj)       ,       &
          &      ffln(jpi,jpj,jpk)    , fflf(jpi,jpj,jpk)    ,       &
-         &      ffls(jpi,jpj,jpk)    , cmask(jpi,jpj)       ,    STAT=ierr(6) ) 
+         &      ffls(jpi,jpj,jpk)    , cmask(jpi,jpj)       ,    STAT=ierr(7) ) 
 #endif
       !
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcavg_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcavg_medusa.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcavg_medusa.F90	(revision 6639)
@@ -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: trcbio.F90 1146 2008-06-25 11:42:56Z rblod $ 
+   !! 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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 6639)
@@ -16,4 +16,7 @@
    !!  -   !  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  
    !!----------------------------------------------------------------------
    !!
@@ -36,4 +39,17 @@
 #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
    !!----------------------------------------------------------------------
@@ -53,7 +69,14 @@
 # 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)
@@ -134,4 +157,7 @@
       REAL(wp) ::    ztmp, zsal
 # endif
+# if defined key_mocsy
+      REAL(wp) ::    zpho
+# endif
       !!
       !! integrated source and sink terms
@@ -142,6 +168,6 @@
       !!
       !! primary production and chl related quantities      
-      REAL(wp) ::    fthetan,faln,fchn1,fchn,fjln,fprn,frn
-      REAL(wp) ::    fthetad,fald,fchd1,fchd,fjld,fprd,frd
+      REAL(wp)                     ::    fthetan,faln,fchn1,fchn,fjln,fprn,frn
+      REAL(wp)                     ::    fthetad,fald,fchd1,fchd,fjld,fprd,frd
       !! AXY (03/02/11): add in Liebig terms
       REAL(wp) ::    fpnlim, fpdlim
@@ -150,5 +176,5 @@
       INTEGER  ::    ieppley
       !! AXY (01/03/10): add in mixed layer PP diagnostics
-      REAL(wp) ::    fprn_ml,fprd_ml
+      REAL(wp), DIMENSION(jpi,jpj) ::  fprn_ml,fprd_ml
       !!
       !! nutrient limiting factors
@@ -161,5 +187,6 @@
       !! iron cycle; includes parameters for Parekh et al. (2005) iron scheme
       REAL(wp) ::    ffetop,ffebot,ffescav
-      REAL(wp) ::    xLgF, xFeT, xFeF, xFeL, xFree  !! state variables for iron-ligand system
+      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
@@ -189,6 +216,6 @@
 # endif
       REAL(wp) ::    fdpn2,fdpd2,fdpds2,fdzmi2,fdzme2
-      REAL(wp) ::    fslown, fslownflux
-      REAL(wp) ::    fslowc, fslowcflux
+      REAL(wp) ::    fslown, fslowc
+      REAL(wp), DIMENSION(jpi,jpj) ::    fslownflux, fslowcflux
       REAL(wp) ::    fregen,fregensi
       REAL(wp), DIMENSION(jpi,jpj) ::    fregenfast,fregenfastsi
@@ -206,5 +233,5 @@
       REAL(wp) ::    fheren,fheresi,fherefe,fherec,fhereca
       REAL(wp) ::    fprotf
-      REAL(wp) ::    fsedn,fsedsi,fsedfe,fsedc,fsedca
+      REAL(wp), DIMENSION(jpi,jpj) ::    fsedn,fsedsi,fsedfe,fsedc,fsedca
       REAL(wp), DIMENSION(jpi,jpj) ::    fccd
       REAL(wp) ::    fccd_dep
@@ -226,10 +253,10 @@
       !!
       !! water column nutrient and flux integrals
-      REAL(wp) ::    ftot_n,ftot_si,ftot_fe
+      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) ::    ftot_c,ftot_a,ftot_o2
+      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
@@ -266,4 +293,9 @@
       REAL(wp) ::    f_kw660, f_o2flux, f_o2sat
       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
+      !!
       INTEGER  ::    iters
       REAL(wp) ::    f_year
@@ -273,5 +305,5 @@
       !! carbon, alkalinity production and consumption
       REAL(wp) ::    fc_prod, fc_cons, fa_prod, fa_cons
-      REAL(wp) ::    fcomm_resp
+      REAL(wp), DIMENSION(jpi,jpj) ::    fcomm_resp
       REAL(wp), DIMENSION(jpi,jpj) ::    fcar_prod, fcar_cons
       !!
@@ -303,6 +335,35 @@
       !! 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_surf2d, dms_andr2d, dms_simo2d, dms_aran2d, dms_hall2d
+      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 
+# endif
+      !! 2D var for diagnostics.
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: tpp3d, detflux3d, remin3dn
       !!---------------------------------------------------------------------
+
+# 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
@@ -376,4 +437,10 @@
       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)
@@ -402,4 +469,7 @@
       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
@@ -420,4 +490,7 @@
       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
@@ -454,5 +527,410 @@
       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
+      !! 
+      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
+                !! 
+      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     
+      !! 
+      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                  
+      IF( med_diag%RR_0100%dgsave ) THEN
+         CALL wrk_alloc( jpi, jpj,   ffastca2d    )
+         ffastca2d(:,:)      = 0.0      !!
+      ENDIF      
+      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 
+      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
+      IF( med_diag%ATM_PCO2%dgsave ) THEN
+         CALL wrk_alloc( jpi, jpj,    f_pco2a2d   )
+         f_pco2a2d(:,:)      = 0.0      !!
+      ENDIF
+      IF( med_diag%OCN_PCO2%dgsave ) THEN
+         CALL wrk_alloc( jpi, jpj,    f_pco2w2d   )
+         f_pco2w2d(:,:)      = 0.0      !!
+      ENDIF
+      IF( med_diag%CO2FLUX%dgsave ) THEN
+         CALL wrk_alloc( jpi, jpj,    f_co2flux2d   )
+         f_co2flux2d(:,:)      = 0.0      !!
+      ENDIF
+      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 
+      !!
+      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
+      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
+      IF( med_diag%LYSO_CA%dgsave ) THEN
+         CALL wrk_alloc( jpi, jpj,    lyso_ca2d  )
+         lyso_ca2d(:,:)      = 0.0      !!
+      ENDIF
+      !!  
+      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   
+# 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
+      ENDIF
+      !! lk_iomput                                   
+      !!
 # if defined key_axy_nancheck
       DO jn = 1,jptra
@@ -486,4 +964,9 @@
 # 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
       !!----------------------------------------------------------------------
@@ -514,8 +997,8 @@
          f_pco2a = fq4
       endif
-# if defined key_axy_pi_co2
-      f_pco2a = hist_pco2(1)
-      IF(lwp) WRITE(numout,*) ' MEDUSA atm pCO2  = FIXED'
-# endif
+#  if defined key_axy_pi_co2
+      !! f_pco2a = hist_pco2(1)
+      f_pco2a = 284.725          !! OCMIP pre-industrial pCO2
+#  endif
       !! IF(lwp) WRITE(numout,*) ' MEDUSA nyear     =', nyear
       !! IF(lwp) WRITE(numout,*) ' MEDUSA nsec_day  =', real(nsec_day)
@@ -529,8 +1012,17 @@
 # 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
+      !! 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,1920) == 0 ) THEN
+      IF( kt == nittrc000 .or. mod(kt,960) == 0 ) THEN
          !!----------------------------------------------------------------------
          !! Calculate the carbonate chemistry for the whole ocean on the first
@@ -540,4 +1032,5 @@
          !!
          IF(lwp) WRITE(numout,*) ' MEDUSA calculating all carbonate chemistry at kt =', kt
+         CALL flush(numout)
          !! blank flags
          i2_omcal(:,:) = 0
@@ -549,6 +1042,8 @@
                   !! OPEN wet point IF..THEN loop
                   if (tmask(ji,jj,jk).eq.1) then
-                     !! carbonate chemistry
+                     !! do carbonate chemistry
+                     !!
                      fdep2 = fsdept(ji,jj,jk)           !! set up level midpoint
+                     !!
                      !! set up required state variables
                      zdic = max(0.,trn(ji,jj,jk,jpdic)) !! dissolved inorganic carbon
@@ -556,4 +1051,8 @@
                      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
@@ -571,7 +1070,28 @@
                         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
-                     CALL trc_co2_medusa( ztmp, zsal, zdic, zalk, fdep2, 5.0, f_pco2a, &    ! inputs
-                     f_ph, f_pco2w, f_h2co3, f_hco3, f_co3, f_omcal(ji,jj),            &    ! outputs
+#  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_pco2a, 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_pco2a, 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
                      !! 
@@ -581,4 +1101,6 @@
                         iters, ' AT (', ji, ', ', jj, ', ', jk, ') AT ', kt
                      endif
+#  endif
+                     !!
                      !! store 3D outputs
                      f3_pH(ji,jj,jk)    = f_ph
@@ -588,4 +1110,5 @@
                      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
@@ -607,4 +1130,5 @@
                         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
@@ -633,4 +1157,9 @@
 # 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
@@ -656,5 +1185,4 @@
             !! OPEN wet point IF..THEN loop
             if (tmask(ji,jj,jk).eq.1) then               
-
                !!======================================================================
                !! SETUP LOCAL GRID CELL
@@ -785,6 +1313,4 @@
                if (idf.eq.1.AND.idfval.eq.1.AND.jk.eq.1) then
                   IF (lwp) write (numout,*) '------------------------------'
-                  IF (lwp) write (numout,*) 'dustmo(1) = ', dustmo(ji,jj,1)
-                  IF (lwp) write (numout,*) 'dustmo(2) = ', dustmo(ji,jj,2)
                   IF (lwp) write (numout,*) 'dust      = ', dust(ji,jj)
                endif
@@ -792,14 +1318,33 @@
 
                !! sum tracers for inventory checks
-               ftot_n  = fthk * ( zphn + zphd + zzmi + zzme + zdet + zdin )
-               ftot_si = fthk * ( zpds + zsil )
-               ftot_fe = fthk * ( xrfn * ( zphn + zphd + zzmi + zzme + zdet ) + zfer )
+               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
-               ftot_c  = fthk * ( (xthetapn * zphn) + (xthetapd * zphd) + &
-                         (xthetazmi * zzmi) + (xthetazme * zzme) + zdtc + &
-                         zdic )
-               ftot_a  = fthk * ( zalk )
-               ftot_o2 = fthk * ( zoxy )
-# endif
+                  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
+# endif
+               ENDIF
+
                CALL flush(numout)
 
@@ -814,7 +1359,4 @@
                   !!----------------------------------------------------------------------
                   !!
-                  !! a bit of set up ...
-                  ! f_uwind = zwnd_i(ji,jj)
-                  ! f_vwind = zwnd_j(ji,jj)
                   !! AXY (17/07/14): zwind_i and zwind_j do not exist in this
                   !!                 version of NEMO because it does not include
@@ -827,22 +1369,32 @@
                   !!                 revisited when MEDUSA properly interacts
                   !!                 with UKESM1 physics
-                  ! f_uwind = zwind_i(ji,jj)
-                  ! f_vwind = zwind_j(ji,jj)
-                  ! f_wind  = ((f_uwind**2.0) + (f_vwind**2.0))**0.5
+                  !!
                   f_wind  = wndm(ji,jj)
-                  !! AXY (17/07/14): the current oxygen code takes in separate
-                  !!                 U and V components of the wind; to avoid
-                  !!                 the need to change this, calculate these
-                  !!                 components based on wndm; again, this is
-                  !!                 not ideal, but should suffice as a
-                  !!                 temporary measure; in the long-term all
-                  !!                 of MEDUSA's air-sea gas exchange terms
-                  !!                 will be revisited to ensure that they are
-                  !!                 valid and self-consistent; and the CO2
-                  !!                 code will be wholly replaced with a more
-                  !!                 up-to-date parameterisation
-                  f_uwind = ((f_wind**2.0) / 2.0)**0.5
-                  f_vwind = f_uwind
+                  !!
+                  !! 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)
@@ -852,10 +1404,26 @@
                   !!
 #  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_pco2a, 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_wind, f_pco2a, &     ! 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
+                  CALL trc_co2_medusa( ztmp, zsal, zdic, zalk, 0.0, f_kw660, f_pco2a,  &  ! 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
@@ -869,4 +1437,5 @@
                      iters, ' AT (', ji, ', ', jj, ', ', jk, ') AT ', kt
                   endif
+#   endif
 #  else
                   !! AXY (18/04/13): switch off carbonate chemistry calculations; provide
@@ -882,18 +1451,34 @@
                   f_TDIC         = zdic
                   f_TALK         = zalk
-                  f_dcf          = 1.
+                  f_dcf          = 1.026
                   f_henry        = 1.
+                  !! AXY (23/06/15): add in some extra MOCSY diagnostics
+                  f_fco2w        = fpco2a
+                  f_BetaD        = 1.
+                  f_rhosw        = 1.026
+                  f_opres        = 0.
+                  f_insitut      = ztmp
+                  f_pco2atm      = fpco2a
+                  f_fco2atm      = fpco2a
+                  f_schmidtco2   = 660.
+                  f_kwco2        = 0.
+                  f_K0           = 0.
+                  f_co2starair   = fpco2a
+                  f_dpco2        = 0.
 #  endif
                   !!
-                  !! already in right units; correct for sea-ice; divide through by layer thickness
-                  f_co2flux = (1. - fr_i(ji,jj)) * f_co2flux / fthk
+                  !! 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
-                  CALL trc_oxy_medusa( ztmp, zsal, f_uwind, f_vwind, f_pp0, zoxy / 1000., fthk, &  ! inputs
-                  f_kw660, f_o2flux, f_o2sat )                                                     ! outputs
-                  !!
-                  !! mol/m3/s -> mmol/m3/d; correct for sea-ice
-                  f_o2flux  = (1. - fr_i(ji,jj)) * f_o2flux * 1000. * 60. * 60. * 24. 
-                  f_o2sat   = f_o2sat  * 1000.
+                  !! 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)
@@ -911,11 +1496,85 @@
                   !!
                   IF (jdms .eq. 1) THEN
-                  !!
-                     !! CALL trc_dms_medusa( zchn, zchd, hmld(ji,jj), &                            !! inputs
-                     !! dms_surf )                                                                 !! outputs
-                     CALL trc_dms_medusa( zchn, zchd, hmld(ji,jj), qsr(ji,jj), zdin, &             !! inputs
-                     dms_surf, dms_andr, dms_simo, dms_aran, dms_hall )                            !! outputs
+                     !!
+                     !! 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: finnish calculating dms'
+                     CALL flush(numout)
+#   endif 
+                     ENDIF
+                     !! End iom
                   ENDIF
                   !! End DMS Loop
+                  !!
+                  !! store 2D outputs
+                  IF ( lk_iomput ) THEN
+                      IF( med_diag%ATM_PCO2%dgsave ) THEN
+                         f_pco2a2d(ji,jj) = f_pco2a
+                      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
+                      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
+                  ENDIF
+                  !! 
                endif
                !! End jk = 1 loop within ROAM key 
@@ -953,5 +1612,5 @@
                   !! 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
@@ -1216,7 +1875,17 @@
                endif
                !!
-               fprn_ml = (fprn * zphn * fthk * fq0)
-               fprd_ml = (fprd * zphd * fthk * fq0)
-
+               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
@@ -1535,5 +2204,5 @@
                !! "free" iron concentration (and convert to mmol Fe / m3)
                xFeF        = (xFeT - xFeL) * 1.e-3
-               xFree       = xFeF / (zfer + tiny(zfer))
+               xFree(ji,jj)= xFeF / (zfer + tiny(zfer))
                !!
                !! scavenging of iron (multiple schemes); I'm only really happy with the 
@@ -1842,5 +2511,5 @@
                   IF (lwp) write (numout,*) 'ffetop(',jk,')  = ', ffetop
                   IF (lwp) write (numout,*) 'ffebot(',jk,')  = ', ffebot
-                  IF (lwp) write (numout,*) 'xFree(',jk,')   = ', xFree
+                  IF (lwp) write (numout,*) 'xFree(',jk,')   = ', xFree(ji,jj)
                   IF (lwp) write (numout,*) 'ffescav(',jk,') = ', ffescav
                endif
@@ -1875,5 +2544,5 @@
                !! standard depths in the diagnostic outputs; needs to be
                !! adjusted from per second to per day because of parameter vsed
-               fslownflux = zdet * vsed * 86400.
+               fslownflux(ji,jj) = zdet * vsed * 86400.
 # if defined key_roam
                !!
@@ -1888,5 +2557,5 @@
                !! standard depths in the diagnostic outputs; needs to be
                !! adjusted from per second to per day because of parameter vsed
-               fslowcflux = zdtc * vsed * 86400.
+               fslowcflux(ji,jj) = zdtc * vsed * 86400.
 # endif
 
@@ -2401,5 +3070,5 @@
                      f_fbenin_c(ji,jj)  = ffastc(ji,jj)             !! fast C -> benthic C                       (mol/m2)
                   endif
-                  fsedc    = ffastc(ji,jj)                          !! record seafloor C                         (mol/m2)
+                  fsedc(ji,jj)   = ffastc(ji,jj)                          !! record seafloor C                         (mol/m2)
                   ffastc(ji,jj)  = 0.0
                   !!
@@ -2413,5 +3082,5 @@
                      f_fbenin_n(ji,jj)  = ffastn(ji,jj)             !! fast N -> benthic N                       (mol/m2)
                   endif
-                  fsedn    = ffastn(ji,jj)                          !! record seafloor N                         (mol/m2)
+                  fsedn(ji,jj)   = ffastn(ji,jj)                          !! record seafloor N                         (mol/m2)
                   ffastn(ji,jj)  = 0.0
                   !!
@@ -2424,5 +3093,5 @@
                      f_fbenin_fe(ji,jj) = ffastfe(ji,jj)            !! fast Fe -> benthic Fe                     (mol/m2)
                   endif
-                  fsedfe   = ffastfe(ji,jj)                         !! record seafloor Fe                        (mol/m2)
+                  fsedfe(ji,jj)  = ffastfe(ji,jj)                         !! record seafloor Fe                        (mol/m2)
                   ffastfe(ji,jj) = 0.0
                   !!
@@ -2433,5 +3102,5 @@
                      f_fbenin_si(ji,jj) = ffastsi(ji,jj)            !! fast Si -> benthic Si                     (mol/m2)
                   endif
-                  fsedsi   = ffastsi(ji,jj)                         !! record seafloor Si                        (mol/m2)
+                  fsedsi(ji,jj)   = ffastsi(ji,jj)                         !! record seafloor Si                        (mol/m2)
                   ffastsi(ji,jj) = 0.0
                   !!
@@ -2442,5 +3111,5 @@
                      f_fbenin_ca(ji,jj) = ffastca(ji,jj)            !! fast Ca -> benthic Ca                     (mol/m2)
                   endif
-                  fsedca   = ffastca(ji,jj)                         !! record seafloor Ca                        (mol/m2)
+                  fsedca(ji,jj)   = ffastca(ji,jj)                         !! record seafloor Ca                        (mol/m2)
                   ffastca(ji,jj) = 0.0
                endif
@@ -2639,5 +3308,5 @@
                !!
                !! community respiration (does not include CaCO3 terms - obviously!)
-               fcomm_resp = fc_prod
+               fcomm_resp(ji,jj) = fcomm_resp(ji,jj) + fc_prod
                !!
                !! CaCO3
@@ -2841,4 +3510,11 @@
                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
                !!----------------------------------------------------------------------
@@ -2917,5 +3593,328 @@
 # endif
 
-               IF( ln_diatrc ) THEN
+               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) 
+                  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) 
+                  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            
+                 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.(mbathy(ji,jj)-1)) 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 + fprd) * zphn 
+                      !CALL iom_put( "TPP3"  , tpp3d )
+                  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
+         !!
+         !!
+         !! ** 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
@@ -2925,7 +3924,7 @@
                   !!    IF (lwp) write (*,*) '*******!MEDUSA DIAADD!*******',kt
                   !! endif     
-                  trc2d(ji,jj,1)  = trc2d(ji,jj,1)  + ftot_n                   !! nitrogen inventory
-                  trc2d(ji,jj,2)  = trc2d(ji,jj,2)  + ftot_si                  !! silicon  inventory
-                  trc2d(ji,jj,3)  = trc2d(ji,jj,3)  + ftot_fe                  !! iron     inventory
+                  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
@@ -2957,8 +3956,8 @@
                   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                !! slow detritus flux at  100 m
-                  if (jk.eq.i0200) trc2d(ji,jj,34) = fslownflux                !! slow detritus flux at  200 m
-                  if (jk.eq.i0500) trc2d(ji,jj,35) = fslownflux                !! slow detritus flux at  500 m
-                  if (jk.eq.i1000) trc2d(ji,jj,36) = fslownflux                !! slow detritus flux at 1000 m
+                  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
@@ -2994,9 +3993,9 @@
                   trc2d(ji,jj,68) = trc2d(ji,jj,68) + (freminca * fthk)        !! sum of fast-sinking Ca fluxes
                   if (jk.eq.(mbathy(ji,jj)-1)) then
-                     trc2d(ji,jj,69) = fsedn                                   !! N  sedimentation flux                                  
-                     trc2d(ji,jj,70) = fsedsi                                  !! Si sedimentation flux
-                     trc2d(ji,jj,71) = fsedfe                                  !! Fe sedimentation flux
-                     trc2d(ji,jj,72) = fsedc                                   !! C  sedimentation flux
-                     trc2d(ji,jj,73) = fsedca                                  !! Ca sedimentation flux
+                     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)
@@ -3004,6 +4003,6 @@
                   !! 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                  !! mixed layer non-diatom production
-                  trc2d(ji,jj,82) = trc2d(ji,jj,82) + fprd_ml                  !! mixed layer     diatom production
+                  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
@@ -3012,18 +4011,12 @@
 # endif
                   trc2d(ji,jj,84) = fccd(ji,jj)                                !! last model level above calcite CCD depth
-                  if (jk.eq.1)     trc2d(ji,jj,85) = xFree                     !! surface "free" iron
-                  if (jk.eq.i0200) trc2d(ji,jj,86) = xFree                     !! "free" iron at  100 m
-                  if (jk.eq.i0200) trc2d(ji,jj,87) = xFree                     !! "free" iron at  200 m
-                  if (jk.eq.i0500) trc2d(ji,jj,88) = xFree                     !! "free" iron at  500 m
-                  if (jk.eq.i1000) trc2d(ji,jj,89) = xFree                     !! "free" iron at 1000 m
+                  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)
                   !! 
-                  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
 # if defined key_roam
                   !! ROAM provisionally has access to a further 20 2D diagnostics
@@ -3077,15 +4070,15 @@
                   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               !! slow detritus flux at  100 m
-                  if (jk.eq.i0200) trc2d(ji,jj,143) = fslowcflux               !! slow detritus flux at  200 m
-                  if (jk.eq.i0500) trc2d(ji,jj,144) = fslowcflux               !! slow detritus flux at  500 m
-                  if (jk.eq.i1000) trc2d(ji,jj,145) = fslowcflux               !! slow detritus flux at 1000 m
-                  trc2d(ji,jj,146)  = trc2d(ji,jj,146)  + ftot_c               !! carbon     inventory
-                  trc2d(ji,jj,147)  = trc2d(ji,jj,147)  + ftot_a               !! alkalinity inventory
-                  trc2d(ji,jj,148)  = trc2d(ji,jj,148)  + ftot_o2              !! oxygen     inventory
+                  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.(mbathy(ji,jj)-1)) then
                      trc2d(ji,jj,149) = f_benout_lyso_ca(ji,jj)
                   endif
-                  trc2d(ji,jj,150) = trc2d(ji,jj,150) + (fcomm_resp * fthk)    !! community respiration
+                  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
@@ -3151,70 +4144,71 @@
 		  !!
 		  !! 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
+		 !! 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,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
@@ -3231,6 +4225,6 @@
                      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        !! Slow detritus N flux at 150 m
-                     trc2d(ji,jj,214) = fslowcflux        !! Slow detritus C flux at 150 m
+                     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
@@ -3260,5 +4254,5 @@
                   !!
                   trc3d(ji,jj,jk,1)  = ((fprn + fprd) * zphn)     !! primary production  
-                  trc3d(ji,jj,jk,2)  = fslownflux + ffastn(ji,jj) !! detrital flux
+                  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
@@ -3272,8 +4266,409 @@
             endif
          !! CLOSE horizontal loops
-         END DO
-         END DO
+         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
+                     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 iom_put( "DMS_SURF"  , dms_surf2d )
+                          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
+# 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
+                         CALL iom_put( "SDT__100"  , fslownflux )
+                     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
+                         CALL iom_put( "SDC__100"  , fslowcflux )
+                     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
+                     IF( med_diag%BASIN_01%dgsave ) THEN
+                         CALL iom_put( "BASIN_01"  , fprn2d )
+                     ENDIF
+                     IF( med_diag%BASIN_02%dgsave ) THEN
+                         CALL iom_put( "BASIN_02"  , fdpn22d )
+                     ENDIF
+                     IF( med_diag%BASIN_03%dgsave ) THEN
+                         CALL iom_put( "BASIN_03"  , fdpn2d )
+                     ENDIF
+                     IF( med_diag%BASIN_04%dgsave ) THEN
+                         CALL iom_put( "BASIN_04"  , fgmipn2d )
+                     ENDIF
+                     IF( med_diag%BASIN_05%dgsave ) THEN
+                         CALL iom_put( "BASIN_05"  , fgmepn2d )
+                     ENDIF
+                     IF( med_diag%BASIN_06%dgsave ) THEN
+                         CALL iom_put( "BASIN_06"  , fprd2d )
+                     ENDIF
+                     IF( med_diag%BASIN_07%dgsave ) THEN
+                         CALL iom_put( "BASIN_07"  , fdpd22d )
+                     ENDIF
+                     IF( med_diag%BASIN_08%dgsave ) THEN
+                         CALL iom_put( "BASIN_08"  , fdpd2d )
+                     ENDIF
+                     IF( med_diag%BASIN_09%dgsave ) THEN
+                         CALL iom_put( "BASIN_09"  , fgmepd2d )
+                     ENDIF
+                     IF( med_diag%BASIN_10%dgsave ) THEN
+                         CALL iom_put( "BASIN_10"  , fgmid2d )
+                     ENDIF
+                     IF( med_diag%BASIN_11%dgsave ) THEN
+                         CALL iom_put( "BASIN_11"  , gmidc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_12%dgsave ) THEN
+                         CALL iom_put( "BASIN_12"  , zimesn2d )
+                     ENDIF
+                     IF( med_diag%BASIN_13%dgsave ) THEN
+                         CALL iom_put( "BASIN_13"  , zimesd2d )
+                     ENDIF
+                     IF( med_diag%BASIN_14%dgsave ) THEN
+                         CALL iom_put( "BASIN_14"  , zimesc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_15%dgsave ) THEN
+                         CALL iom_put( "BASIN_15"  , zimesdc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_16%dgsave ) THEN
+                         CALL iom_put( "BASIN_16"  , ziexcr2d )
+                     ENDIF
+                     IF( med_diag%BASIN_17%dgsave ) THEN
+                         CALL iom_put( "BASIN_17"  , ziresp2d )
+                     ENDIF
+                     IF( med_diag%BASIN_18%dgsave ) THEN
+                         CALL iom_put( "BASIN_18"  , zigrow2d )
+                     ENDIF
+                     IF( med_diag%BASIN_19%dgsave ) THEN
+                         CALL iom_put( "BASIN_19"  , fdzmi22d )
+                     ENDIF
+                     IF( med_diag%BASIN_20%dgsave ) THEN
+                         CALL iom_put( "BASIN_20"  , fdzmi2d )
+                     ENDIF
+                     IF( med_diag%BASIN_21%dgsave ) THEN
+                         CALL iom_put( "BASIN_21"  , fgmezmi2d )
+                     ENDIF
+                     IF( med_diag%BASIN_22%dgsave ) THEN
+                         CALL iom_put( "BASIN_22"  , fgmed2d )
+                     ENDIF
+                     IF( med_diag%BASIN_23%dgsave ) THEN
+                         CALL iom_put( "BASIN_23"  , gmedc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_24%dgsave ) THEN
+                         CALL iom_put( "BASIN_24"  , zemesn2d )
+                     ENDIF  
+                     IF( med_diag%BASIN_25%dgsave ) THEN
+                         CALL iom_put( "BASIN_25"  , zemesd2d )
+                     ENDIF
+                     IF( med_diag%BASIN_26%dgsave ) THEN
+                         CALL iom_put( "BASIN_26"  , zemesc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_27%dgsave ) THEN
+                         CALL iom_put( "BASIN_27"  , zemesdc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_28%dgsave ) THEN
+                         CALL iom_put( "BASIN_28"  , zeexcr2d )
+                     ENDIF
+                     IF( med_diag%BASIN_29%dgsave ) THEN
+                         CALL iom_put( "BASIN_29"  , zeresp2d )
+                     ENDIF
+                     IF( med_diag%BASIN_30%dgsave ) THEN
+                         CALL iom_put( "BASIN_30"  , zegrow2d )
+                     ENDIF
+                     IF( med_diag%BASIN_31%dgsave ) THEN
+                         CALL iom_put( "BASIN_30"  , fdzme22d )
+                     ENDIF
+                     IF( med_diag%BASIN_32%dgsave ) THEN
+                         CALL iom_put( "BASIN_32"  , fdzme2d )
+                     ENDIF
+                     IF( med_diag%BASIN_33%dgsave ) THEN
+                         CALL iom_put( "BASIN_33"  , fslown2d )
+                     ENDIF
+                     IF( med_diag%BASIN_34%dgsave ) THEN
+                         CALL iom_put( "BASIN_34"  , fdd2d )
+                     ENDIF
+                     IF( med_diag%BASIN_35%dgsave ) THEN
+                         CALL iom_put( "BASIN_35"  , fslowc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_36%dgsave ) THEN
+                         CALL iom_put( "BASIN_36"  , mdetc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_37%dgsave ) THEN
+                         CALL iom_put( "BASIN_37"  , ftempn2d )
+                     ENDIF
+                     IF( med_diag%BASIN_38%dgsave ) THEN
+                         CALL iom_put( "BASIN_38"  , freminn2d )
+                     ENDIF
+                     IF( med_diag%BASIN_39%dgsave ) THEN
+                         CALL iom_put( "BASIN_39"  , ftempc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_40%dgsave ) THEN
+                         CALL iom_put( "BASIN_40"  , freminc2d )
+                     ENDIF
+                     IF( med_diag%BASIN_41%dgsave ) THEN
+                         CALL iom_put( "BASIN_41"  , fcomm_resp )
+                     ENDIF                  
+                     IF( med_diag%BASIN_42%dgsave ) THEN
+                         CALL iom_put( "BASIN_42"  , fslownflux )
+                     ENDIF
+                     IF( med_diag%BASIN_43%dgsave ) THEN
+                         CALL iom_put( "BASIN_43"  , fslowcflux )
+                     ENDIF
+                     IF( med_diag%BASIN_44%dgsave ) THEN
+                         CALL iom_put( "BASIN_44"  , ffastn )
+                     ENDIF
+                     IF( med_diag%BASIN_45%dgsave ) THEN
+                         CALL iom_put( "BASIN_45"  , ffastc )
+                     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
+                         CALL iom_put( "SDT__200"  , fslownflux )
+                     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
+                         CALL iom_put( "SDC__200"  , fslowcflux )
+                     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
+                         CALL iom_put( "SDT__500"  , fregen2d )
+                     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
+                         CALL iom_put( "SDC__500"  , fslowcflux )
+                     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
+                         CALL iom_put( "SDT_1000"  , fslownflux )
+                     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
+                         CALL iom_put( "SDC_1000"  , fslowcflux )
+                     ENDIF 
+# endif                      
+                 ENDIF
+                 !! to do on every k loop :
+                 IF( med_diag%DETFLUX3%dgsave ) THEN
+                      detflux3d(:,:,jk) = fslownflux(:,:) + ffastn(:,:) !! detrital flux
+                      !CALL iom_put( "DETFLUX3"  , ftot_n )
+                 ENDIF
+             ENDIF
       !! CLOSE vertical loop
-      END DO
+      ENDDO
 
       !!----------------------------------------------------------------------
@@ -3308,119 +4703,129 @@
          zn_sed_ca(:,:) = za_sed_ca(:,:)
       endif
-      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)
+      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
-      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
+            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(:,:)  = zn_sed_n(:,:)
+               zb_sed_n(:,:)  = za_sed_n(:,:)
                zn_sed_n(:,:)  = za_sed_n(:,:)
                za_sed_n(:,:)  = 0.0
                !!
-               zb_sed_fe(:,:) = zn_sed_fe(:,:)
+               zb_sed_fe(:,:) = za_sed_fe(:,:)
                zn_sed_fe(:,:) = za_sed_fe(:,:)
                za_sed_fe(:,:) = 0.0
                !!
-               zb_sed_c(:,:)  = zn_sed_c(:,:)
+               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(:,:) = zn_sed_si(:,:)
+               zb_sed_si(:,:) = za_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(:,:))
+               zb_sed_ca(:,:) = za_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
          !!----------------------------------------------------------------------
@@ -3465,7 +4870,7 @@
                trc2d(ji,jj,117) = foxy_anox(ji,jj)  !! integrated unrealised oxygen consumption
 # endif
-            END DO
-         END DO
-
+            ENDDO
+         ENDDO
+         
 # if defined key_roam
 #  if defined key_axy_nancheck
@@ -3488,6 +4893,6 @@
                         &        ji, jj, jn
                      endif
-                  enddo
-               enddo
+                  ENDDO
+               ENDDO
 	       CALL ctl_stop( 'trcbio_medusa, NAN in 2D diagnostic field' )
             endif
@@ -3509,7 +4914,7 @@
                            &        ji, jj, jk, jn
                         endif
-                     enddo
-                  enddo
-               enddo
+                     ENDDO
+                  ENDDO
+               ENDDO
 	       CALL ctl_stop( 'trcbio_medusa, NAN in 3D diagnostic field' )
             endif
@@ -3526,10 +4931,11 @@
          DO jn=1,jp_medusa_2d
              CALL lbc_lnk(trc2d(:,:,jn),'T',1. )
-         END DO 
+         ENDDO 
 
          !! Lateral boundary conditions on trc3d
          DO jn=1,jp_medusa_3d
              CALL lbc_lnk(trc3d(:,:,1,jn),'T',1. )
-         END DO 
+         ENDDO 
+
 
 # if defined key_axy_nodiag
@@ -3545,5 +4951,5 @@
 # endif
 
-# if defined key_iomput
+
          !!----------------------------------------------------------------------
          !! Add in XML diagnostics stuff
@@ -3569,6 +4975,529 @@
 !!          CALL iom_put(TRIM(ctrc3d(5)), trc3d(:,:,:,5))
 !! #  endif
-# endif
-      ENDIF ! end of ln_diatrc option
+
+
+      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
+# endif         
+
+      CALL wrk_dealloc( jpi, jpj,   zw2d   )
+
+     ENDIF ! end of ln_diatrc option
 
 # if defined key_trc_diabio
@@ -3576,5 +5505,5 @@
       DO jn=1,jp_medusa_trd
           CALL lbc_lnk(trbio(:,:,1,jn),'T',1. )
-      END DO 
+      ENDDO 
 # endif
 
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcco2_medusa.F90	(revision 6639)
@@ -47,5 +47,5 @@
 !=======================================================================
 !
-      SUBROUTINE trc_co2_medusa( Temp, Sal, DIC, ALK, Depth, Wnd, pCO2a, &
+      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 )
@@ -72,4 +72,6 @@
 ! 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: 
@@ -85,5 +87,6 @@
       REAL(wp), INTENT( in )    :: ALK        ! meq  / m3
       REAL(wp), INTENT( in )    :: Depth      ! m
-      REAL(wp), INTENT( in )    :: Wnd        ! m / s
+!     REAL(wp), INTENT( in )    :: Wnd        ! m / s
+      REAL(wp), INTENT( in )    :: xkw        ! m / s
       REAL(wp), INTENT( in )    :: pCO2a      ! uatm
 !----------------------------------------------------------------------
@@ -95,5 +98,5 @@
       REAL(wp), INTENT( inout ) :: om_cal     ! normalised
       REAL(wp), INTENT( inout ) :: om_arg     ! normalised
-      REAL(wp), INTENT( inout ) :: co2flux    ! mmol / m2 / d
+      REAL(wp), INTENT( inout ) :: co2flux    ! mmol / m2 / s
       REAL(wp), INTENT( inout ) :: TDIC       ! umol / kg
       REAL(wp), INTENT( inout ) :: TALK       ! ueq  / kg
@@ -129,5 +132,5 @@
    !                 (i.e. surface calculations being performed)
    if (Depth .eq. 0.0) then
-      call Air_sea_exchange( Temp, Wnd, pCO2w, pCO2a, henry, dcf, &         ! inputs
+      call Air_sea_exchange( Temp, xkw, pCO2w, pCO2a, henry, dcf, &         ! inputs
          co2flux )                                                          ! output
    else
@@ -145,5 +148,5 @@
       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_wind  =', Wnd
+      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
@@ -162,5 +165,5 @@
       &        ' DIC', DIC, ' ALK', ALK
       if (lwp) write (numout,'(a,a,f10.3,a,f10.3)') 'CO2FLUX-NAN', &
-      &        ' WND', Wnd, ' PH ', ph
+      &        ' XKW', xkw, ' PH ', ph
       if (lwp) write (numout,'(a,a,i6)') 'CO2FLUX-NAN', &
       &        ' ITERS', iters
@@ -196,5 +199,5 @@
 !  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/d) = ", flux
+!  WRITE(*,'(A27,F10.3)') "    air sea flux(mmol/m2/s) = ", flux
 !  WRITE(*,*) " "
 
@@ -287,5 +290,5 @@
 !=======================================================================
 !
-      SUBROUTINE Air_sea_exchange( T, Wnd, pco2w, pco2a, henry, dcf, &
+      SUBROUTINE Air_sea_exchange( T, xkw, pco2w, pco2a, henry, dcf, &
       flux )
 !      
@@ -302,5 +305,6 @@
 !  pCO2a    partial pressure of CO2 in the atmosphere (usually external forcing).
 !  T        temperature (C)
-!  Wnd      wind speed, metres
+!  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
@@ -312,5 +316,5 @@
    IMPLICIT NONE
 
-      REAL(wp), INTENT( in )    :: T, wnd, pco2w, pco2a, henry, dcf ! INPUT PARAMETERS:
+      REAL(wp), INTENT( in )    :: T, xkw, pco2w, pco2a, henry, dcf ! INPUT PARAMETERS:
 !-----------------------------------------------------------------------
       REAL(wp), INTENT( inout ) :: flux                             ! OUTPUT Variables
@@ -320,5 +324,6 @@
 ! 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 = (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
 
@@ -326,4 +331,7 @@
 ! 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 
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcdms_medusa.F90	(revision 6639)
@@ -39,5 +39,5 @@
 !
    SUBROUTINE trc_dms_medusa( chn, chd, mld, xqsr, xdin,   &  !! inputs
-     &  dms_surf, dms_andr, dms_simo, dms_aran, dms_hall )    !! outputs
+     &  dms_andr, dms_simo, dms_aran, dms_hall )              !! outputs
 !      
 !=======================================================================
@@ -70,4 +70,9 @@
       !!                    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
+      !!
 !=======================================================================
 
@@ -79,5 +84,4 @@
       REAL(wp), INTENT( in )    :: xqsr                 !! surface irradiance        (W/m2)
       REAL(wp), INTENT( in )    :: xdin                 !! surface DIN               (mmol N/m3)
-      REAL(wp), INTENT( inout ) :: dms_surf             !! DMS surface concentration (mol/m3) 
       REAL(wp), INTENT( inout ) :: dms_andr             !! DMS surface concentration (mol/m3) 
       REAL(wp), INTENT( inout ) :: dms_simo             !! DMS surface concentration (mol/m3) 
@@ -89,73 +93,4 @@
       !! temporary variables
       REAL(wp) ::    fq1,fq2,fq3
-!
-!! IJT (30/03/13): DMS calc needs this
-!! Julien : in Simo & Dachs, GBC, 2002, DMS is derived from 
-!!          CHL/MLD ratio in mg/m4 (i.e. CHL is in mg/m3
-!!          MLD in m).
-!!          In MEDUSA, we already have CHL in mg/m3 for both
-!!          Diatoms and non-diatoms (zchn,zchd); and mld from
-!!          NEMO (hmld) in m.
-      CHL = 0.0
-!!
-!!            CHL = mask * TT(I,J,1,PHYTO_TRACER) &
-!!     &       * c2n_p * mw_carbon / CCHL_P(I,J,1,1)
-      CHL = chn+chd                                 !! mg/m3 
-!!
-!! ------------------------------------------------
-!!  Calculate the DMS concentration in nM (nanomol/litre)
-!!   from Simo & Dachs, GBC, 2002, modified to be positive-definite
-!!   for MLD>182.536m, using DMS=90./MLD (Aranami & Tsunogai, JGR, 2004)
-!!   Multiply by 1.0E-6 to convert nM to (mol/m3)
-!!       cmr = fm(i,1)*chl/mld(i)
-!!       IF (cmr .lt. 0.02) THEN
-!!         IF (mld(i) .le. 182.536) THEN
-!!           csurf(i,astf_dms) = 1.0e-6*fm(i,1)*(-LOG(mld(i)) + 5.7)
-!!         ELSE
-!!           csurf(i,astf_dms) = 1.0e-6*fm(i,1)*(90./mld(i))
-!!         ENDIF
-!!       ELSE
-!!         csurf(i,astf_dms) = 1.0e-6*fm(i,1)*(55.8*cmr + 0.6)
-!!       ENDIF
-!!
-        cmr      = CHL / mld
-!       sw_dms   = 0.5 + SIGN( 0.5, cmr - 0.02 )
-!! Jpalm (11-08-2014)
-!! Explanation about the SIGN function :
-!! not easy to read, but maybe "more elegant and efficient")
-!! here for example: 
-!! sw_dms = 1 if cmr is greater than 0.02,
-!!          0 if cmr lower than 0.02
-!! then 
-!! if cmr < 0.02
-!!  dms_surf =  1.0e-6 * 90.0 / mld 
-!!       or  =  1.0e-6 * 5.7 - LOG(mld)
-!! and if cmr > 0.02
-!!  dms_surf = 1.0e-6 * ( 55.8 * cmr + 0.6 )
-!! what is equivalent to the IF loops formulations.
-!! difference is on the stresholds between mld = 182.536m
-!! (strange value...)
-!! and the Max function... that stay uncertain.
-!!
-!        dms_surf = 1.0e-6 * ( sw_dms *             &
-!     &  ( 55.8 * cmr + 0.6 ) + ( 1.0 - sw_dms ) *  &
-!     &  ( MAX( 90.0 / mld, 5.7 - LOG(mld) ) ) )
-!
-! AXY (12/01/15): the DMS equation donated by the UKMO does not match
-!                 that reported in Halloran et al. (2010); amend the
-!                 equations appropriately
-!
-        if (cmr .lt. 0.02) then
-           dms_surf = (-1.0 * log(mld)) + 5.7
-        else
-           dms_surf = (55.8 * cmr) + 0.6
-        endif
-!    
-        if (mld > 182.5) then
-           dms_surf = (90.0 / mld)
-        endif
-!     
-        dms_surf = 1.0e-6 * dms_surf
-
 ! 
 !=======================================================================
@@ -163,4 +98,8 @@
 ! 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)
@@ -180,5 +119,4 @@
 !
 ! AXY (13/03/15): Simo & Dachs (2002)
-        cmr = CHL / mld
         fq1 = (-1 * log(mld)) + 5.7
         fq2 = (55.8 * cmr) + 0.6
@@ -191,5 +129,4 @@
 !           
 ! AXY (13/03/15): Aranami & Tsunogai (2004)
-        cmr = CHL / mld
         fq1 = 60.0 / mld
         fq2 = (55.8 * cmr) + 0.6
@@ -202,5 +139,4 @@
 !        
 ! AXY (13/03/15): Halloran et al. (2010)
-        cmr = CHL / mld
         fq1 = (-1 * log(mld)) + 5.7
         fq2 = (55.8 * cmr) + 0.6
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 6639)
@@ -36,4 +36,8 @@
    LOGICAL, PUBLIC ::                  &
       bocalccd = .TRUE.
+   !! JPALM (14/09/15)
+   LOGICAL, PUBLIC ::                  &
+      ln_ccd = .TRUE.
+
    INTEGER ::                          &
       numccd
@@ -232,4 +236,28 @@
      
       !!----------------------------------------------------------------------
+      !! 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)
+
+      !!----------------------------------------------------------------------
       !! AXY (04/11/13): initialise fields previously done by trc_sed_medusa
       !!----------------------------------------------------------------------
@@ -302,22 +330,32 @@
       !! -------------
       !!
-      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'
+      !!!! 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'
+         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)
-      
+         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
 
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcnam_medusa.F90	(revision 6639)
@@ -22,4 +22,5 @@
    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
@@ -29,5 +30,6 @@
    PRIVATE
 
-   PUBLIC   trc_nam_medusa   ! called by trcnam.F90 module
+   PUBLIC   trc_nam_medusa       ! called by trcnam.F90 module
+   PUBLIC   trc_nam_iom_medusa   ! called by trcnam.F90 module
 
    !!* Substitution
@@ -83,5 +85,5 @@
       &  xsdiss,                                              &
       &  vsed,xhr,                                            &
-      &  sedlam,sedlostpoc,jpkb,jdms
+      &  sedlam,sedlostpoc,jpkb,jdms,jdms_input,jdms_model
 #if defined key_roam
       NAMELIST/natroam/ xthetaphy,xthetazoo,xthetanit,        &
@@ -138,11 +140,11 @@
      IF( ( .NOT.lk_iomput .AND. ln_diatrc ) .OR. ( ln_diatrc .AND. lk_medusa ) ) THEN
          !
-         ! Namelist nampisdia
+         ! Namelist nammeddia
          ! -------------------
-         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
+         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 nampisdia in configuration namelist : Pisces diagnostics
+         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 )
@@ -338,4 +340,6 @@
       jpkb	  = 0.
       jdms        = 0
+      jdms_input  = 0
+      jdms_input  = 3
             
       !REWIND(numnatm)
@@ -343,11 +347,11 @@
          ! Namelist natbio
          ! -------------------
-         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
-         READ  ( numnatp_ref, natbio, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
-
-         REWIND( numnatp_cfg )              ! Namelist nampisdia in configuration namelist : Pisces diagnostics
-         READ  ( numnatp_cfg, natbio, IOSTAT = ios, ERR = 902 )
-902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
+         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 )
 
@@ -488,8 +492,8 @@
 !! 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
 !!
@@ -510,4 +514,18 @@
          &   ' 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,*)     &
@@ -544,4 +562,11 @@
          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,*) ' '
@@ -971,8 +996,28 @@
          &   ' Vert layer for diagnostic of vertical flux,                jpkp        = ', jpkb
 !!
-!! UKESM1 - new diagnostics  !! Jpalm
+!! 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
@@ -1032,14 +1077,14 @@
 
       !READ(numnatm,natroam)
-         ! Namelist natbio
+         ! Namelist natroam
          ! -------------------
-         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
-         READ  ( numnatp_ref, natbio, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
-
-         REWIND( numnatp_cfg )              ! Namelist nampisdia in configuration namelist : Pisces diagnostics
-         READ  ( numnatp_cfg, natbio, IOSTAT = ios, ERR = 902 )
-902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
-         IF(lwm) WRITE ( numonp, natbio )
+         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
@@ -1086,11 +1131,11 @@
          ! Namelist natopt
          ! -------------------
-         REWIND( numnatp_ref )              ! Namelist nampisdia in reference namelist : Pisces diagnostics
-         READ  ( numnatp_ref, natopt, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in reference namelist', lwp )
-
-         REWIND( numnatp_cfg )              ! Namelist nampisdia in configuration namelist : Pisces diagnostics
-         READ  ( numnatp_cfg, natopt, IOSTAT = ios, ERR = 902 )
-902      IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammeddia in configuration namelist', lwp )
+         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 )
 
@@ -1126,4 +1171,1175 @@
    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("BASIN_01")) THEN 
+          med_diag%BASIN_01%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_01%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_02")) THEN 
+          med_diag%BASIN_02%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_02%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_03")) THEN 
+          med_diag%BASIN_03%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_03%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_04")) THEN 
+          med_diag%BASIN_04%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_04%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_05")) THEN 
+          med_diag%BASIN_05%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_05%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_06")) THEN 
+          med_diag%BASIN_06%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_06%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_07")) THEN 
+          med_diag%BASIN_07%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_07%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_08")) THEN 
+          med_diag%BASIN_08%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_08%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_09")) THEN 
+          med_diag%BASIN_09%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_09%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_10")) THEN 
+          med_diag%BASIN_10%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_10%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_11")) THEN 
+          med_diag%BASIN_11%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_11%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_12")) THEN 
+          med_diag%BASIN_12%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_12%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_13")) THEN 
+          med_diag%BASIN_13%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_13%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_14")) THEN 
+          med_diag%BASIN_14%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_14%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_15")) THEN 
+          med_diag%BASIN_15%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_15%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_16")) THEN 
+          med_diag%BASIN_16%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_16%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_17")) THEN 
+          med_diag%BASIN_17%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_17%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_18")) THEN 
+          med_diag%BASIN_18%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_18%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_19")) THEN 
+          med_diag%BASIN_19%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_19%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_20")) THEN 
+          med_diag%BASIN_20%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_20%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_21")) THEN 
+          med_diag%BASIN_21%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_21%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_22")) THEN 
+          med_diag%BASIN_22%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_22%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_23")) THEN 
+          med_diag%BASIN_23%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_23%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_24")) THEN 
+          med_diag%BASIN_24%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_24%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_25")) THEN 
+          med_diag%BASIN_25%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_25%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_26")) THEN 
+          med_diag%BASIN_26%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_26%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_27")) THEN 
+          med_diag%BASIN_27%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_27%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_28")) THEN 
+          med_diag%BASIN_28%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_28%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_29")) THEN 
+          med_diag%BASIN_29%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_29%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_30")) THEN 
+          med_diag%BASIN_30%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_30%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_31")) THEN 
+          med_diag%BASIN_31%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_31%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_32")) THEN 
+          med_diag%BASIN_32%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_32%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_33")) THEN 
+          med_diag%BASIN_33%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_33%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_34")) THEN 
+          med_diag%BASIN_34%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_34%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_35")) THEN 
+          med_diag%BASIN_35%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_35%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_36")) THEN 
+          med_diag%BASIN_36%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_36%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_37")) THEN 
+          med_diag%BASIN_37%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_37%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_38")) THEN 
+          med_diag%BASIN_38%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_38%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_39")) THEN 
+          med_diag%BASIN_39%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_39%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_40")) THEN 
+          med_diag%BASIN_40%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_40%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_41")) THEN 
+          med_diag%BASIN_41%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_41%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_42")) THEN 
+          med_diag%BASIN_42%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_42%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_43")) THEN 
+          med_diag%BASIN_43%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_43%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_44")) THEN 
+          med_diag%BASIN_44%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_44%dgsave = .FALSE.
+      ENDIF
+      IF  (iom_use("BASIN_45")) THEN 
+          med_diag%BASIN_45%dgsave = .TRUE.
+      ELSE 
+          med_diag%BASIN_45%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("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
+      !!
+      !!
+   END SUBROUTINE   trc_nam_iom_medusa
+   
 #else
    !!----------------------------------------------------------------------
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcopt_medusa.F90	(revision 6639)
@@ -73,5 +73,22 @@
       ! determination of surface irradiance
       ! -----------------------------------
-      zpar0m (:,:)   = qsr   (:,:) * 0.43
+      ! 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); 
@@ -92,5 +109,4 @@
       zparr  (:,:,1) = 0.5 * zpar0m(:,:)
       zparg  (:,:,1) = 0.5 * zpar0m(:,:)
-
 
       ! determination of xpar
@@ -146,5 +162,4 @@
       ENDDO 
 
-
       IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
          WRITE(charout, FMT="('opt')")
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcoxy_medusa.F90	(revision 6639)
@@ -34,5 +34,4 @@
 ! The following is a map of the subroutines contained within this module
 ! - trc_oxy_medusa
-!      - CALLS gas_transfer
 !      - CALLS oxy_schmidt
 !      - CALLS oxy_sato
@@ -42,6 +41,6 @@
 !=======================================================================
 !
-   SUBROUTINE trc_oxy_medusa( pt, ps, uwind, vwind, pp0, o2, dz, &  !! inputs
-      kw660, o2flux, o2sat )                                        !! outputs
+   SUBROUTINE trc_oxy_medusa( pt, ps, kw660, pp0, o2,  &  !! inputs
+      kwo2, o2flux, o2sat )                               !! outputs
 !      
 !=======================================================================
@@ -57,16 +56,18 @@
       !! 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)
-      !!     uwind   u-wind velocity                 (m/s)
-      !!     vwind   v-wind velocity                 (m/s)
+      !!     kw660   gas transfer velocity           (m/s)
       !!     pp0     surface pressure                (divided by 1 atm)
-      !!     o2      surface O2 concentration        (mol/m3)
-      !!     dz      surface layer thickness         (m)
-      !! (*) kw660   gas transfer velocity           (m/s)
-      !! (*) o2flux  exchange rate of oxygen         (mol/m3/s)
-      !! (+) o2sat   oxygen saturation concentration (mol/m3)
+      !!     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).  
@@ -78,16 +79,14 @@
       REAL(wp), INTENT( in )    :: pt
       REAL(wp), INTENT( in )    :: ps
-      REAL(wp), INTENT( in )    :: uwind
-      REAL(wp), INTENT( in )    :: vwind
+      REAL(wp), INTENT( in )    :: kw660
       REAL(wp), INTENT( in )    :: pp0
       REAL(wp), INTENT( in )    :: o2
-      REAL(wp), INTENT( in )    :: dz
-      REAL(wp), INTENT( inout ) :: kw660, o2flux, o2sat
-!
-      REAL(wp) :: scl_wind, kwo2, o2schmidt, o2sato
-!
-! Calculate gas transfer
-! 
-      call gas_transfer(uwind, vwind, scl_wind, kw660)
+      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
@@ -106,5 +105,10 @@
 ! Calculate time rate of change of O2 due to gas exchange (mol/m3/s)
 !
-      o2flux = kwo2 * (o2sat - o2) / dz
+      o2flux = kwo2 * (o2sat - mol_o2)
+!
+! Oxygen flux and saturation to mmol / m3
+!
+      o2sat  =  o2sat * 1000.
+      o2flux = o2flux * 1000.
 !
       END SUBROUTINE trc_oxy_medusa
@@ -130,4 +134,12 @@
       !! 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)
@@ -141,12 +153,21 @@
 !
       REAL(wp) :: pt, o2_schmidt
-      REAL(wp) :: a0, a1, a2, a3
-!
-      data a0 /    1638.0 /
-      data a1 /    -81.83 /
-      data a2 /     1.483 /
-      data a3 / -0.008004 /
-!
-      o2_schmidt = a0 + pt*(a1 + pt*(a2 + pt*a3))
+      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
@@ -231,88 +252,4 @@
 !=======================================================================
 
-!=======================================================================
-!
-   SUBROUTINE gas_transfer( uwind, vwind, &  !! input 
-      scl_wind, k )                          !! output
-!      
-!=======================================================================
-      !!
-      !! Title  : Calculates gas transfer velocity
-      !! Author : Andrew Yool
-      !! Date   : 15/10/04 (revised 04/08/2011)
-      !! 
-      !! 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.
-      !! 
-      !! Subroutine inputs are (in order) :
-      !!     uwind     wind u velocity at 10 m (m/s)
-      !!     vwind     wind v velocity at 10 m (m/s)
-      !! (+) scl_wind  scalar wind velocity at 10 m (m/s)
-      !! (*) k         gas transfer velocity (m/s)
-      !! Where (*) is the function output and (+) is a diagnostic output.
-      !!
-!=======================================================================
-
-      implicit none
-!
-! Input variables
-      REAL(wp) :: uwind, vwind
-!
-! Output variables
-      REAL(wp) :: scl_wind, k, tmp_k
-!
-! Choice of parameterisation
-      INTEGER  :: eqn
-!
-! Coefficients for various parameterisations
-      REAL(wp), DIMENSION(6) :: a
-      REAL(wp), DIMENSION(6) :: b
-!
-! 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 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   /
-!
-! Which parameterisation is to be used?
-      eqn = 2
-!
-! Calculate scalar wind (m/s)
-      scl_wind = (uwind**2 + vwind**2)**0.5
-!
-! Calculate gas transfer velocity (cm/h)
-      tmp_k = (a(eqn) * scl_wind**2) + (b(eqn) * scl_wind)
-!
-! Convert tmp_k from cm/h to m/s
-      k = tmp_k / (100. * 3600.)
-!
-      END SUBROUTINE gas_transfer
-
-!=======================================================================
-!=======================================================================
-!=======================================================================
-
 #else
    !!======================================================================
@@ -322,14 +259,14 @@
 CONTAINS
 
-   SUBROUTINE trc_oxy_medusa( pt, ps, uwind, vwind, pp0, o2, dz, &  !! inputs
-      kw660, o2flux, o2sat )                                        !! outputs
+   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( in )    :: dz
-      REAL(wp), INTENT( inout ) :: kw660, o2flux, o2sat
+      REAL(wp), INTENT( inout ) :: o2flux, o2sat
 
       WRITE(*,*) 'trc_oxy_medusa: You should not have seen this print! error?', kt
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcrst_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcrst_medusa.F90	(revision 6639)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcrst_medusa.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsed_medusa.F90	(revision 6639)
@@ -23,5 +23,7 @@
    !! 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
@@ -39,13 +41,20 @@
 
    !! AXY (10/02/09)
-   LOGICAL, PUBLIC ::                  &
-      bdustfer = .TRUE.
+   LOGICAL, PUBLIC  ::   bdustfer  !: boolean for dust input from the atmosphere
    REAL(wp), PUBLIC ::                 &
       sedfeinput = 1.e-9_wp  ,         &
       dustsolub  = 0.014_wp
+
+   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"
@@ -90,6 +99,16 @@
 
       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
@@ -120,5 +139,17 @@
 
       !! AXY (10/02/09)
-      IF( (jnt == 1) .and. (bdustfer) )  CALL trc_sed_medusa_sbc( kt )
+      !!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 
+      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
+      ELSE
+         dust(:,:) = 0.0
+      ENDIF
+      !!
+           
       !!
       zirondep(:,:,:) = 0.e0     !! Initialisation of deposition variables
@@ -165,6 +196,12 @@
                trbio(ji,jj,jk,8) = ztra
 # endif
-               IF( ln_diatrc ) &
-                  &  trc2d(ji,jj,8) = trc2d(ji,jj,8) + ztra * fse3t(ji,jj,jk) * 86400.
+               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
@@ -175,8 +212,14 @@
 # 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
-
+      !!
+      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
 
@@ -238,4 +281,9 @@
 
    !! 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)
 
@@ -243,97 +291,91 @@
       !!                  ***  ROUTINE trc_sed_medusa_sbc  ***
       !!
-      !! ** Purpose :   Read and interpolate the external sources of 
-      !!                nutrients
-      !!
-      !! ** Method  :   Read the files and interpolate the appropriate variables
-      !!
-      !! ** input   :   external netcdf files
+      !! ** 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
-
-      !! * Local declarations
-      INTEGER ::   &
-         imois, imois2,       &  ! temporary integers
-         i15  , iman             !    "          "
-      REAL(wp) ::   &
-         zxy                     !    "         "
+      INTEGER  :: ji, jj, jk, jm, ifpr
+      INTEGER  :: ii0, ii1, ij0, ij1
+      INTEGER  :: numdust
+      INTEGER  :: ierr 
+      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) ::   sn_dust               ! informations about the fields to be read
+      !
+      NAMELIST/nammedsbc/cn_dir, sn_dust, bdustfer 
 
       !!---------------------------------------------------------------------
-
-      !! Initialization
-      !! --------------
-      !!
-      i15 = nday / 16
-      iman  = INT( raamo )
-      imois = nmonth + i15 - 1
-      IF( imois == 0 ) imois = iman
-      imois2 = nmonth
-
-      !! 1. first call kt=nittrc000
-      !! -----------------------
-      !!
-      IF( kt == nittrc000 ) THEN
-         ! initializations
-         nflx1  = 0
-         nflx11 = 0
-         ! open the file
-         IF(lwp) THEN
-            WRITE(numout,*) ' '
-            WRITE(numout,*) ' **** Routine trc_sed_medusa_sbc'
+      !
+      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
+         !
+         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' )
+         !
+         CALL fld_fill( sf_dust, (/ sn_dust /), cn_dir, 'trc_sed_medusa_sbc', 'Atmospheric dust deposition', 'nammedsed' )
+                                   ALLOCATE( sf_dust(1)%fnow(jpi,jpj,1)   )
+         IF( sn_dust%ln_tint )     ALLOCATE( sf_dust(1)%fdta(jpi,jpj,1,2) )
+         !
+         IF( Agrif_Root() ) THEN   !  Only on the master grid
+            ! Get total input dust ; need to compute total atmospheric supply of Si in a year
+            CALL iom_open (  TRIM( sn_dust%clname ) , numdust )
+            CALL iom_gettime( numdust, zsteps, kntime=ntimes_dust)  ! get number of record in file
+            ALLOCATE( zdust(jpi,jpj,ntimes_dust) )
+            DO jm = 1, ntimes_dust
+               CALL iom_get( numdust, jpdom_data, TRIM( sn_dust%clvar ), zdust(:,:,jm), jm )
+            END DO
+            CALL iom_close( numdust )
+            DEALLOCATE( zdust)
          ENDIF
-         CALL iom_open ( 'dust.orca.nc', numdust )
-	 IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: dust.orca.nc opened'
-      ENDIF
-
-      !! Read monthly file
-      !! ----------------
-      !!
-      IF( kt == nittrc000 .OR. imois /= nflx1 ) THEN
-
-         !! Calendar computation
-         !!
-         !! nflx1 number of the first file record used in the simulation
-         !! nflx2 number of the last  file record
-         !!
-         nflx1 = imois
-         nflx2 = nflx1+1
-         nflx1 = MOD( nflx1, iman )
-         nflx2 = MOD( nflx2, iman )
-         IF( nflx1 == 0 )   nflx1 = iman
-         IF( nflx2 == 0 )   nflx2 = iman
-         IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: first record file used nflx1 ',nflx1
-         IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: last  record file used nflx2 ',nflx2
-
-         !! Read monthly fluxes data
-         !!
-         !! humidity
-         !!
-         CALL iom_get ( numdust, jpdom_data, 'dust', dustmo(:,:,1), nflx1 )
-         CALL iom_get ( numdust, jpdom_data, 'dust', dustmo(:,:,2), nflx2 )
-
-         IF(lwp .AND. nitend-nit000 <= 100 ) THEN
-            WRITE(numout,*)
-            WRITE(numout,*) ' read clio flx ok'
-            WRITE(numout,*)
-            WRITE(numout,*)
-            WRITE(numout,*) 'Clio month: ',nflx1,'  field: dust'
-            CALL prihre( dustmo(:,:,1),jpi,jpj,1,jpi,20,1,jpj,10,1e9,numout )
-         ENDIF
-
-      ENDIF
-
-      !! 3. at every time step interpolation of fluxes
-      !! ---------------------------------------------
-      !!
-      zxy = FLOAT( nday + 15 - 30 * i15 ) / 30
-      dust(:,:) = ( (1.-zxy) * dustmo(:,:,1) + zxy * dustmo(:,:,2) )
-
-      IF( kt == nitend ) THEN
-         CALL iom_close (numdust)
-         IF(lwp) WRITE(numout,*) 'trc_sed_medusa_sbc: dust.orca.nc closed'
-      ENDIF
-
+         !
+         CALL fld_read( kt, 1, sf_dust )
+         dust(:,:) = sf_dust(1)%fnow(:,:,1)
+         !
+      ELSE
+         dust(:,:) = 0.0
+      END IF
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('trc_sed_medusa_sbc')
+      !
    END SUBROUTINE trc_sed_medusa_sbc
 
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcsms_medusa.F90	(revision 6639)
@@ -21,4 +21,5 @@
    USE trcopt_medusa
    USE trcsed_medusa
+   USE trcavg_medusa
 
 
@@ -46,4 +47,9 @@
       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,*)
@@ -52,5 +58,15 @@
       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
@@ -60,6 +76,14 @@
 # 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
 
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trcadv.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trcsbc.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/TRP/trctrp.F90	(revision 6639)
@@ -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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/par_trc.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/par_trc.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/par_trc.F90	(revision 6639)
@@ -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
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trc.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trc.F90	(revision 6639)
@@ -104,4 +104,44 @@
    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,               &
+                  BASIN_01, BASIN_02, BASIN_03, BASIN_04, BASIN_05, BASIN_06, BASIN_07, BASIN_08,   &
+                  BASIN_09, BASIN_10, BASIN_11, BASIN_12, BASIN_13, BASIN_14, BASIN_15, BASIN_16,   &
+                  BASIN_17, BASIN_18, BASIN_19, BASIN_20, BASIN_21, BASIN_22, BASIN_23, BASIN_24,   &
+                  BASIN_25, BASIN_26, BASIN_27, BASIN_28, BASIN_29, BASIN_30, BASIN_31, BASIN_32,   &
+                  BASIN_33, BASIN_34, BASIN_35, BASIN_36, BASIN_37, BASIN_38, BASIN_39, BASIN_40,   &
+                  BASIN_41, BASIN_42, BASIN_43, BASIN_44, BASIN_45,                                 &
+                  INT_ZMI, INT_ZME, INT_DET, INT_DTC, DMS_SURF, DMS_ANDR, DMS_SIMO, DMS_ARAN,       &
+                  DMS_HALL,   &
+                  TPP3, DETFLUX3, REMIN3N, PH3, OM_CAL3      
+                  !! 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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcini.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcini.F90	(revision 6639)
@@ -103,9 +103,9 @@
 
       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_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
-      IF( lk_medusa  )       CALL trc_ini_medusa       ! MEDUSA  tracers
-      IF( lk_idtra   )       CALL trc_ini_idtra        ! Idealize tracers
 
       CALL trc_ice_ini                                 ! Tracers in sea ice
@@ -274,4 +274,8 @@
       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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcnam.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcnam.F90	(revision 6639)
@@ -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
@@ -56,5 +57,5 @@
       !! ** Method  : - read passive tracer namelist 
       !!              - read namelist of each defined SMS model
-      !!                ( (PISCES, CFC, MY_TRC )
+      !!                ( (PISCES, CFC, MY_TRC, MEDUSA, IDTRA )
       !!---------------------------------------------------------------------
       INTEGER  ::   jn, jk                     ! dummy loop indice
@@ -235,5 +236,5 @@
       IF (lwp) write (numout,*) '------------------------------'
       IF (lwp) write (numout,*) 'Jpalm - debug'
-      IF (lwp) write (numout,*) 'CALL trc_nam_pisces -- OK'
+      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,*) ' '
@@ -269,5 +270,14 @@
       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 - CALL trc_nam OK'
+      IF (lwp) write (numout,*) ' '
+# endif
+      !
       IF( lk_c14b     ) THEN   ;   CALL trc_nam_c14b         ! C14 bomb     tracers
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          C14 not used'
@@ -277,5 +287,5 @@
       ELSE                    ;   IF(lwp) WRITE(numout,*) '          MY_TRC not used'
       ENDIF
-      !
+       
       IF(lwp)   CALL flush(numout)
    END SUBROUTINE trc_nam
@@ -489,4 +499,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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcrst.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcrst.F90	(revision 6639)
@@ -27,4 +27,5 @@
    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
@@ -32,4 +33,13 @@
    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)
+
    IMPLICIT NONE
    PRIVATE
@@ -39,4 +49,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
@@ -52,4 +65,6 @@
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt       ! number of iteration
+      INTEGER             ::   iyear, imonth, iday
+      REAL (wp)           ::   zsec
       !
       CHARACTER(LEN=20)   ::   clkt     ! ocean time-step define as a character
@@ -82,7 +97,24 @@
       ! 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)) 
+            !!--------------------------------------------------------------------      
+            CALL ju2ymds( fjulday + (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
@@ -105,5 +137,5 @@
       !! ** purpose  :   read passive tracer fields in restart files
       !!----------------------------------------------------------------------
-      INTEGER  ::  jn     
+      INTEGER  ::  jn, jl     
       !! AXY (05/11/13): temporary variables
       REAL(wp) ::    fq0,fq1,fq2
@@ -118,10 +150,12 @@
       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
@@ -167,31 +201,95 @@
       !! 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
-#endif
- 
+      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
+      !!
+      !! 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')
+#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
@@ -205,5 +303,5 @@
       INTEGER, INTENT( in ) ::   kt    ! ocean time-step index
       !!
-      INTEGER  :: jn
+      INTEGER  :: jn, jl
       REAL(wp) :: zarak0
       !! AXY (05/11/13): temporary variables
@@ -248,32 +346,62 @@
       !! 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
-#endif
-
-      !
+      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(:,:)  )
+      !!
+      !! 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')
+      !! 
+#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
@@ -437,9 +565,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_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcsms.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcsms.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcsms.F90	(revision 6639)
@@ -45,4 +45,5 @@
       INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
       !!
+      INTEGER            ::  jn
       CHARACTER (len=25) :: charout
       !!---------------------------------------------------------------------
@@ -52,6 +53,18 @@
       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 --  continue -- '
+      CALL flush(numout)
+# endif
       IF( lk_c14b    )   CALL trc_sms_c14b   ( kt )    ! surface fluxes of C14
       IF( lk_my_trc  )   CALL trc_sms_my_trc ( kt )    ! MY_TRC  tracers
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcstp.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcstp.F90	(revision 6639)
@@ -92,4 +92,8 @@
 # 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
@@ -99,4 +103,6 @@
 # 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
@@ -104,4 +110,6 @@
 # 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
Index: branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcwri.F90
===================================================================
--- branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcwri.F90	(revision 6638)
+++ branches/UKMO/dev_r5518_RH_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcwri.F90	(revision 6639)
@@ -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
@@ -22,4 +23,5 @@
    USE trcwri_my_trc
    USE trcwri_medusa
+   USE trcwri_idtra
 
    IMPLICIT NONE
@@ -58,4 +60,7 @@
       ! ---------------------------------------
       IF( lk_pisces  )   CALL trc_wri_pisces     ! PISCES 
+      IF( lk_cfc     )   CALL trc_wri_cfc        ! surface fluxes of CFC
+      IF( lk_c14b    )   CALL trc_wri_c14b       ! surface fluxes of C14
+      IF( lk_my_trc  )   CALL trc_wri_my_trc     ! MY_TRC  tracers
       !
 # if defined key_debug_medusa
@@ -79,9 +84,14 @@
 # endif
       !
-      !!! JPALM
-      !!! don't forget to add idtra 
-      IF( lk_cfc     )   CALL trc_wri_cfc        ! surface fluxes of CFC
-      IF( lk_c14b    )   CALL trc_wri_c14b       ! surface fluxes of C14
-      IF( lk_my_trc  )   CALL trc_wri_my_trc     ! MY_TRC  tracers
+      IF( lk_idtra   )   CALL trc_wri_idtra       ! Idealize tracers
+      !
+# if defined key_debug_medusa
+      CALL flush(numout)
+      IF (lwp) write (numout,*) '------------------------------'
+      IF (lwp) write (numout,*) 'Jpalm - debug'
+      IF (lwp) write (numout,*) 'CALL trc_wri_idtra -- OK'
+      IF (lwp) write (numout,*) ' '
+      CALL flush(numout)
+# endif
       !
       IF( nn_timing == 1 )  CALL timing_stop('trc_wri')
