Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/C1D_PAPA/cpp_C1D_PAPA.fcm
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/C1D_PAPA/cpp_C1D_PAPA.fcm	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/C1D_PAPA/cpp_C1D_PAPA.fcm	(revision 13402)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys   key_c1d key_mpp_mpi key_iomput
+ bld::tool::fppkeys   key_c1d key_iomput
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/GYRE_PISCES/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/GYRE_PISCES/EXPREF/namelist_cfg	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/GYRE_PISCES/EXPREF/namelist_cfg	(revision 13402)
@@ -142,4 +142,8 @@
       rn_Ld        = 100.e+3        !  lateral diffusive length   [m]
 /
+!-----------------------------------------------------------------------
+&namtra_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
+/
 !!======================================================================
 !!                      ***  Dynamics namelists  ***                  !!
@@ -212,4 +216,12 @@
 !-----------------------------------------------------------------------
    nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to internal & intertial waves
+/
+!-----------------------------------------------------------------------
+&namzdf_osm    !   OSM vertical diffusion                               (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namosm_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
 /
 !!======================================================================
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 13402)
@@ -135,4 +135,8 @@
 /
 !-----------------------------------------------------------------------
+&namtra_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr =T)
 !-----------------------------------------------------------------------
@@ -377,4 +381,12 @@
 /
 !-----------------------------------------------------------------------
+&namzdf_osm    !   OSM vertical diffusion                               (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namosm_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
 &namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
 !-----------------------------------------------------------------------
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/domain_def_nemo.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/domain_def_nemo.xml	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/domain_def_nemo.xml	(revision 13402)
@@ -10,5 +10,20 @@
      </domain>
 
-     <!--   Eq section -->
+     <domain id="1point" domain_ref="grid_T" >
+       <zoom_domain ibegin="1" jbegin="1" ni="1" nj="1"/>
+     </domain>
+     <domain id="danger_T" domain_ref="grid_T" >
+       <zoom_domain id="danger_T"  ibegin="45" jbegin="196" ni="5" nj="5"/>
+     </domain>
+     <domain id="danger_U" domain_ref="grid_U" >
+       <zoom_domain id="danger_U"  ibegin="45" jbegin="196" ni="5" nj="5"/>
+     </domain>
+      <domain id="danger_V" domain_ref="grid_V" >
+       <zoom_domain id="danger_V"  ibegin="45" jbegin="196" ni="5" nj="5"/>
+     </domain>
+     <domain id="danger_W" domain_ref="grid_W" >
+       <zoom_domain id="danger_W"  ibegin="45" jbegin="196" ni="5" nj="5"/>
+    </domain>
+    <!--   Eq section -->
      <domain id="EqT" domain_ref="grid_T" > <zoom_domain id="EqT"/> </domain>
      <!--   TAO : see example above   -->
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/field_def_nemo-oce.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/field_def_nemo-oce.xml	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/field_def_nemo-oce.xml	(revision 13402)
@@ -197,41 +197,96 @@
 
       <field_group id="OSMOSIS_T" grid_ref="grid_T_2D">
+        <field id="hml"                 long_name="mixed layr depth"                         unit="m"       />
+        <field id="hbl"                 long_name="boundary layer depth"                     unit="m"       />
+        <field id="dh"                  long_name="Pycnocline thickness"                     unit=" m"      />
+        <field id="ibld"                long_name="index of boundary layer depth"            unit="#"       />
+        <field id="imld"                long_name="index of mixed layer depth"            unit="#"       />
+        <field id="zhbl"                long_name="boundary layer depth -grid"                     unit="m"       />
+        <field id="zhml"                long_name="mixed layer depth - grid"                        unit="m"       />
+        <field id="zdh"                 long_name="Pycnocline  depth - grid"                 unit=" m"      />
+        <field id="zustke"              long_name="magnitude of stokes drift  at T-points"   unit="m/s"     />
+        <field id="us_x"        long_name="i component of active Stokes drift"                      unit="m/s"     />
+        <field id="us_y"        long_name="j component of active Stokes drift"                      unit="m/s"     />
+        <field id="dstokes"             long_name="stokes drift  depth scale"                unit="m"       />
         <field id="zwth0"               long_name="surface non-local temperature flux"       unit="deg m/s" />
         <field id="zws0"                long_name="surface non-local salinity flux"          unit="psu m/s" />
-        <field id="hbl"                 long_name="boundary layer depth"                     unit="m"       />
-        <field id="hbli"                long_name="initial boundary layer depth"             unit="m"       />
-        <field id="dstokes"             long_name="stokes drift  depth scale"                unit="m"       />
-        <field id="zustke"              long_name="magnitude of stokes drift  at T-points"   unit="m/s"     />
         <field id="zwstrc"              long_name="convective velocity scale"                unit="m/s"     />
+        <field id="zustar"              long_name="friction velocity"                        unit="m/s"     />
         <field id="zwstrl"              long_name="langmuir velocity scale"                  unit="m/s"     />
-        <field id="zustar"              long_name="friction velocity"                        unit="m/s"     />
-        <field id="zhbl"                long_name="boundary layer depth"                     unit="m"       />
-        <field id="zhml"                long_name="mixed layer depth"                        unit="m"       />
+        <field id="zvstr"               long_name="mixed velocity scale"                     unit="m/s"     />
+        <field id="zla"                 long_name="langmuir number"                          unit="m/s"     />
         <field id="wind_wave_abs_power" long_name="\rho |U_s| x u*^2"                        unit="mW"      />
         <field id="wind_wave_power"     long_name="U_s \dot  tau"                            unit="mW"      />
         <field id="wind_power"          long_name="\rho  u*^3"                               unit="mW"      />
 
-        <!-- extra OSMOSIS diagnostics -->
+       <!-- interior BL OSMOSIS diagnostics -->
         <field id="zwthav"              long_name="av turb flux of T in ml"                  unit="deg m/s" />
         <field id="zt_ml"               long_name="av T in ml"                               unit="deg"     />
+        <field id="zhol"                long_name="Hoenekker number"                         unit="#"       />
+        <field id="zws_ent"            long_name="entrainment turb flux of S"                unit="10^-3 m/s" />
         <field id="zwth_ent"            long_name="entrainment turb flux of T"               unit="deg m/s" />
-        <field id="zhol"                long_name="Hoenekker number"                         unit="#"       />
-        <field id="zdh"                 long_name="Pycnocline  depth - grid"                 unit=" m"      />
-      </field_group>
-
-      <field_group id="OSMOSIS_W" grid_ref="grid_W_3D" operation="instant" >
+        <field id="zwb_ent"            long_name="entrainment turb flux of buoyancy"         unit="m^2/s^-3" />
+ 
+        <field id="zdt_bl"             long_name="temperature jump at base of BL"                 unit="deg"      />
+        <field id="zds_bl"             long_name="salinity jump at base of BL"                 unit="10^-3"      />
+        <field id="zdb_bl"             long_name="buoyancy jump at base of BL"                 unit="m/s^2"      />
+        <field id="zdu_bl"             long_name="u jump at base of BL"                       unit="m/s"      />
+        <field id="zdv_bl"             long_name="v jump at base of BL"                       unit="m/s"      />
+
+        <!-- extra OSMOSIS diagnostics for debugging -->
+       <field id="zsc_uw_1_0"       long_name="zsc u-momentum flux on T after Stokes"                       unit="m^2/s^2" />
+        <field id="zsc_uw_1_f"       long_name="zsc u-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zsc_vw_1_f"       long_name="zsc v-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zsc_uw_2_f"       long_name="2nd zsc u-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zsc_vw_2_f"       long_name="2nd zsc v-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zuw_bse"       long_name="base u-flux T-points"                          unit="m^2/s^2" />
+        <field id="zvw_bse"       long_name="base v-flux T-points"                          unit="m^2/s^2" />
+
+       <!-- FK_OSM OSMOSIS diagnostics (require also ln_osm_mle=.true.-->
+         <field id="hmle"          long_name="OBL FK-layer thickness"                                     unit="m"        />
+        <field id="mld_prof"              long_name="FK-layer depth index"                  unit="#" />
+        <field id="zmld"          long_name="target FK-layer thickness"                                     unit="m"        />
+        <field id="zwb_fk"          long_name="FK b-flux"                                     unit="m^2 s^-3"        />
+        <field id="zwb_fk_b"          long_name="layer averaged FK b-flux"                 unit="m^2 s^-3"       />
+        <field id="zdiff_mle"          long_name="max FK diffusivity in MLE"       unit=" 10^-4 m^2 s^-1"       />
+        <field id="zvel_mle"          long_name="FK velocity scale in MLE"       unit=" m s^-1"       />
+    </field_group>
+
+      <field_group id="OSMOSIS_W" grid_ref="grid_W_3D" >
+        <field id="zviscos"       long_name="BL viscosity"   unit="m^2/s" />
         <field id="ghamt"       long_name="non-local temperature flux"                       unit="deg m/s" />
         <field id="ghams"       long_name="non-local salinity flux"                          unit="psu m/s" />
         <field id="zdtdz_pyc"   long_name="Pycnocline temperature gradient"                  unit=" deg/m"  />
-      </field_group>
+        <field id="zdsdz_pyc"   long_name="Pycnocline salinity gradient"                  unit=" 10^-3/m"  />
+        <field id="zdbdz_pyc"   long_name="Pycnocline buoyancy gradient"                  unit=" s^-2"  />
+        <field id="zdudz_pyc"   long_name="Pycnocline u gradient"                  unit=" s^-2"  />
+        <field id="zdvdz_pyc"   long_name="Pycnocline v gradient"                  unit=" s^-2"  />
+
+        <!-- extra OSMOSIS diagnostics for debugging -->
+         <field id="ghamu_00"       long_name="initial non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_00"       long_name="initial non-local v-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamu_0"       long_name="after dstokes non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamu_f"       long_name="after Coriolis non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_f"       long_name="after Coriolis  non-local v-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamu_b"       long_name="after buoyancy added non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_b"       long_name="after buoyancy added  non-local v-momentum flux"  unit="m^2/s^2" />
+        <field id="ghamu_1"       long_name="after entrainment non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_1"       long_name="after entrainment  non-local v-momentum flux"  unit="m^2/s^2" />
+     </field_group>
 
       <field_group id="OSMOSIS_U" grid_ref="grid_U_2D" >
         <field id="ghamu"       long_name="non-local u-momentum flux"   grid_ref="grid_U_3D" unit="m^2/s^2" />
-        <field id="us_x"        long_name="i component of Stokes drift"                      unit="m/s"     />
-      </field_group>
+       <!-- FK_OSM OSMOSIS diagnostics (require also ln_osm_mle=.true.-->
+       <field id="zdtdx"          long_name="FK  T x-gradient"                                     unit=" deg C m^-1"        />
+        <field id="zdsdx"          long_name="FK  S x-gradient"                                     unit=" 10^-3 m^-1"        />
+        <field id="dbdx_mle"          long_name="FK  B x-gradient"                                     unit=" s^-2"        />
+     </field_group>
 
       <field_group id="OSMOSIS_V" grid_ref="grid_V_2D" >
         <field id="ghamv"       long_name="non-local v-momentum flux"   grid_ref="grid_V_3D" unit="m^2/s^2" />
-        <field id="us_y"        long_name="j component of Stokes drift"                      unit="m/s"     />
+        <!-- FK_OSM OSMOSIS diagnostics (require also ln_osm_mle=.true.-->
+        <field id="zdtdy"          long_name="FK T y-gradient"                                     unit=" deg C m^-1"        />
+        <field id="zdsdy"          long_name="FK S y-gradient"                                     unit=" 10^-3 m^-1"        />
+        <field id="dbdy_mle"          long_name="FK B y-gradient"                                     unit=" s^-2"        />
       </field_group>
       
@@ -245,6 +300,6 @@
           <field id="emp_oce"      long_name="Evap minus Precip over ocean"         standard_name="evap_minus_precip_over_sea_water"                                     unit="kg/m2/s"   />
           <field id="emp_ice"      long_name="Evap minus Precip over ice"           standard_name="evap_minus_precip_over_sea_ice"                                       unit="kg/m2/s"   />
-          <field id="saltflx"      long_name="Downward salt flux"                                                                                                        unit="1e-3/m2/s" />
-          <field id="fmmflx"       long_name="Water flux due to freezing/melting"                                                                                        unit="kg/m2/s"   />
+          <field id="saltflx"      long_name="Total downward salinity flux"             standard_name="total_downward_salinity_flux"                                   unit="1e-3/m2/s" />
+          <field id="fmmflx"       long_name="Water flux due to freezing/melting"     standard_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"   />
@@ -676,5 +731,10 @@
      <field id="strd_zdfp"     long_name="salinity   -trend: pure vert. diffusion"   unit="1e-3/s" />
 
-     <!-- -->
+     <!-- ln_zdfosm=T only (OSMOSIS-OBL) -->
+     <field id="ttrd_osm"      long_name="temperature-trend: OSM-OSBL non-local forcing"                             unit="degC/s" />
+     <field id="strd_osm"      long_name="salinity   -trend: OSM-OSBL non-local forcing"                             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" />
@@ -712,4 +772,8 @@
      <field id="strd_zdfp_e3t"     unit="1e-3/s * m"  >  strd_zdfp * e3t </field>
 
+          <!-- ln_zdfosm=T only (OSMOSIS-OBL) -->
+     <field id="ttrd_osm_e3t"      long_name="temperature-trend: OSM-OSBL non-local forcing"                             unit="degC/s * m" >  ttrd_osm * e3t </field>
+     <field id="strd_osm_e3t"      long_name="salinity   -trend: OSM-OSBL non-local forcing"                             unit="1e-3/s * m" >  strd_osm * e3t </field>
+     
      <!-- -->
      <field id="ttrd_dmp_e3t"      unit="degC/s * m"  >  ttrd_dmp * e3t </field>
@@ -720,13 +784,20 @@
      <field id="strd_npc_e3t"      unit="1e-3/s * m"  >  strd_npc * e3t </field>
      <field id="ttrd_qns_e3t"      unit="degC/s * m"  >  ttrd_qns * e3t_surf </field>
-     <field id="strd_cdt_e3t"      unit="degC/s * m"  >  strd_cdt * e3t_surf </field>
+     <!-- <field id="strd_cdt_e3t"      unit="degC/s * m"  >  strd_cdt * e3t_surf </field> -->
      <field id="ttrd_qsr_e3t"      unit="degC/s * m"  >  ttrd_qsr * e3t </field>
      <field id="ttrd_bbc_e3t"      unit="degC/s * m"  >  ttrd_bbc * e3t </field>
 
      <!-- OMIP  layer-integrated trends -->
+     <field id="sfd"      long_name="Total downward salt flux"                                                     unit="kg/(m^2 s)" > saltflux * 1026.0 * 0.001 </field>
+     <field id="wfo"      long_name="Total downward FW mass flux"                                                   unit="kg/(m^2 s)" > -empmr </field>
+
      <field id="ttrd_totad_li"    long_name="layer integrated heat-trend: total advection"         unit="W/m^2"     > ttrd_totad_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="strd_totad_li"    long_name="layer integrated salt-trend: total advection"         unit="kg/(m^2 s)"    > strd_totad_e3t * 1026.0 * 0.001  </field>
+     <field id="ttrd_osm_li"    long_name="layer integrated heat-trend: non-local OSM"         unit="W/m^2"     > ttrd_osm_e3t * 1026.0 * 3991.86795711963 </field>
+     <field id="strd_osm_li"    long_name="layer integrated salt-trend: non-local OSM"         unit="kg/(m^2 s)"    > strd_osm_e3t * 1026.0 * 0.001  </field>
      <field id="ttrd_evd_li"      long_name="layer integrated heat-trend: EVD convection"          unit="W/m^2"    > ttrd_evd_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="strd_evd_li"      long_name="layer integrated salt-trend: EVD convection"          unit="kg/(m^2 s)"  > strd_evd_e3t * 1026.0 * 0.001  </field>
+     <field id="ttrd_npc_li"      long_name="layer integrated heat-trend: NPC convection"          unit="W/m^2"    > ttrd_npc_e3t * 1026.0 * 3991.86795711963 </field>
+     <field id="strd_npc_li"      long_name="layer integrated salt-trend: NPC convection"          unit="kg/(m^2 s)"  > strd_npc_e3t * 1026.0 * 0.001  </field>
      <field id="ttrd_iso_li"      long_name="layer integrated heat-trend: isopycnal diffusion"     unit="W/m^2" > ttrd_iso_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="strd_iso_li"      long_name="layer integrated salt-trend: isopycnal diffusion"     unit="kg/(m^2 s)" > strd_iso_e3t * 1026.0 * 0.001  </field>
@@ -735,4 +806,5 @@
      <field id="ttrd_qns_li"      long_name="layer integrated heat-trend: non-solar flux + runoff" unit="W/m^2" grid_ref="grid_T_2D"> ttrd_qns_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="ttrd_qsr_li"      long_name="layer integrated heat-trend: solar flux"              unit="W/m^2"  grid_ref="grid_T_3D"> ttrd_qsr_e3t * 1026.0 * 3991.86795711963 </field>
+     <field id="ttrd_bbc_li"      long_name="layer integrated heat-trend: geothermal heating "  unit="W/m^2" > ttrd_bbc_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="ttrd_bbl_li"      long_name="layer integrated heat-trend: bottom boundary layer "  unit="W/m^2" > ttrd_bbl_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="strd_bbl_li"      long_name="layer integrated salt-trend: bottom boundary layer "  unit="kg/(m^2 s)" > strd_bbl_e3t * 1026.0 * 0.001  </field>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/field_def_nemo-waves.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/field_def_nemo-waves.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/field_def_nemo-waves.xml	(revision 13402)
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+
+   <field_definition level="1" prec="4" operation="average" enabled=".TRUE." default_value="1.e20" detect_missing_value="true"> <!-- time step automaticaly defined -->
+
+    <!-- 
+============================================================================================================
+                                  WAVE variables
+============================================================================================================
+    -->
+
+
+        <!-- WAVE  diagnostics -->
+      <field_group id="WAVE_T" grid_ref="grid_T_2D"  >
+	<field id="hsw"          long_name="significant wave height"                                     unit="m"        />
+	<field id="wmp"          long_name="wave mean period"                                     unit="s"        />
+	<field id="hsw_NP"          long_name="significant wave height from NP"                                     unit="m"        />
+	<field id="wmp_NP"          long_name="wave mean period from NP"                                     unit="s"        />
+ 	<field id="wndm"          long_name="U_10"                                                                         unit="m/s"        />
+       </field_group>
+  
+    </field_definition>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/grid_def_nemo.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/grid_def_nemo.xml	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/grid_def_nemo.xml	(revision 13402)
@@ -58,4 +58,11 @@
       </grid>
 
-    </grid_definition>
+        <!--  -->
+       <grid id="grid_T_SFC">
+         <domain domain_ref="grid_T" />
+         <scalar>
+           <extract_axis position="0" />
+         </scalar>
+       </grid>
+     </grid_definition>
     
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/namelist_ref
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/namelist_ref	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/SHARED/namelist_ref	(revision 13402)
@@ -257,4 +257,7 @@
    ln_COARE_3p5 = .false.   ! "COARE 3.5" algorithm   (Edson et al. 2013)
    ln_ECMWF    = .false.   ! "ECMWF"     algorithm   (IFS cycle 31)
+
+   ln_humi_dpt    = .false.   !  Supply dewpoint tempearture instead of specific humidity (is true for ERA5)
+
       !
       rn_zqt      = 10.       !  Air temperature & humidity reference height (m)
@@ -1086,5 +1089,5 @@
 &namzdf_osm    !   OSM vertical diffusion                               (ln_zdfosm =T)
 !-----------------------------------------------------------------------
-   ln_use_osm_la = .false.      !  Use namelist  rn_osm_la
+   ln_use_osm_la = .false.     !  Use   rn_osm_la
    rn_osm_la     = 0.3         !  Turbulent Langmuir number
    rn_osm_dstokes     = 5.     !  Depth scale of Stokes drift (m)
@@ -1101,4 +1104,17 @@
       !                        !  = 1: Pierson Moskowitz wave spectrum
       !                        !  = 0: Constant La# = 0.3
+   ln_osm_mle = .false.        !  Use integrated FK-OSM model
+/
+!-----------------------------------------------------------------------
+&namosm_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
+   rn_osm_mle_ce       = 0.06      ! magnitude of the MLE (typical value: 0.06 to 0.08)
+   nn_osm_mle          = 0         ! MLE type: =0 standard Fox-Kemper ; =1 new formulation
+   rn_osm_mle_lf       = 5.e+3     ! typical scale of mixed layer front (meters)                      (case rn_osm_mle=0)
+   rn_osm_mle_time     = 172800.   ! time scale for mixing momentum across the mixed layer (seconds)  (case rn_osm_mle=0)
+   rn_osm_mle_lat      = 20.       ! reference latitude (degrees) of MLE coef.                        (case rn_mle=1)
+   rn_osm_mle_rho_c =    0.01      ! delta rho criterion used to calculate MLD for FK
+   rn_osm_mle_thresh = 0.0005      ! delta b criterion used for FK MLD criterion
+   rn_osm_mle_tau     = 172800.   ! time scale for FK-OSM (seconds)  (case rn_osm_mle=0)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo.xml	(revision 13402)
@@ -0,0 +1,1 @@
+link context_nemo_1m.xml
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1d.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1d.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1d.xml	(revision 13402)
@@ -0,0 +1,54 @@
+<!--
+ ============================================================================================== 
+    NEMO context
+============================================================================================== 
+-->
+<context id="nemo">
+<!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
+<!-- Fields definition -->
+    <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     -->
+    <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      -->
+    <!-- <field_definition src="./field_def_nemo-pisces.xml"/>  <!-\-   NEMO ocean biology          -\-> -->
+    <field_definition src="./field_def_nemo-waves.xml"/>   <!--  NEMO ocean sea ice                      -->
+
+<!-- Files definition -->
+    <!-- <file_definition src="./file_def_nemo-oce.xml"/>     <!-\-  NEMO ocean dynamics      -\-> -->
+    <!-- <file_definition src="./file_def_nemo-ice.xml"/>     <!-\-  NEMO sea-ice model       -\-> -->
+    <!-- <file_definition src="./file_def_nemo-pisces.xml"/>  <!-\-  NEMO ocean biology       -\-> -->
+    <file_definition src="./file_def_1d.xml"/>
+    <!-- <file_definition src="./file_def_osmosis_my.xml"/> -->
+    <file_definition src="./file_def_osmosis_1d.xml"/> 
+    <file_definition src="./file_def_nemo-ice_1d.xml"/> 
+    <file_definition src="./file_def_waves_1d.xml"/>    <!-- 
+============================================================================================================
+= 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="-"                 />
+      <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_nemo.xml"/>
+  
+    <grid_definition src="./grid_def_nemo.xml"/>
+
+</context>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1m.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1m.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1m.xml	(revision 13402)
@@ -0,0 +1,54 @@
+<!--
+ ============================================================================================== 
+    NEMO context
+============================================================================================== 
+-->
+<context id="nemo">
+<!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
+<!-- Fields definition -->
+    <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     -->
+    <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      -->
+    <!-- <field_definition src="./field_def_nemo-pisces.xml"/>  <!-\-   NEMO ocean biology          -\-> -->
+    <field_definition src="./field_def_nemo-waves.xml"/>   <!--  NEMO ocean sea ice                      -->
+
+<!-- Files definition -->
+    <!-- <file_definition src="./file_def_nemo-oce.xml"/>     <!-\-  NEMO ocean dynamics      -\-> -->
+    <!-- <file_definition src="./file_def_nemo-ice.xml"/>     <!-\-  NEMO sea-ice model       -\-> -->
+    <!-- <file_definition src="./file_def_nemo-pisces.xml"/>  <!-\-  NEMO ocean biology       -\-> -->
+    <file_definition src="./file_def_1m.xml"/>
+    <!-- <file_definition src="./file_def_osmosis_my.xml"/> -->
+    <file_definition src="./file_def_osmosis_1m.xml"/> 
+    <file_definition src="./file_def_nemo-ice_1m.xml"/> 
+    <file_definition src="./file_def_waves_1m.xml"/>    <!-- 
+============================================================================================================
+= 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="-"                 />
+      <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_nemo.xml"/>
+  
+    <grid_definition src="./grid_def_nemo.xml"/>
+
+</context>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_1ts.xml	(revision 13402)
@@ -0,0 +1,53 @@
+<!--
+ ============================================================================================== 
+    NEMO context
+============================================================================================== 
+-->
+<context id="nemo">
+<!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
+<!-- Fields definition -->
+    <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     -->
+    <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      -->
+    <!-- <field_definition src="./field_def_nemo-pisces.xml"/>  <!-\-   NEMO ocean biology          -\-> -->
+    <field_definition src="./field_def_nemo-waves.xml"/>   <!--  NEMO ocean sea ice                      -->
+
+<!-- <!-\- Files definition -\-> -->
+<!--     <!-\- <file_definition src="./file_def_nemo-oce.xml"/>     <!-\\-  NEMO ocean dynamics      -\\-> -\-> -->
+<!--     <!-\- <file_definition src="./file_def_nemo-ice.xml"/>     <!-\\-  NEMO sea-ice model       -\\-> -\-> -->
+<!--     <!-\- <file_definition src="./file_def_nemo-pisces.xml"/>  <!-\\-  NEMO ocean biology       -\\-> -\-> -->
+     <file_definition src="./file_def_1ts.xml"/>
+     <file_definition src="./file_def_osmosis_1ts.xml"/>
+     <!-- <file_definition src="./file_def_nemo-ice_1ts.xml"/>  -->
+     <!-- <file_definition src="./file_def_waves_1ts.xml"/>  -->
+============================================================================================================
+= 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="-"                 />
+      <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_nemo.xml"/>
+  
+    <grid_definition src="./grid_def_nemo.xml"/>
+
+</context>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_danger_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_danger_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/context_nemo_danger_1ts.xml	(revision 13402)
@@ -0,0 +1,53 @@
+<!--
+ ============================================================================================== 
+    NEMO context
+============================================================================================== 
+-->
+<context id="nemo">
+<!-- $id$ -->
+    <variable_definition>
+    <!-- Year of time origin for NetCDF files; defaults to 1800 -->
+       <variable id="ref_year" type="int"   > 1800 </variable>
+       <variable id="rau0"     type="float" > 1026.0 </variable>
+       <variable id="cpocean"  type="float" > 3991.86795711963 </variable>
+       <variable id="convSpsu" type="float" > 0.99530670233846  </variable>
+       <variable id="rhoic"    type="float" > 917.0 </variable>
+       <variable id="rhosn"    type="float" > 330.0 </variable>
+       <variable id="missval"  type="float" > 1.e20 </variable>
+    </variable_definition>
+<!-- Fields definition -->
+    <field_definition src="./field_def_nemo-oce.xml"/>    <!--  NEMO ocean dynamics     -->
+    <field_definition src="./field_def_nemo-ice.xml"/>    <!--  NEMO sea-ice model      -->
+    <!-- <field_definition src="./field_def_nemo-pisces.xml"/>  <!-\-   NEMO ocean biology          -\-> -->
+    <field_definition src="./field_def_nemo-waves.xml"/>   <!--  NEMO ocean sea ice                      -->
+
+<!-- <!-\- Files definition -\-> -->
+<!--     <!-\- <file_definition src="./file_def_nemo-oce.xml"/>     <!-\\-  NEMO ocean dynamics      -\\-> -\-> -->
+<!--     <!-\- <file_definition src="./file_def_nemo-ice.xml"/>     <!-\\-  NEMO sea-ice model       -\\-> -\-> -->
+<!--     <!-\- <file_definition src="./file_def_nemo-pisces.xml"/>  <!-\\-  NEMO ocean biology       -\\-> -\-> -->
+     <file_definition src="./file_def_danger_1ts.xml"/>
+     <file_definition src="./file_def_osmosis_danger_1ts.xml"/>
+     <!-- <file_definition src="./file_def_nemo-ice_1ts.xml"/>  -->
+     <!-- <file_definition src="./file_def_waves_1ts.xml"/>  -->
+============================================================================================================
+= 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="-"                 />
+      <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_nemo.xml"/>
+  
+    <grid_definition src="./grid_def_nemo.xml"/>
+
+</context>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1d.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1d.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1d.xml	(revision 13402)
@@ -0,0 +1,80 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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="1d" output_freq="1d"  output_level="10" enabled=".TRUE."> <!-- 1d files -->
+
+	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+	  <field field_ref="toce"         name="votemper"  />
+	  <field field_ref="soce"         name="vosaline"  />
+	  <field field_ref="sst"          name="sosstsst"  />
+	  <field field_ref="sss"          name="sosaline"  />
+	  <field field_ref="ssh"          name="sossheig"  />
+	  <field field_ref="empmr"        name="sowaflup"  />
+	  <field field_ref="qsr"          name="soshfldo"  />
+	  <field field_ref="saltflx"      name="sosfldow"  />
+          <field field_ref="fmmflx"       name="soffldow"  />
+	  <field field_ref="qt"           name="sohefldo"  />
+	  <field field_ref="mldr10_1"     name="somxl010"  />
+	  <field field_ref="mldkz5"       name="somixhgt"  />
+	  <field field_ref="pycndep"       name="pycndep"  />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal"  /> -->
+	</file>
+	
+	<file id="file2" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field field_ref="uoce"         name="vozocrtx"  />
+          <field field_ref="utau"         name="sozotaux"  />
+          <!-- <field field_ref="us_x"          name="ustokes0"     /> -->
+          <field field_ref="ahtu_2d"        name="soleahtu" />
+          <!-- <field field_ref="ustokes"        name="ustokes" /> -->
+	</file>
+	
+	<file id="file3" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field field_ref="voce"         name="vomecrty"  /> 
+          <field field_ref="vtau"         name="sometauy"  /> 
+	  <!-- <field field_ref="e3v"         name="e3v" /> -->
+          <field field_ref="ahtv_2d"        name="soleahtv" />
+         <!-- <field field_ref="vstokes"        name="vstokes" /> -->
+	</file>
+	
+	<file id="file4" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field field_ref="woce"         name="vovecrtz" />
+          <field field_ref="avt"          name="votkeavt" />
+          <field field_ref="avm"          name="votkeavm" />
+           <!-- <field field_ref="wstokes"        name="wstokes" /> -->
+	</file>
+
+
+      </file_group>
+  
+      <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_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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1m.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1m.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1m.xml	(revision 13402)
@@ -0,0 +1,80 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
+
+	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+	  <field field_ref="toce"         name="votemper"  />
+	  <field field_ref="soce"         name="vosaline"  />
+	  <field field_ref="sst"          name="sosstsst"  />
+	  <field field_ref="sss"          name="sosaline"  />
+	  <field field_ref="ssh"          name="sossheig"  />
+	  <field field_ref="empmr"        name="sowaflup"  />
+	  <field field_ref="qsr"          name="soshfldo"  />
+	  <field field_ref="saltflx"      name="sosfldow"  />
+          <field field_ref="fmmflx"       name="soffldow"  />
+	  <field field_ref="qt"           name="sohefldo"  />
+	  <field field_ref="mldr10_1"     name="somxl010"  />
+	  <field field_ref="mldkz5"       name="somixhgt"  />
+	  <field field_ref="pycndep"       name="pycndep"  />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal"  /> -->
+	</file>
+	
+	<file id="file2" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field field_ref="uoce"         name="vozocrtx"  />
+          <field field_ref="utau"         name="sozotaux"  />
+          <!-- <field field_ref="us_x"          name="ustokes0"     /> -->
+          <field field_ref="ahtu_2d"        name="soleahtu" />
+          <!-- <field field_ref="ustokes"        name="ustokes" /> -->
+	</file>
+	
+	<file id="file3" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field field_ref="voce"         name="vomecrty"  /> 
+          <field field_ref="vtau"         name="sometauy"  /> 
+	  <!-- <field field_ref="e3v"         name="e3v" /> -->
+          <field field_ref="ahtv_2d"        name="soleahtv" />
+         <!-- <field field_ref="vstokes"        name="vstokes" /> -->
+	</file>
+	
+	<file id="file4" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field field_ref="woce"         name="vovecrtz" />
+          <field field_ref="avt"          name="votkeavt" />
+          <field field_ref="avm"          name="votkeavm" />
+           <!-- <field field_ref="wstokes"        name="wstokes" /> -->
+	</file>
+
+
+      </file_group>
+  
+      <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="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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_1ts.xml	(revision 13402)
@@ -0,0 +1,78 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" min_digits="4">
+    
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+
+	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+	  <field field_ref="toce"         name="votemper"  />
+	  <field field_ref="soce"         name="vosaline"  />
+	  <field field_ref="sst"          name="sosstsst"  />
+	  <field field_ref="sss"          name="sosaline"  />
+	  <field field_ref="ssh"          name="sossheig"  />
+	  <field field_ref="empmr"        name="sowaflup"  />
+	  <field field_ref="qsr"          name="soshfldo"  />
+	  <field field_ref="saltflx"      name="sosfldow"  />
+	  <field field_ref="qt"           name="sohefldo"  />
+	  <field field_ref="mldr10_1"     name="somxl010"  />
+	  <field field_ref="mldkz5"       name="somixhgt"  />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal"  /> -->
+	</file>
+	
+	<file id="file2" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field field_ref="uoce"         name="vozocrtx"  />
+          <field field_ref="utau"         name="sozotaux"  />
+          <field field_ref="us_x"          name="ustokes0"     />
+          <field field_ref="ahtu_2d"        name="soleahtu" />
+          <!-- <field field_ref="ustokes"        name="ustokes" /> -->
+	</file>
+	
+	<file id="file3" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field field_ref="voce"         name="vomecrty"  /> 
+          <field field_ref="vtau"         name="sometauy"  /> 
+	  <field field_ref="e3v"         name="e3v" />
+          <field field_ref="ahtv_2d"        name="soleahtv" />
+         <!-- <field field_ref="vstokes"        name="vstokes" /> -->
+	</file>
+	
+	<file id="file4" name_suffix="_grid_W" description="ocean W grid variables" >
+          <field field_ref="woce"         name="vovecrtz" />
+          <field field_ref="avt"          name="votkeavt" />
+          <field field_ref="avm"          name="votkeavm" />
+           <!-- <field field_ref="wstokes"        name="wstokes" /> -->
+	</file>
+
+
+      </file_group>
+  
+      <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_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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_danger_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_danger_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_danger_1ts.xml	(revision 13402)
@@ -0,0 +1,77 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1ts" min_digits="4">
+    
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+
+	<file id="file71" name_suffix="_danger_T" description="ocean T grid variables" >
+	  <field field_ref="toce"         name="votemper"  grid_ref="danger_T_3D"   />
+	  <field field_ref="soce"         name="vosaline"   grid_ref="danger_T_3D"   />
+	  <field field_ref="sst"          name="sosstsst"  grid_ref="danger_T_2D"   />
+	  <field field_ref="sss"          name="sosaline"  grid_ref="danger_T_2D"   />
+	  <field field_ref="ssh"          name="sossheig"  grid_ref="danger_T_2D"   />
+	  <field field_ref="empmr"        name="sowaflup"  grid_ref="danger_T_2D"   />
+	  <field field_ref="qsr"          name="soshfldo"  grid_ref="danger_T_2D"   />
+	  <field field_ref="saltflx"      name="sosfldow"  grid_ref="danger_T_2D"   />
+	  <field field_ref="qt"           name="sohefldo"  grid_ref="danger_T_2D"   />
+	  <field field_ref="mldr10_1"     name="somxl010"  grid_ref="danger_T_2D"   />
+	  <field field_ref="mldkz5"       name="somixhgt"  grid_ref="danger_T_2D"   />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal"  /> -->
+	</file>
+	
+	<file id="file72" name_suffix="_danger_U" description="ocean U grid variables" >
+          <field field_ref="uoce"         name="vozocrtx"   grid_ref="danger_U_3D"   />
+          <field field_ref="utau"         name="sozotaux"  grid_ref="danger_U_2D"   />
+           <field field_ref="ahtu_2d"        name="soleahtu" grid_ref="danger_U_2D"  />
+          <!-- <field field_ref="ustokes"        name="ustokes" /> -->
+	</file>
+	
+	<file id="file73" name_suffix="_danger_V" description="ocean V grid variables" >
+          <field field_ref="voce"         name="vomecrty"   grid_ref="danger_V_3D"   /> 
+          <field field_ref="vtau"         name="sometauy"  grid_ref="danger_V_2D"  /> 
+	  <field field_ref="e3v"         name="e3v"  grid_ref="danger_V_3D"   />
+          <field field_ref="ahtv_2d"        name="soleahtv" grid_ref="danger_V_2D"  />
+         <!-- <field field_ref="vstokes"        name="vstokes" /> -->
+	</file>
+	
+	<file id="file74" name_suffix="_danger_W" description="ocean W grid variables" >
+          <field field_ref="woce"         name="vovecrtz"  grid_ref="danger_W_3D"   />
+          <field field_ref="avt"          name="votkeavt"  grid_ref="danger_W_3D"   />
+          <field field_ref="avm"          name="votkeavm" grid_ref="danger_W_3D"   />
+           <!-- <field field_ref="wstokes"        name="wstokes" /> -->
+	</file>
+
+
+      </file_group>
+  
+      <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_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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1d.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1d.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1d.xml	(revision 13402)
@@ -0,0 +1,139 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+ <!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                      Define your own files for sea ice                                   =
+=                                         put the variables you want...                                    =
+============================================================================================================
+ -->
+    
+ <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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."> <!-- 1d files -->        
+     <file id="file21" name_suffix="_icemod" description="ice variables" enabled=".true." >
+
+       <!-- ice mask -->
+       <field field_ref="icemask"          name="simsk"   />
+       <field field_ref="icemask05"        name="simsk05" />
+       <field field_ref="icemask15"        name="simsk15" />
+       
+       <!-- general -->
+       <field field_ref="snwvolu"          name="snvolu" />
+       <field field_ref="icethic"          name="sithic" />
+       <field field_ref="icevolu"          name="sivolu" />
+       <field field_ref="iceconc"          name="siconc" />
+       <field field_ref="icesalt"          name="sisali" />
+       <field field_ref="iceapnd"          name="siapnd" />
+       <field field_ref="icevpnd"          name="sivpnd" />
+       <field field_ref="sst_m"            name="sst_m"  />
+       <field field_ref="sss_m"            name="sss_m"  />
+       
+       <!-- heat -->
+       <field field_ref="icetemp"          name="sitemp" />
+       <field field_ref="snwtemp"          name="sntemp" />
+       <field field_ref="icettop"          name="sittop" />
+       <field field_ref="icetbot"          name="sitbot" />
+       <field field_ref="icetsni"          name="sitsni" />
+       
+       <!-- momentum -->
+       <field field_ref="uice"             name="sivelu"  />
+       <field field_ref="vice"             name="sivelv"  />
+       <field field_ref="icevel"           name="sivelo"  />
+       <field field_ref="utau_ai"          name="utau_ai" />
+       <field field_ref="vtau_ai"          name="vtau_ai" />
+       <field field_ref="utau_oi"          name="utau_oi" />
+       <field field_ref="vtau_oi"          name="vtau_oi" />
+       
+       <!-- rheology -->
+       <field field_ref="icediv"           name="sidive"  />
+       <field field_ref="iceshe"           name="sishea"  />
+       <field field_ref="icestr"           name="sistre"  />
+       <field field_ref="normstr"          name="normstr" />
+       <field field_ref="sheastr"          name="sheastr" />
+       <field field_ref="isig1"            name="isig1"   />
+       <field field_ref="isig2"            name="isig2"   />
+       <field field_ref="isig3"            name="isig3"   />
+       
+       <!-- heat fluxes -->
+       <field field_ref="qt_oce_ai"        name="qt_oce_ai"  />
+       <field field_ref="qt_atm_oi"        name="qt_atm_oi"  />
+       <field field_ref="qtr_ice_top"      name="qtr_ice_top"/>
+       <field field_ref="qtr_ice_bot"      name="qtr_ice_bot"/>
+       <field field_ref="qt_ice"           name="qt_ice"     />
+       <field field_ref="qsr_ice"          name="qsr_ice"    />
+       <field field_ref="qns_ice"          name="qns_ice"    />
+       <field field_ref="qemp_ice"         name="qemp_ice"   />
+       <field field_ref="albedo"           name="albedo"     />
+       
+       <field field_ref="hfxcndtop"        name="hfxcndtop"  />
+       <field field_ref="hfxcndbot"        name="hfxcndbot"  />
+       <field field_ref="hfxsensib"        name="hfxsensib"  />
+       
+       <!-- salt fluxes -->
+       <field field_ref="sfxice"           name="sfxice" />
+       
+       <!-- mass fluxes -->
+       <field field_ref="vfxice"           name="vfxice" />
+       <field field_ref="vfxsnw"           name="vfxsnw" />
+       
+       <!-- categories -->
+       <field field_ref="icemask_cat"      name="simskcat"/>
+       <field field_ref="snwthic_cat"      name="snthicat"/>
+       <field field_ref="iceconc_cat"      name="siconcat"/>
+       <field field_ref="icethic_cat"      name="sithicat"/>
+       <field field_ref="icesalt_cat"      name="sisalcat"/>
+       <field field_ref="icetemp_cat"      name="sitemcat"/>
+       <field field_ref="snwtemp_cat"      name="sntemcat"/>
+       <field field_ref="icettop_cat"      name="sitopcat"/>
+
+      </file>
+     
+      <file id="file22" name_suffix="_SBC_scalar" description="scalar variables" enabled=".true." >
+       <!-- global contents -->
+       <field field_ref="ibgvol_tot"     grid_ref="grid_1point"   name="ibgvol_tot"   />
+       <field field_ref="sbgvol_tot"     grid_ref="grid_1point"   name="sbgvol_tot"   />
+       <field field_ref="ibgarea_tot"    grid_ref="grid_1point"   name="ibgarea_tot"  />
+       <field field_ref="ibgsalt_tot"    grid_ref="grid_1point"   name="ibgsalt_tot"  />
+       <field field_ref="ibgheat_tot"    grid_ref="grid_1point"   name="ibgheat_tot"  />
+       <field field_ref="sbgheat_tot"    grid_ref="grid_1point"   name="sbgheat_tot"  />
+       
+       <!-- global drifts (conservation checks) -->
+       <field field_ref="ibgvolume"      grid_ref="grid_1point"   name="ibgvolume"    />
+       <field field_ref="ibgsaltco"      grid_ref="grid_1point"   name="ibgsaltco"    />
+       <field field_ref="ibgheatco"      grid_ref="grid_1point"   name="ibgheatco"    />
+       <field field_ref="ibgheatfx"      grid_ref="grid_1point"   name="ibgheatfx"    />
+       
+       <!-- global forcings  -->
+       <field field_ref="ibgfrcvoltop"   grid_ref="grid_1point"   name="ibgfrcvoltop" />
+       <field field_ref="ibgfrcvolbot"   grid_ref="grid_1point"   name="ibgfrcvolbot" />
+       <field field_ref="ibgfrctemtop"   grid_ref="grid_1point"   name="ibgfrctemtop" />
+       <field field_ref="ibgfrctembot"   grid_ref="grid_1point"   name="ibgfrctembot" />
+       <field field_ref="ibgfrcsal"      grid_ref="grid_1point"   name="ibgfrcsal"    />
+       <field field_ref="ibgfrchfxtop"   grid_ref="grid_1point"   name="ibgfrchfxtop" />
+       <field field_ref="ibgfrchfxbot"   grid_ref="grid_1point"   name="ibgfrchfxbot" />
+     </file>
+     
+   </file_group>
+   
+ 
+   <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_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>
+ 
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1m.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1m.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1m.xml	(revision 13402)
@@ -0,0 +1,139 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+ <!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                      Define your own files for sea ice                                   =
+=                                         put the variables you want...                                    =
+============================================================================================================
+ -->
+    
+ <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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."/> <!-- 1d files -->        
+   <file_group id="1m"  output_freq="1mo" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
+     <file id="file21" name_suffix="_icemod" description="ice variables" enabled=".true." >
+
+       <!-- ice mask -->
+       <field field_ref="icemask"          name="simsk"   />
+       <field field_ref="icemask05"        name="simsk05" />
+       <field field_ref="icemask15"        name="simsk15" />
+       
+       <!-- general -->
+       <field field_ref="snwvolu"          name="snvolu" />
+       <field field_ref="icethic"          name="sithic" />
+       <field field_ref="icevolu"          name="sivolu" />
+       <field field_ref="iceconc"          name="siconc" />
+       <field field_ref="icesalt"          name="sisali" />
+       <field field_ref="iceapnd"          name="siapnd" />
+       <field field_ref="icevpnd"          name="sivpnd" />
+       <field field_ref="sst_m"            name="sst_m"  />
+       <field field_ref="sss_m"            name="sss_m"  />
+       
+       <!-- heat -->
+       <field field_ref="icetemp"          name="sitemp" />
+       <field field_ref="snwtemp"          name="sntemp" />
+       <field field_ref="icettop"          name="sittop" />
+       <field field_ref="icetbot"          name="sitbot" />
+       <field field_ref="icetsni"          name="sitsni" />
+       
+       <!-- momentum -->
+       <field field_ref="uice"             name="sivelu"  />
+       <field field_ref="vice"             name="sivelv"  />
+       <field field_ref="icevel"           name="sivelo"  />
+       <field field_ref="utau_ai"          name="utau_ai" />
+       <field field_ref="vtau_ai"          name="vtau_ai" />
+       <field field_ref="utau_oi"          name="utau_oi" />
+       <field field_ref="vtau_oi"          name="vtau_oi" />
+       
+       <!-- rheology -->
+       <field field_ref="icediv"           name="sidive"  />
+       <field field_ref="iceshe"           name="sishea"  />
+       <field field_ref="icestr"           name="sistre"  />
+       <field field_ref="normstr"          name="normstr" />
+       <field field_ref="sheastr"          name="sheastr" />
+       <field field_ref="isig1"            name="isig1"   />
+       <field field_ref="isig2"            name="isig2"   />
+       <field field_ref="isig3"            name="isig3"   />
+       
+       <!-- heat fluxes -->
+       <field field_ref="qt_oce_ai"        name="qt_oce_ai"  />
+       <field field_ref="qt_atm_oi"        name="qt_atm_oi"  />
+       <field field_ref="qtr_ice_top"      name="qtr_ice_top"/>
+       <field field_ref="qtr_ice_bot"      name="qtr_ice_bot"/>
+       <field field_ref="qt_ice"           name="qt_ice"     />
+       <field field_ref="qsr_ice"          name="qsr_ice"    />
+       <field field_ref="qns_ice"          name="qns_ice"    />
+       <field field_ref="qemp_ice"         name="qemp_ice"   />
+       <field field_ref="albedo"           name="albedo"     />
+       
+       <field field_ref="hfxcndtop"        name="hfxcndtop"  />
+       <field field_ref="hfxcndbot"        name="hfxcndbot"  />
+       <field field_ref="hfxsensib"        name="hfxsensib"  />
+       
+       <!-- salt fluxes -->
+       <field field_ref="sfxice"           name="sfxice" />
+       
+       <!-- mass fluxes -->
+       <field field_ref="vfxice"           name="vfxice" />
+       <field field_ref="vfxsnw"           name="vfxsnw" />
+       
+       <!-- categories -->
+       <field field_ref="icemask_cat"      name="simskcat"/>
+       <field field_ref="snwthic_cat"      name="snthicat"/>
+       <field field_ref="iceconc_cat"      name="siconcat"/>
+       <field field_ref="icethic_cat"      name="sithicat"/>
+       <field field_ref="icesalt_cat"      name="sisalcat"/>
+       <field field_ref="icetemp_cat"      name="sitemcat"/>
+       <field field_ref="snwtemp_cat"      name="sntemcat"/>
+       <field field_ref="icettop_cat"      name="sitopcat"/>
+
+      </file>
+     
+      <file id="file22" name_suffix="_SBC_scalar" description="scalar variables" enabled=".true." >
+       <!-- global contents -->
+       <field field_ref="ibgvol_tot"     name="ibgvol_tot"   />
+       <field field_ref="sbgvol_tot"     name="sbgvol_tot"   />
+       <field field_ref="ibgarea_tot"    name="ibgarea_tot"  />
+       <field field_ref="ibgsalt_tot"    name="ibgsalt_tot"  />
+       <field field_ref="ibgheat_tot"    name="ibgheat_tot"  />
+       <field field_ref="sbgheat_tot"    name="sbgheat_tot"  />
+       
+       <!-- global drifts (conservation checks) -->
+       <field field_ref="ibgvolume"      name="ibgvolume"    />
+       <field field_ref="ibgsaltco"      name="ibgsaltco"    />
+       <field field_ref="ibgheatco"      name="ibgheatco"    />
+       <field field_ref="ibgheatfx"      name="ibgheatfx"    />
+       
+       <!-- global forcings  -->
+       <field field_ref="ibgfrcvoltop"   name="ibgfrcvoltop" />
+       <field field_ref="ibgfrcvolbot"   name="ibgfrcvolbot" />
+       <field field_ref="ibgfrctemtop"   name="ibgfrctemtop" />
+       <field field_ref="ibgfrctembot"   name="ibgfrctembot" />
+       <field field_ref="ibgfrcsal"      name="ibgfrcsal"    />
+       <field field_ref="ibgfrchfxtop"   name="ibgfrchfxtop" />
+       <field field_ref="ibgfrchfxbot"   name="ibgfrchfxbot" />
+     </file>
+     
+   </file_group>
+   
+ 
+   <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->   	
+   <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>
+ 
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_nemo-ice_1ts.xml	(revision 13402)
@@ -0,0 +1,138 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+ <!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                      Define your own files for sea ice                                   =
+=                                         put the variables you want...                                    =
+============================================================================================================
+ -->
+    
+ <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1ts" min_digits="4">
+   
+   <file_group id="1ts" output_freq="1ts" output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+      <file id="file21" name_suffix="_icemod" description="ice variables" enabled=".true." >
+
+       <!-- ice mask -->
+       <field field_ref="icemask"          name="simsk"   />
+       <field field_ref="icemask05"        name="simsk05" />
+       <field field_ref="icemask15"        name="simsk15" />
+       
+       <!-- general -->
+       <field field_ref="snwvolu"          name="snvolu" />
+       <field field_ref="icethic"          name="sithic" />
+       <field field_ref="icevolu"          name="sivolu" />
+       <field field_ref="iceconc"          name="siconc" />
+       <field field_ref="icesalt"          name="sisali" />
+       <field field_ref="iceapnd"          name="siapnd" />
+       <field field_ref="icevpnd"          name="sivpnd" />
+       <field field_ref="sst_m"            name="sst_m"  />
+       <field field_ref="sss_m"            name="sss_m"  />
+       
+       <!-- heat -->
+       <field field_ref="icetemp"          name="sitemp" />
+       <field field_ref="snwtemp"          name="sntemp" />
+       <field field_ref="icettop"          name="sittop" />
+       <field field_ref="icetbot"          name="sitbot" />
+       <field field_ref="icetsni"          name="sitsni" />
+       
+       <!-- momentum -->
+       <field field_ref="uice"             name="sivelu"  />
+       <field field_ref="vice"             name="sivelv"  />
+       <field field_ref="icevel"           name="sivelo"  />
+       <field field_ref="utau_ai"          name="utau_ai" />
+       <field field_ref="vtau_ai"          name="vtau_ai" />
+       <field field_ref="utau_oi"          name="utau_oi" />
+       <field field_ref="vtau_oi"          name="vtau_oi" />
+       
+       <!-- rheology -->
+       <field field_ref="icediv"           name="sidive"  />
+       <field field_ref="iceshe"           name="sishea"  />
+       <field field_ref="icestr"           name="sistre"  />
+       <field field_ref="normstr"          name="normstr" />
+       <field field_ref="sheastr"          name="sheastr" />
+       <field field_ref="isig1"            name="isig1"   />
+       <field field_ref="isig2"            name="isig2"   />
+       <field field_ref="isig3"            name="isig3"   />
+       
+       <!-- heat fluxes -->
+       <field field_ref="qt_oce_ai"        name="qt_oce_ai"  />
+       <field field_ref="qt_atm_oi"        name="qt_atm_oi"  />
+       <field field_ref="qtr_ice_top"      name="qtr_ice_top"/>
+       <field field_ref="qtr_ice_bot"      name="qtr_ice_bot"/>
+       <field field_ref="qt_ice"           name="qt_ice"     />
+       <field field_ref="qsr_ice"          name="qsr_ice"    />
+       <field field_ref="qns_ice"          name="qns_ice"    />
+       <field field_ref="qemp_ice"         name="qemp_ice"   />
+       <field field_ref="albedo"           name="albedo"     />
+       
+       <field field_ref="hfxcndtop"        name="hfxcndtop"  />
+       <field field_ref="hfxcndbot"        name="hfxcndbot"  />
+       <field field_ref="hfxsensib"        name="hfxsensib"  />
+       
+       <!-- salt fluxes -->
+       <field field_ref="sfxice"           name="sfxice" />
+       
+       <!-- mass fluxes -->
+       <field field_ref="vfxice"           name="vfxice" />
+       <field field_ref="vfxsnw"           name="vfxsnw" />
+       
+       <!-- categories -->
+       <field field_ref="icemask_cat"      name="simskcat"/>
+       <field field_ref="snwthic_cat"      name="snthicat"/>
+       <field field_ref="iceconc_cat"      name="siconcat"/>
+       <field field_ref="icethic_cat"      name="sithicat"/>
+       <field field_ref="icesalt_cat"      name="sisalcat"/>
+       <field field_ref="icetemp_cat"      name="sitemcat"/>
+       <field field_ref="snwtemp_cat"      name="sntemcat"/>
+       <field field_ref="icettop_cat"      name="sitopcat"/>
+
+      </file>
+     
+      <file id="file22" name_suffix="_SBC_scalar" description="scalar variables" enabled=".true." >
+       <!-- global contents -->
+       <field field_ref="ibgvol_tot"     grid_ref="grid_1point"   name="ibgvol_tot"   />
+       <field field_ref="sbgvol_tot"     grid_ref="grid_1point"   name="sbgvol_tot"   />
+       <field field_ref="ibgarea_tot"    grid_ref="grid_1point"   name="ibgarea_tot"  />
+       <field field_ref="ibgsalt_tot"    grid_ref="grid_1point"   name="ibgsalt_tot"  />
+       <field field_ref="ibgheat_tot"    grid_ref="grid_1point"   name="ibgheat_tot"  />
+       <field field_ref="sbgheat_tot"    grid_ref="grid_1point"   name="sbgheat_tot"  />
+       
+       <!-- global drifts (conservation checks) -->
+       <field field_ref="ibgvolume"      grid_ref="grid_1point"   name="ibgvolume"    />
+       <field field_ref="ibgsaltco"      grid_ref="grid_1point"   name="ibgsaltco"    />
+       <field field_ref="ibgheatco"      grid_ref="grid_1point"   name="ibgheatco"    />
+       <field field_ref="ibgheatfx"      grid_ref="grid_1point"   name="ibgheatfx"    />
+       
+       <!-- global forcings  -->
+       <field field_ref="ibgfrcvoltop"   grid_ref="grid_1point"   name="ibgfrcvoltop" />
+       <field field_ref="ibgfrcvolbot"   grid_ref="grid_1point"   name="ibgfrcvolbot" />
+       <field field_ref="ibgfrctemtop"   grid_ref="grid_1point"   name="ibgfrctemtop" />
+       <field field_ref="ibgfrctembot"   grid_ref="grid_1point"   name="ibgfrctembot" />
+       <field field_ref="ibgfrcsal"      grid_ref="grid_1point"   name="ibgfrcsal"    />
+       <field field_ref="ibgfrchfxtop"   grid_ref="grid_1point"   name="ibgfrchfxtop" />
+       <field field_ref="ibgfrchfxbot"   grid_ref="grid_1point"   name="ibgfrchfxbot" />
+     </file>
+     
+   </file_group>
+   
+ 
+   <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="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_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>
+ 
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1d.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1d.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1d.xml	(revision 13402)
@@ -0,0 +1,120 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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="1d" output_freq="1d"  output_level="10" enabled=".TRUE."> <!-- 1d files -->
+ 	<file id="file30" name_suffix="_grid_TO" description="osmosis T grid variables">
+          <field field_ref="e3t"          name="e3t"     />
+          <field field_ref="ghamt"          name="ghamt"     />
+          <field field_ref="ghams"          name="ghams"    />
+          <field field_ref="zwth0"          name="zwth0"  />
+          <field field_ref="zws0"          name="zws0" />
+          <field field_ref="hbl"          name="hbl"  />
+          <field field_ref="ibld"          name="ibld"  />
+          <field field_ref="imld"          name="imld"  />
+           <field field_ref="hml"          name= "hml"     />
+          <field field_ref="dh"          name= "dh"     />
+          <field field_ref="utau"          name="tauuo"   />
+          <field field_ref="vtau"          name="tauvo"   />
+          <field field_ref="dstokes"          name="dstokes"   />
+          <field field_ref="zustke"          name="zustke"   />
+          <field field_ref="zwstrc"          name="zwstrc"  />
+          <field field_ref="zwstrl"          name="zwstrl"  />
+          <field field_ref="zla"          name="zla"  />
+          <field field_ref="zustar"          name="zustar"  />
+          <field field_ref="zvstr"          name="zvstr"  />
+          <field field_ref="zhbl"          name="zhbl"    />
+          <field field_ref="zhml"          name="zhml"    />
+          <field field_ref="zwthav"          name= "zwthav"     />
+          <field field_ref="zt_ml"          name= "zt_ml"     />
+          <field field_ref="zdt_bl"          name= "zdt_bml"     />
+          <field field_ref="zds_bl"          name= "zds_bml"     />
+          <field field_ref="zdb_bl"          name= "zdb_bml"     />
+          <field field_ref="zdu_bl"          name= "zdu_bml"     />
+          <field field_ref="zdv_bl"          name= "zdv_bml"     />
+          <field field_ref="zwth_ent"          name= "zwth_ent"     />
+          <field field_ref="zws_ent"          name= "zws_ent"     />
+          <field field_ref="zwb_ent"          name= "zwb_ent"     />
+          <field field_ref="zhol"          name= "zhol"     />
+          <field field_ref="zdh"          name= "zdh"     />
+          <field field_ref="zdtdz_pyc"          name= "zdtdz_pyc"     />
+          <field field_ref="zdsdz_pyc"          name= "zdsdz_pyc"     />
+          <field field_ref="zdbdz_pyc"          name= "zdbdz_pyc"     />
+	  <field id="hmle"               name  = "hmle" />
+          <field id="mld_prof"         name  = "mld_prof" />
+          <field id="zmld"             name  = "zmld" />
+          <field id="zwb_fk"         name  = "zwb_fk" />
+          <field id="zwb_fk_b"         name  = "zwb_fk_b" />
+          <field field_ref="zdiff_mle"         name  = "zdiff_mle" />
+          <field field_ref="zvel_mle"         name  = "zvel_mle"  />
+          <field field_ref="us_x"          name="us_x"   />
+          <field field_ref="us_y"          name="us_y"   />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline" operation="instant"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  operation="instant" /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal" operation="instant"  /> -->
+        <!-- <field id="ghamu_00"       name  = "ghamu_00"/> -->
+        <!-- <field id="ghamv_00"       name  = "ghamv_00" /> -->
+        <!-- <field id="ghamu_0"        name  = "ghamu_0" /> -->
+        <!-- <field id="zsc_uw_1_0"        name  = "zsc_uw_1_0" /> -->
+        <!-- <field id="ghamu_f"            name  = "ghamu_f" /> -->
+        <!-- <field id="ghamv_f"            name  = "ghamv_f" /> -->
+        <!-- <field id="zsc_uw_1_f"            name  = "zsc_uw_1_f" /> -->
+        <!-- <field id="zsc_vw_1_f"            name  = "zsc_vw_1_f" /> -->
+        <!-- <field id="zsc_uw_2_f"            name  = "zsc_uw_2_f" /> -->
+        <!-- <field id="zsc_vw_2_f"           name  = "zsc_vw_2_f" /> -->
+        <!-- <field id="ghamu_b"            name  = "ghamu_b" /> -->
+        <!-- <field id="ghamv_b"           name  = "ghamv_b" /> -->
+        <!-- <field id="ghamu_1"           name  = "ghamu_1" /> -->
+        <!-- <field id="ghamv_1"           name  = "ghamv_1" /> -->
+        <!-- <field id="zviscos"            name  = "zviscos" /> -->
+        <!-- <field id="zdudz_pyc"           name  = "zdudz_pyc" /> -->
+        <!-- <field id="zdvdz_pyc"            name  = "zdvdz_pyc" /> -->
+        <!-- <field id="zuw_bse"           name  = "zuw_bse" /> -->
+        <!-- <field id="zvw_bse"           name  = "zvw_bse" /> -->
+       </file>
+ 	<file id="file31" name_suffix="_grid_UO" description="osmosisU grid variables">
+          <field field_ref="ghamu"          name="ghamu"     />
+           <field id="zdtdx"          name  = "zdtdx" />
+          <field id="zdsdx"         name  = "zdsdx" />
+          <field field_ref="dbdx_mle"          name="dbdx_mle" />
+       </file>
+  	<file id="file32" name_suffix="_grid_VO" description="osmosisV grid variables">
+          <field field_ref="ghamv"          name="ghamv"     />
+          <field id="zdtdy"          name  = "zdtdy" />
+          <field id="zdsdy"         name  = "zdsdy" />
+          <field field_ref="dbdy_mle"          name="dbdy_mle"  />
+       </file>
+     </file_group>
+      <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" split_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+
+        <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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1m.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1m.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1m.xml	(revision 13402)
@@ -0,0 +1,120 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="1m" output_freq="1mo" split_freq="1y" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
+ 	<file id="file30" name_suffix="_grid_TO" description="osmosis T grid variables">
+          <field field_ref="e3t"          name="e3t"     />
+          <field field_ref="ghamt"          name="ghamt"     />
+          <field field_ref="ghams"          name="ghams"    />
+          <field field_ref="zwth0"          name="zwth0"  />
+          <field field_ref="zws0"          name="zws0" />
+          <field field_ref="hbl"          name="hbl"  />
+          <field field_ref="ibld"          name="ibld"  />
+          <field field_ref="imld"          name="imld"  />
+           <field field_ref="hml"          name= "hml"     />
+          <field field_ref="dh"          name= "dh"     />
+          <field field_ref="utau"          name="tauuo"   />
+          <field field_ref="vtau"          name="tauvo"   />
+          <field field_ref="dstokes"          name="dstokes"   />
+          <field field_ref="zustke"          name="zustke"   />
+          <field field_ref="zwstrc"          name="zwstrc"  />
+          <field field_ref="zwstrl"          name="zwstrl"  />
+          <field field_ref="zla"          name="zla"  />
+          <field field_ref="zustar"          name="zustar"  />
+          <field field_ref="zvstr"          name="zvstr"  />
+          <field field_ref="zhbl"          name="zhbl"    />
+          <field field_ref="zhml"          name="zhml"    />
+          <field field_ref="zwthav"          name= "zwthav"     />
+          <field field_ref="zt_ml"          name= "zt_ml"     />
+          <field field_ref="zdt_bl"          name= "zdt_bml"     />
+          <field field_ref="zds_bl"          name= "zds_bml"     />
+          <field field_ref="zdb_bl"          name= "zdb_bml"     />
+          <field field_ref="zdu_bl"          name= "zdu_bml"     />
+          <field field_ref="zdv_bl"          name= "zdv_bml"     />
+          <field field_ref="zwth_ent"          name= "zwth_ent"     />
+          <field field_ref="zws_ent"          name= "zws_ent"     />
+          <field field_ref="zwb_ent"          name= "zwb_ent"     />
+          <field field_ref="zhol"          name= "zhol"     />
+          <field field_ref="zdh"          name= "zdh"     />
+          <field field_ref="zdtdz_pyc"          name= "zdtdz_pyc"     />
+          <field field_ref="zdsdz_pyc"          name= "zdsdz_pyc"     />
+          <field field_ref="zdbdz_pyc"          name= "zdbdz_pyc"     />
+	  <field id="hmle"               name  = "hmle" />
+          <field id="mld_prof"         name  = "mld_prof" />
+          <field id="zmld"             name  = "zmld" />
+          <field id="zwb_fk"         name  = "zwb_fk" />
+          <field id="zwb_fk_b"         name  = "zwb_fk_b" />
+          <field field_ref="zdiff_mle"         name  = "zdiff_mle" />
+          <field field_ref="zvel_mle"         name  = "zvel_mle"  />
+          <field field_ref="us_x"          name="us_x"   />
+          <field field_ref="us_y"          name="us_y"   />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline" operation="instant"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  operation="instant" /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal" operation="instant"  /> -->
+        <!-- <field id="ghamu_00"       name  = "ghamu_00"/> -->
+        <!-- <field id="ghamv_00"       name  = "ghamv_00" /> -->
+        <!-- <field id="ghamu_0"        name  = "ghamu_0" /> -->
+        <!-- <field id="zsc_uw_1_0"        name  = "zsc_uw_1_0" /> -->
+        <!-- <field id="ghamu_f"            name  = "ghamu_f" /> -->
+        <!-- <field id="ghamv_f"            name  = "ghamv_f" /> -->
+        <!-- <field id="zsc_uw_1_f"            name  = "zsc_uw_1_f" /> -->
+        <!-- <field id="zsc_vw_1_f"            name  = "zsc_vw_1_f" /> -->
+        <!-- <field id="zsc_uw_2_f"            name  = "zsc_uw_2_f" /> -->
+        <!-- <field id="zsc_vw_2_f"           name  = "zsc_vw_2_f" /> -->
+        <!-- <field id="ghamu_b"            name  = "ghamu_b" /> -->
+        <!-- <field id="ghamv_b"           name  = "ghamv_b" /> -->
+        <!-- <field id="ghamu_1"           name  = "ghamu_1" /> -->
+        <!-- <field id="ghamv_1"           name  = "ghamv_1" /> -->
+        <!-- <field id="zviscos"            name  = "zviscos" /> -->
+        <!-- <field id="zdudz_pyc"           name  = "zdudz_pyc" /> -->
+        <!-- <field id="zdvdz_pyc"            name  = "zdvdz_pyc" /> -->
+        <!-- <field id="zuw_bse"           name  = "zuw_bse" /> -->
+        <!-- <field id="zvw_bse"           name  = "zvw_bse" /> -->
+       </file>
+ 	<file id="file31" name_suffix="_grid_UO" description="osmosisU grid variables">
+          <field field_ref="ghamu"          name="ghamu"     />
+           <field id="zdtdx"          name  = "zdtdx" />
+          <field id="zdsdx"         name  = "zdsdx" />
+          <field field_ref="dbdx_mle"          name="dbdx_mle" />
+       </file>
+  	<file id="file32" name_suffix="_grid_VO" description="osmosisV grid variables">
+          <field field_ref="ghamv"          name="ghamv"     />
+          <field id="zdtdy"          name  = "zdtdy" />
+          <field id="zdsdy"         name  = "zdsdy" />
+          <field field_ref="dbdy_mle"          name="dbdy_mle"  />
+       </file>
+     </file_group>
+      <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="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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_1ts.xml	(revision 13402)
@@ -0,0 +1,120 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1ts" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+  	<file id="file30" name_suffix="_grid_TO" description="osmosis T grid variables">
+          <field field_ref="e3t"          name="e3t"     />
+          <field field_ref="ghamt"          name="ghamt"     />
+          <field field_ref="ghams"          name="ghams"    />
+          <field field_ref="zwth0"          name="zwth0"  />
+          <field field_ref="zws0"          name="zws0" />
+          <field field_ref="hbl"          name="hbl"  />
+          <field field_ref="ibld"          name="ibld"  />
+          <field field_ref="imld"          name="imld"  />
+           <field field_ref="hml"          name= "hml"     />
+          <field field_ref="dh"          name= "dh"     />
+          <field field_ref="utau"          name="tauuo"   />
+          <field field_ref="vtau"          name="tauvo"   />
+          <field field_ref="dstokes"          name="dstokes"   />
+          <field field_ref="zustke"          name="zustke"   />
+          <field field_ref="zwstrc"          name="zwstrc"  />
+          <field field_ref="zwstrl"          name="zwstrl"  />
+          <field field_ref="zla"          name="zla"  />
+          <field field_ref="zustar"          name="zustar"  />
+          <field field_ref="zvstr"          name="zvstr"  />
+          <field field_ref="zhbl"          name="zhbl"    />
+          <field field_ref="zhml"          name="zhml"    />
+          <field field_ref="zwthav"          name= "zwthav"     />
+          <field field_ref="zt_ml"          name= "zt_ml"     />
+          <field field_ref="zdt_bl"          name= "zdt_bml"     />
+          <field field_ref="zds_bl"          name= "zds_bml"     />
+          <field field_ref="zdb_bl"          name= "zdb_bml"     />
+          <field field_ref="zdu_bl"          name= "zdu_bml"     />
+          <field field_ref="zdv_bl"          name= "zdv_bml"     />
+          <field field_ref="zwth_ent"          name= "zwth_ent"     />
+          <field field_ref="zws_ent"          name= "zws_ent"     />
+          <field field_ref="zwb_ent"          name= "zwb_ent"     />
+          <field field_ref="zhol"          name= "zhol"     />
+          <field field_ref="zdh"          name= "zdh"     />
+          <field field_ref="zdtdz_pyc"          name= "zdtdz_pyc"     />
+          <field field_ref="zdsdz_pyc"          name= "zdsdz_pyc"     />
+          <field field_ref="zdbdz_pyc"          name= "zdbdz_pyc"     />
+	  <field id="hmle"               name  = "hmle" />
+          <field id="mld_prof"         name  = "mld_prof" />
+          <field id="zmld"             name  = "zmld" />
+          <field id="zwb_fk"         name  = "zwb_fk" />
+          <field id="zwb_fk_b"         name  = "zwb_fk_b" />
+          <field field_ref="zdiff_mle"         name  = "zdiff_mle" />
+          <field field_ref="zvel_mle"         name  = "zvel_mle"  />
+          <field field_ref="us_x"          name="us_x"   />
+          <field field_ref="us_y"          name="us_y"   />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline" operation="instant"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  operation="instant" /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal" operation="instant"  /> -->
+        <field id="ghamu_00"       name  = "ghamu_00"/>
+        <field id="ghamv_00"       name  = "ghamv_00" />
+        <field id="ghamu_0"        name  = "ghamu_0" />
+        <field id="zsc_uw_1_0"        name  = "zsc_uw_1_0" />
+        <field id="ghamu_f"            name  = "ghamu_f" />
+        <field id="ghamv_f"            name  = "ghamv_f" />
+        <field id="zsc_uw_1_f"            name  = "zsc_uw_1_f" />
+        <field id="zsc_vw_1_f"            name  = "zsc_vw_1_f" />
+        <field id="zsc_uw_2_f"            name  = "zsc_uw_2_f" />
+        <field id="zsc_vw_2_f"           name  = "zsc_vw_2_f" />
+        <field id="ghamu_b"            name  = "ghamu_b" />
+        <field id="ghamv_b"           name  = "ghamv_b" />
+        <field id="ghamu_1"           name  = "ghamu_1" />
+        <field id="ghamv_1"           name  = "ghamv_1" />
+        <field id="zviscos"            name  = "zviscos" />
+        <field id="zdudz_pyc"           name  = "zdudz_pyc" />
+        <field id="zdvdz_pyc"            name  = "zdvdz_pyc" />
+        <field id="zuw_bse"           name  = "zuw_bse" />
+        <field id="zvw_bse"           name  = "zvw_bse" />
+       </file>
+ 	<file id="file31" name_suffix="_grid_UO" description="osmosisU grid variables">
+          <field field_ref="ghamu"          name="ghamu"     />
+           <field id="zdtdx"          name  = "zdtdx" />
+          <field id="zdsdx"         name  = "zdsdx" />
+          <field field_ref="dbdx_mle"          name="dbdx_mle" />
+       </file>
+  	<file id="file32" name_suffix="_grid_VO" description="osmosisV grid variables">
+          <field field_ref="ghamv"          name="ghamv"     />
+          <field id="zdtdy"          name  = "zdtdy" />
+          <field id="zdsdy"         name  = "zdsdy" />
+          <field field_ref="dbdy_mle"          name="dbdy_mle"  />
+       </file>
+     </file_group>
+     <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->  
+     
+      <file_group id="1m" output_freq="1mo" split_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+
+        <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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_danger_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_danger_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_danger_1ts.xml	(revision 13402)
@@ -0,0 +1,119 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1ts" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+ 	<file id="file66" name_suffix="_danger_TO" description="osmosis T grid variables in blowup">
+          <field field_ref="e3t"          name="e3t"     grid_ref="danger_T_3D"  />
+          <field field_ref="ghamt"          name="ghamt"     grid_ref="danger_W_3D"  />
+          <field field_ref="ghams"          name="ghams"    grid_ref="danger_W_3D"  />
+          <field field_ref="zwth0"          name="zwth0"  grid_ref="danger_T_2D"   />
+          <field field_ref="zws0"          name="zws0" grid_ref="danger_T_2D"   />
+          <field field_ref="hbl"          name="hbl"  grid_ref="danger_T_2D"   />
+          <field field_ref="ibld"          name="ibld"  grid_ref="danger_T_2D"   />
+          <field field_ref="imld"          name="imld"  grid_ref="danger_T_2D"   />
+          <field field_ref="hml"          name= "hml"     grid_ref="danger_T_2D"   />
+          <field field_ref="dh"          name= "dh"     grid_ref="danger_T_2D"   />
+          <field field_ref="utau"          name="tauuo"  grid_ref="danger_T_2D"    />
+          <field field_ref="vtau"          name="tauvo"  grid_ref="danger_T_2D"    />
+          <field field_ref="dstokes"          name="dstokes"  grid_ref="danger_T_2D"    />
+          <field field_ref="zustke"          name="zustke"   grid_ref="danger_T_2D"   />
+          <field field_ref="zwstrc"          name="zwstrc"  grid_ref="danger_T_2D"   />
+          <field field_ref="zwstrl"          name="zwstrl"  grid_ref="danger_T_2D"   />
+          <field field_ref="zla"          name="zla"  grid_ref="danger_T_2D"   />
+          <field field_ref="zustar"          name="zustar"  grid_ref="danger_T_2D"   />
+          <field field_ref="zvstr"          name="zvstr"  grid_ref="danger_T_2D"   />
+          <field field_ref="zhbl"          name="zhbl"    grid_ref="danger_T_2D"   />
+          <field field_ref="zhml"          name="zhml"   grid_ref="danger_T_2D"   />
+          <field field_ref="zwthav"          name= "zwthav"    grid_ref="danger_T_2D"   />
+          <field field_ref="zt_ml"          name= "zt_ml"     grid_ref="danger_T_2D"   />
+          <field field_ref="zdt_bl"          name= "zdt_bml"     grid_ref="danger_T_2D"   />
+          <field field_ref="zds_bl"          name= "zds_bml"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdb_bl"          name= "zdb_bml"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdu_bl"          name= "zdu_bml"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdv_bl"          name= "zdv_bml"  grid_ref="danger_T_2D"      />
+          <field field_ref="zwth_ent"          name= "zwth_ent"  grid_ref="danger_T_2D"      />
+          <field field_ref="zws_ent"          name= "zws_ent"    grid_ref="danger_T_2D"    />
+          <field field_ref="zhol"          name= "zhol"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdh"          name= "zdh"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdtdz_pyc"          name= "zdtdz_pyc"    grid_ref="danger_W_3D"   />
+          <field field_ref="zdsdz_pyc"          name= "zdsdz_pyc"    grid_ref="danger_W_3D"   />
+          <field field_ref="zdbdz_pyc"          name= "zdbdz_pyc"    grid_ref="danger_W_3D"   />
+      	  <field field_ref="hmle"               name  = "hmle"  grid_ref="danger_T_2D"  />
+          <field field_ref="mld_prof"         name  = "mld_prof" grid_ref="danger_T_2D"   />
+          <field field_ref="zmld"             name  = "zmld"  grid_ref="danger_T_2D"  />
+          <field field_ref="zwb_fk"         name  = "zwb_fk"  grid_ref="danger_T_2D"  />
+          <field field_ref="zwb_fk_b"         name  = "zwb_fk_b"  grid_ref="danger_T_2D"  />
+          <field field_ref="zdiff_mle"         name  = "zdiff_mle" grid_ref="danger_W_2D"   />
+          <field field_ref="zvel_mle"         name  = "zvel_mle"  grid_ref="danger_W_2D"   />
+          <field field_ref="us_x"          name="us_x"   grid_ref="danger_T_2D"   />
+          <field field_ref="us_y"          name="us_y"  grid_ref="danger_T_2D"    />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline" operation="instant"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  operation="instant" /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal" operation="instant"  /> -->
+        <field field_ref="ghamu_00"       name  = "ghamu_00"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_00"       name  = "ghamv_00"   grid_ref="danger_W_3D"  />
+        <field field_ref="ghamu_0"        name  = "ghamu_0"    grid_ref="danger_W_3D" />
+        <field field_ref="zsc_uw_1_0"        name  = "zsc_uw_1_0" grid_ref="danger_T_2D"    />
+        <field field_ref="ghamu_f"            name  = "ghamu_f"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_f"            name  = "ghamv_f"   grid_ref="danger_W_3D" />
+        <field field_ref="zsc_uw_1_f"            name  = "zsc_uw_1_f"  grid_ref="danger_T_2D"   />
+        <field field_ref="zsc_vw_1_f"            name  = "zsc_vw_1_f"  grid_ref="danger_T_2D"   />
+        <field field_ref="zsc_uw_2_f"            name  = "zsc_uw_2_f" grid_ref="danger_T_2D"   />
+        <field field_ref="zsc_vw_2_f"           name  = "zsc_vw_2_f"  grid_ref="danger_T_2D"  />
+        <field field_ref="ghamu_b"            name  = "ghamu_b"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_b"           name  = "ghamv_b"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamu_1"           name  = "ghamu_1"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_1"           name  = "ghamv_1"   grid_ref="danger_W_3D" />
+        <field field_ref="zviscos"            name  = "zviscos"  grid_ref="danger_W_3D" />
+        <field field_ref="zdudz_pyc"           name  = "zdudz_pyc"  grid_ref="danger_W_3D" />
+        <field field_ref="zdvdz_pyc"            name  = "zdvdz_pyc"  grid_ref="danger_W_3D" />
+        <field field_ref="zuw_bse"           name  = "zuw_bse"  grid_ref="danger_T_2D"  />
+        <field field_ref="zvw_bse"           name  = "zvw_bse"  grid_ref="danger_T_2D"  />
+   </file>
+ 	<file id="file67" name_suffix="_danger_UO" description="osmosisU grid variables">
+          <field field_ref="ghamu"          name="ghamu"    grid_ref="danger_U_3D"   />
+           <field field_ref="zdtdx"          name="zdtdx"   grid_ref="danger_U_2D" />
+           <field field_ref="zdsdx"          name="zdsdx"   grid_ref="danger_U_2D" />
+           <field field_ref="dbdx_mle"          name="dbdx_mle"   grid_ref="danger_U_2D" />
+    </file>
+  	<file id="file68" name_suffix="_danger_VO" description="osmosisV grid variables">
+          <field field_ref="ghamv"          name="ghamv"    grid_ref="danger_V_3D"    />
+           <field field_ref="zdtdy"          name="zdtdy"   grid_ref="danger_V_2D" />
+           <field field_ref="zdsdy"          name="zdsdy"   grid_ref="danger_V_2D" />
+           <field field_ref="dbdy_mle"          name="dbdy_mle"   grid_ref="danger_V_2D" />
+       </file>
+     </file_group>
+     <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->  
+     
+      <file_group id="1m" output_freq="1mo" split_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+
+        <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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_danger_1ts_noFK.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_danger_1ts_noFK.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_danger_1ts_noFK.xml	(revision 13402)
@@ -0,0 +1,106 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1ts" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+ 	<file id="file66" name_suffix="_danger_TO" description="osmosis T grid variables in blowup">
+          <field field_ref="e3t"          name="e3t"     grid_ref="danger_T_3D"  />
+          <field field_ref="ghamt"          name="ghamt"     grid_ref="danger_W_3D"  />
+          <field field_ref="ghams"          name="ghams"    grid_ref="danger_W_3D"  />
+          <field field_ref="zwth0"          name="zwth0"  grid_ref="danger_T_2D"   />
+          <field field_ref="zws0"          name="zws0" grid_ref="danger_T_2D"   />
+          <field field_ref="hbl"          name="hbl"  grid_ref="danger_T_2D"   />
+          <field field_ref="ibld"          name="ibld"  grid_ref="danger_T_2D"   />
+          <field field_ref="imld"          name="imld"  grid_ref="danger_T_2D"   />
+          <field field_ref="hml"          name= "hml"     grid_ref="danger_T_2D"   />
+          <field field_ref="dh"          name= "dh"     grid_ref="danger_T_2D"   />
+          <field field_ref="utau"          name="tauuo"  grid_ref="danger_T_2D"    />
+          <field field_ref="vtau"          name="tauvo"  grid_ref="danger_T_2D"    />
+          <field field_ref="dstokes"          name="dstokes"  grid_ref="danger_T_2D"    />
+          <field field_ref="zustke"          name="zustke"   grid_ref="danger_T_2D"   />
+          <field field_ref="zwstrc"          name="zwstrc"  grid_ref="danger_T_2D"   />
+          <field field_ref="zwstrl"          name="zwstrl"  grid_ref="danger_T_2D"   />
+          <field field_ref="zla"          name="zla"  grid_ref="danger_T_2D"   />
+          <field field_ref="zustar"          name="zustar"  grid_ref="danger_T_2D"   />
+          <field field_ref="zvstr"          name="zvstr"  grid_ref="danger_T_2D"   />
+          <field field_ref="zhbl"          name="zhbl"    grid_ref="danger_T_2D"   />
+          <field field_ref="zhml"          name="zhml"   grid_ref="danger_T_2D"   />
+          <field field_ref="zwthav"          name= "zwthav"    grid_ref="danger_T_2D"   />
+          <field field_ref="zt_ml"          name= "zt_ml"     grid_ref="danger_T_2D"   />
+          <field field_ref="zdt_bl"          name= "zdt_bml"     grid_ref="danger_T_2D"   />
+          <field field_ref="zds_bl"          name= "zds_bml"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdb_bl"          name= "zdb_bml"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdu_bl"          name= "zdu_bml"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdv_bl"          name= "zdv_bml"  grid_ref="danger_T_2D"      />
+          <field field_ref="zwth_ent"          name= "zwth_ent"  grid_ref="danger_T_2D"      />
+          <field field_ref="zws_ent"          name= "zws_ent"    grid_ref="danger_T_2D"    />
+          <field field_ref="zhol"          name= "zhol"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdh"          name= "zdh"   grid_ref="danger_T_2D"     />
+          <field field_ref="zdtdz_pyc"          name= "zdtdz_pyc"    grid_ref="danger_W_3D"   />
+          <field field_ref="zdsdz_pyc"          name= "zdsdz_pyc"    grid_ref="danger_W_3D"   />
+          <field field_ref="zdbdz_pyc"          name= "zdbdz_pyc"    grid_ref="danger_W_3D"   />
+          <field field_ref="us_x"          name="us_x"   grid_ref="danger_T_2D"   />
+          <field field_ref="us_y"          name="us_y"  grid_ref="danger_T_2D"    />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline" operation="instant"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  operation="instant" /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal" operation="instant"  /> -->
+        <field field_ref="ghamu_00"       name  = "ghamu_00"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_00"       name  = "ghamv_00"   grid_ref="danger_W_3D"  />
+        <field field_ref="ghamu_0"        name  = "ghamu_0"    grid_ref="danger_W_3D" />
+        <field field_ref="zsc_uw_1_0"        name  = "zsc_uw_1_0" grid_ref="danger_T_2D"    />
+        <field field_ref="ghamu_f"            name  = "ghamu_f"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_f"            name  = "ghamv_f"   grid_ref="danger_W_3D" />
+        <field field_ref="zsc_uw_1_f"            name  = "zsc_uw_1_f"  grid_ref="danger_T_2D"   />
+        <field field_ref="zsc_vw_1_f"            name  = "zsc_vw_1_f"  grid_ref="danger_T_2D"   />
+        <field field_ref="zsc_uw_2_f"            name  = "zsc_uw_2_f" grid_ref="danger_T_2D"   />
+        <field field_ref="zsc_vw_2_f"           name  = "zsc_vw_2_f"  grid_ref="danger_T_2D"  />
+        <field field_ref="ghamu_b"            name  = "ghamu_b"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_b"           name  = "ghamv_b"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamu_1"           name  = "ghamu_1"   grid_ref="danger_W_3D" />
+        <field field_ref="ghamv_1"           name  = "ghamv_1"   grid_ref="danger_W_3D" />
+        <field field_ref="zviscos"            name  = "zviscos"  grid_ref="danger_W_3D" />
+        <field field_ref="zdudz_pyc"           name  = "zdudz_pyc"  grid_ref="danger_W_3D" />
+        <field field_ref="zdvdz_pyc"            name  = "zdvdz_pyc"  grid_ref="danger_W_3D" />
+        <field field_ref="zuw_bse"           name  = "zuw_bse"  grid_ref="danger_T_2D"  />
+        <field field_ref="zvw_bse"           name  = "zvw_bse"  grid_ref="danger_T_2D"  />
+   </file>
+ 	<file id="file67" name_suffix="_danger_UO" description="osmosisU grid variables">
+          <field field_ref="ghamu"          name="ghamu"    grid_ref="danger_U_3D"   />
+    </file>
+  	<file id="file68" name_suffix="_danger_VO" description="osmosisV grid variables">
+          <field field_ref="ghamv"          name="ghamv"    grid_ref="danger_V_3D"    />
+       </file>
+     </file_group>
+     <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->  
+     
+      <file_group id="1m" output_freq="1mo" split_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+
+        <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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_short_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_short_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_osmosis_short_1ts.xml	(revision 13402)
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1ts" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE." fi> <!-- 1 time step files -->
+ 	<file id="file66" name_suffix="_danger" description="osmosis T grid variables in blowup">
+          <field field_ref="e3t"          name="e33t"    grid_ref="danger_T_3D" />
+        </file>
+  	<file id="file30" name_suffix="_grid_TO" description="osmosis T grid variables">
+          <field field_ref="e3t"          name="e3t"     />
+          <field field_ref="ghamt"          name="ghamt"     />
+          <field field_ref="ghams"          name="ghams"    />
+          <field field_ref="zwth0"          name="zwth0"  />
+          <field field_ref="zws0"          name="zws0" />
+          <field field_ref="hbl"          name="hbl"  />
+          <field field_ref="ibld"          name="ibld"  />
+          <field field_ref="imld"          name="imld"  />
+          <!-- <field field_ref="hbli"          name="hbli"  /> -->
+          <field field_ref="hml"          name= "hml"     />
+          <field field_ref="dh"          name= "dh"     />
+          <field field_ref="utau"          name="tauuo"   />
+          <field field_ref="vtau"          name="tauvo"   />
+          <field field_ref="dstokes"          name="dstokes"   />
+          <field field_ref="zustke"          name="zustke"   />
+          <field field_ref="zwstrc"          name="zwstrc"  />
+          <field field_ref="zwstrl"          name="zwstrl"  />
+          <field field_ref="zla"          name="zla"  />
+          <field field_ref="zustar"          name="zustar"  />
+          <field field_ref="zvstr"          name="zvstr"  />
+          <field field_ref="zhbl"          name="zhbl"    />
+          <field field_ref="zhml"          name="zhml"    />
+          <field field_ref="zwthav"          name= "zwthav"     />
+          <field field_ref="zt_ml"          name= "zt_ml"     />
+          <field field_ref="zdt_bl"          name= "zdt_bml"     />
+          <field field_ref="zds_bl"          name= "zds_bml"     />
+          <field field_ref="zdb_bl"          name= "zdb_bml"     />
+          <field field_ref="zdu_bl"          name= "zdu_bml"     />
+          <field field_ref="zdv_bl"          name= "zdv_bml"     />
+          <field field_ref="zwth_ent"          name= "zwth_ent"     />
+          <field field_ref="zws_ent"          name= "zws_ent"     />
+          <field field_ref="zhol"          name= "zhol"     />
+          <field field_ref="zdh"          name= "zdh"     />
+          <!-- <field field_ref="zdsdz_pyc"          name= "zdsdz_pyc"     /> -->
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline" operation="instant"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  operation="instant" /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh" operation="instant"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol" operation="instant"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  operation="instant" /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal" operation="instant"  /> -->
+	<field id="hmle"               name  = "hmle" />
+        <field id="imld_prof"         name  = "imld_prof" />
+        <field id="zmld"             name  = "zmld" />
+        <field id="zwb_fk"         name  = "zwb_fk" />
+        <field id="zwt_fk"          name  = "zwt_fk" />
+        <field id="zws_fk"          name  = "zws_fk" />
+        <field id="zwb_fk_b"         name  = "zwb_fk_b" />
+       </file>
+        </file_group>
+     <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->  
+     
+      <file_group id="1m" output_freq="1mo" split_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+
+        <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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_short_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_short_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_short_1ts.xml	(revision 13402)
@@ -0,0 +1,55 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" min_digits="4">
+    
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+
+	<file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+	  <field field_ref="toce"         name="votemper"  />
+	  <field field_ref="soce"         name="vosaline"  />
+	  <field field_ref="sst"          name="sosstsst"  />
+	  <field field_ref="sss"          name="sosaline"  />
+	  <field field_ref="ssh"          name="sossheig"  />
+	  <field field_ref="empmr"        name="sowaflup"  />
+	  <field field_ref="qsr"          name="soshfldo"  />
+	  <field field_ref="saltflx"      name="sosfldow"  />
+	  <field field_ref="qt"           name="sohefldo"  />
+	  <field field_ref="mldr10_1"     name="somxl010"  />
+	  <field field_ref="mldkz5"       name="somixhgt"  />
+	  <!-- <field field_ref="bgtemper"       name="bgtemper"  /> -->
+	  <!-- <field field_ref="bgsaline"       name="bgsaline"  /> -->
+	  <!-- <field field_ref="bgheatco"       name="bgheatco"  /> -->
+	  <!-- <field field_ref="bgsaltco"       name="bgsaltco"  /> -->
+	  <!-- <field field_ref="bgvolssh"       name="bgvolssh"  /> -->
+	  <!-- <field field_ref="bgvole3t"       name="bgvole3t"  /> -->
+	  <!-- <field field_ref="bgfrcvol"       name="bgfrcvol"  /> -->
+	  <!-- <field field_ref="bgfrctem"       name="bgfrctem"  /> -->
+	  <!-- <field field_ref="bgfrcsal"       name="bgfrcsal"  /> -->
+	</file>
+	
+
+      </file_group>
+  
+      <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_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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1d.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1d.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1d.xml	(revision 13402)
@@ -0,0 +1,48 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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="1d" output_freq="1d"  output_level="10" enabled=".TRUE."> <!-- 1d files -->
+ 	<file id="file25" name_suffix="_grid_WT" description="wave T grid variables">
+          <field field_ref="hsw"          name="hsw"     />
+ 	  <field field_ref="wmp"          name="wmp"     />
+	  <field field_ref="hsw_NP"          name="hsw_NP"     />
+	  <field field_ref="wmp_NP"          name="wmp_NP"     />
+ 	  <field field_ref="wndm"          name="wndm"     />
+          <field field_ref="us_x"          name="us_x"   />
+          <field field_ref="us_y"          name="us_y"   />
+     </file>
+  	<file id="file26" name_suffix="_grid_WU" description="wave U grid variables">
+          <field field_ref="ustokes"          name="ustokes"     />
+       </file>
+  	<file id="file27" name_suffix="_grid_WV" description="wave V grid variables">
+          <field field_ref="vstokes"          name="vstokes"     />
+       </file>
+  	<file id="file28" name_suffix="_grid_WW" description="wave W grid variables">
+          <field field_ref="wstokes"          name="wstokes"     />
+       </file>
+
+      </file_group>
+      <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" split_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+       <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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1m.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1m.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1m.xml	(revision 13402)
@@ -0,0 +1,48 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" 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="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1m files -->
+      <file_group id="1m" output_freq="1mo" split_freq="1y" output_level="10" enabled=".TRUE."> <!-- real monthly files -->
+ 	<file id="file25" name_suffix="_grid_WT" description="wave T grid variables">
+          <field field_ref="hsw"          name="hsw"     />
+ 	  <field field_ref="wmp"          name="wmp"     />
+	  <field field_ref="hsw_NP"          name="hsw_NP"     />
+	  <field field_ref="wmp_NP"          name="wmp_NP"     />
+ 	  <field field_ref="wndm"          name="wndm"     />
+          <field field_ref="us_x"          name="us_x"   />
+          <field field_ref="us_y"          name="us_y"   />
+     </file>
+  	<file id="file26" name_suffix="_grid_WU" description="wave U grid variables">
+          <field field_ref="ustokes"          name="ustokes"     />
+       </file>
+  	<file id="file27" name_suffix="_grid_WV" description="wave V grid variables">
+          <field field_ref="vstokes"          name="vstokes"     />
+       </file>
+  	<file id="file28" name_suffix="_grid_WW" description="wave W grid variables">
+          <field field_ref="wstokes"          name="wstokes"     />
+       </file>
+
+      </file_group>
+      <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="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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1ts.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1ts.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/file_def_waves_1ts.xml	(revision 13402)
@@ -0,0 +1,48 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="1d" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."> <!-- 1 time step files -->
+ 	<file id="file25" name_suffix="_grid_WT" description="wave T grid variables">
+          <field field_ref="hsw"          name="hsw"     />
+ 	  <field field_ref="wmp"          name="wmp"     />
+	  <field field_ref="hsw_NP"          name="hsw_NP"     />
+	  <field field_ref="wmp_NP"          name="wmp_NP"     />
+ 	  <field field_ref="wndm"          name="wndm"     />
+          <field field_ref="us_x"          name="us_x"   />
+          <field field_ref="us_y"          name="us_y"   />
+     </file>
+  	<file id="file26" name_suffix="_grid_WU" description="wave U grid variables">
+          <field field_ref="ustokes"          name="ustokes"     />
+       </file>
+  	<file id="file27" name_suffix="_grid_WV" description="wave V grid variables">
+          <field field_ref="vstokes"          name="vstokes"     />
+       </file>
+  	<file id="file28" name_suffix="_grid_WW" description="wave W grid variables">
+          <field field_ref="wstokes"          name="wstokes"     />
+       </file>
+
+      </file_group>
+     <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 1d files -->
+      <file_group id="3d" output_freq="3d"  output_level="10" enabled=".TRUE."/> <!-- 3d files -->    
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->  
+     
+      <file_group id="1m" output_freq="1mo" split_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real monthly files -->
+       <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>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/iodef.xml
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/iodef.xml	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/iodef.xml	(revision 13402)
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<simulation> 
+
+<!-- ============================================================================================ -->
+<!-- XIOS context                                                                                 -->
+<!-- ============================================================================================ -->
+
+  <context id="xios" >
+
+      <variable_definition>
+	
+	  <variable id="info_level"                type="int">10</variable>
+	  <variable id="using_server"              type="bool">true</variable>
+	  <variable id="using_oasis"               type="bool">false</variable>
+	  <variable id="oasis_codes_id"            type="string" >oceanx</variable>
+	
+      </variable_definition>
+  </context>
+
+<!-- ============================================================================================ -->
+<!-- NEMO  CONTEXT add and suppress the components you need                                       -->
+<!-- ============================================================================================ -->
+
+  <context id="nemo" src="./context_nemo.xml"/>       <!--  NEMO       -->
+
+</simulation>
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_cfg	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_cfg	(revision 13402)
@@ -0,0 +1,530 @@
+!-----------------------------------------------------------------------
+&namrun        !   parameters of the run
+!-----------------------------------------------------------------------
+   nn_no       =       0   !  job number (no more used...)
+   cn_exp      =  "eORCA1L3_OSM_N"  !  experience name
+   nn_it000    =       1 !8993 !33 !8992   !  first time step
+   nn_itend    =     35040 !72 !35040 !35040 !6 4 !11680 !32 !2464 !35040  !64 !9000 !116800  !  last  time step (std 5475)
+   nn_date0    =  19800101 !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_leapy    =       0   !  Leap year calendar (1) or not (0)
+   ln_rstart   = .false. !.false.   !  start from rest (F) or from a restart file (T)
+   !
+   nn_rstctl   =   2 !0 ! 2            !  restart control ==> activated only if ln_rstart=T
+   cn_ocerst_in    =  "restart"  ! "eORCA1L3_OSM_no_w_00000032_restart" !  suffix of ocean restart name (input)
+   cn_ocerst_indir = "RESTARTS"         !  directory from which to read input ocean restarts
+   cn_ocerst_outdir = "RESTARTS"         !  directory from which to read input ocean restarts
+   nn_istate   =      0 !1   !  output the initial state (1) or not (0)
+   ln_rst_list = .false.   !  output restarts at list of times using nn_stocklist (T) or at set frequency with nn_stock (F)
+   nn_stock    =    11680 !8892 ! 32 !8892 !11680   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_stocklist = 8892,11680,0,0,0,0,0,0 ! List of timesteps when a restart file is to be written
+   nn_write    =    11680   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
+   ln_cfmeta   = .false.   !  output additional data to netCDF files required for compliance with the CF metadata standard
+   nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
+/
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration                      (default: user defined GYRE)
+!-----------------------------------------------------------------------
+   ln_read_cfg = .true.    !  (=T) read the domain configuration file
+      !                    !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
+      cn_domcfg = "eORCA_R1_zps_domcfg"    ! domain configuration filename
+/
+!-----------------------------------------------------------------------
+&namdom        !   time and space domain
+!-----------------------------------------------------------------------
+   rn_rdt      =  2700.     !  time step for the dynamics 
+   ln_meshmask = .false. !.true.    ! create meshfile  
+/
+!-----------------------------------------------------------------------
+&namtsd        !   data : Temperature  & Salinity
+!-----------------------------------------------------------------------
+   !                       ! =T  read T-S fields for:
+   ln_tsd_init = .true.         !  ocean initialisation
+   ln_tsd_dmp  = .false.         !  T-S restoring   (see namtra_dmp)
+   
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the T-S data location
+   !___________!_________________________!___________________!___________!_____________!________!___________!__________________!__________!_______________!
+   !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
+   !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
+   sn_tem  = 'conservative_temperature_WOA13_decav_Reg1L75_clim', -1 ,'votemper' , .true. , .true. , 'yearly' , 'weights_3D_WOA13d1_2_eorca1_bilinear.nc'  ,   ''    ,    ''
+   sn_sal  = 'absolute_salinity_WOA13_decav_Reg1L75_clim'       , -1 ,'vosaline' , .true. , .true. , 'yearly' , 'weights_3D_WOA13d1_2_eorca1_bilinear.nc'  ,   ''    ,    ''
+/
+!-----------------------------------------------------------------------
+&namwad        !   Wetting and drying  default is no WAD
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namc1d_dyndmp !   U & V newtonian damping                              ("key_c1d")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc        !   Surface Boundary Condition (surface module)
+!-----------------------------------------------------------------------
+   nn_fsbc     = 1         !  frequency of surface boundary condition computation
+                           !     (also = the frequency of sea-ice & iceberg model call)
+                     ! Type of air-sea fluxes 
+   ln_blk      = .true.    !  Bulk formulation                          (T => fill namsbc_blk )
+   nn_ice      = 2         !  =0 no ice boundary condition    
+                           !  =1 use observed ice-cover                 (  => fill namsbc_iif )
+                           !  =2 or 3 automatically for LIM3 or CICE    ("key_lim3" or "key_cice")
+                           !          except in AGRIF zoom where it has to be specified
+   ln_ice_embd = .false.   !  =T embedded sea-ice (pressure + mass and salt exchanges)
+                           !  =F levitating ice (no pressure, mass and salt exchanges)
+                     ! Misc. options of sbc : 
+   ln_traqsr   = .true.    !  Light penetration in the ocean            (T => fill namtra_qsr)
+   ln_dm2dc    = .true.   !  daily mean to diurnal cycle on short wave
+   ln_rnf      = .true.    !  runoffs                                   (T => fill namsbc_rnf)
+   ln_ssr      = .true.    !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
+   nn_fwb      = 2         !  FreshWater Budget: =0 unchecked
+                           !     =1 global mean of e-p-r set to zero at each time step
+                           !     =2 annual global mean of e-p-r set to zero
+   ln_isf      = .true.   !  ice shelf                                 (T   => fill namsbc_isf)
+   ln_wave     = .true.   !  Activate coupling with wave  (T => fill namsbc_wave)
+   ln_cdgw     = .false.   !  Neutral drag coefficient read from wave model (T => ln_wave=.true. & fill namsbc_wave)
+   ln_sdw      = .true. !.false.   !  Read 2D Surf Stokes Drift & Computation of 3D stokes drift (T => ln_wave=.true. & fill namsbc_wave) 
+   nn_sdrift   =  1        !  Parameterization for the calculation of 3D-Stokes drift from the surface Stokes drift
+                           !   = 0 Breivik 2015 parameterization: v_z=v_0*[exp(2*k*z)/(1-8*k*z)]
+                           !   = 1 Phillips:                      v_z=v_o*[exp(2*k*z)-beta*sqrt(-2*k*pi*z)*erfc(sqrt(-2*k*z))]
+                           !   = 2 Phillips as (1) but using the wave frequency from a wave model
+   ln_tauwoc    = .false.   !  Activate ocean stress modified by external wave induced stress (T => ln_wave=.true. & fill namsbc_wave)
+   ln_stcor    = .true.   !  Activate Stokes Coriolis term (T => ln_wave=.true. & ln_sdw=.true. & fill namsbc_wave)
+   nn_lsm      = 0         !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
+                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
+/
+!-----------------------------------------------------------------------
+&namsbc_flx    !   surface boundary condition : flux formulation
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_blk   !   namsbc_blk  generic Bulk formula                      (ln_blk =T)
+!-----------------------------------------------------------------------
+!              !  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_wndi     = 'u_10_core_oonly'       ,         6         , 'U_10_MOD',   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bicubic.nc'  , 'U1'    , ''
+   sn_wndj     = 'v_10_core_oonly'       ,         6         , 'V_10_MOD',   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bicubic.nc'  , 'V1'    , ''
+   sn_qsr      = 'rad_core_oonly'        ,        24         , 'SWDN_MOD',   .false.    ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_qlw      = 'rad_core_oonly'        ,        24         , 'LWDN_MOD',   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_tair     = 't_10_core_oonly'       ,         6         , 'T_10_MOD',   .false.    ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_humi     = 'q_10_core_oonly'       ,         6         , 'Q_10_MOD',   .false.    ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_prec     = 'tprecip_core_oonly'    ,        -1         , 'TPRECIP' ,   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_snow     = 'tprecip_core_oonly'    ,        -1         , 'SNOW'    ,   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_slp      = 'slp_core_oonly'        ,         6         , 'SLP'     ,   .true.     , .false.  , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   ln_NCAR     = .true.   ! "NCAR"      algorithm   (Large and Yeager 2008)
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/IAF_CORE/'      !  root directory for the location of the flux files
+/
+!-----------------------------------------------------------------------
+&namsbc_cpl    !   coupled ocean/atmosphere model                       ("key_oasis3")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_sas    !   Stand-Alone Surface boundary condition
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_iif    !   Ice-IF : use observed ice cover                      (nn_ice = 1)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr =T)
+!-----------------------------------------------------------------------
+!              !  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_chl      ='merged_ESACCI_BIOMER4V1R1_CHL_REG05',  -1  , 'CHLA' , .true. , .true. , 'yearly' , 'weights_reg05_2_eorca1_bilinear.nc' , '' , ''
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+   ln_qsr_rgb  = .false.   !  RGB (Red-Green-Blue) light penetration
+   ln_qsr_2bd  = .true.  !  2 bands              light penetration
+   ln_qsr_bio  = .false.  !  bio-model light penetration
+   nn_chldta   =      1    !  RGB : Chl data (=1) or cst value (=0)
+   rn_abs      =   0.58    !  RGB & 2 bands: fraction of light (rn_si1)
+   rn_si0      =   0.35    !  RGB & 2 bands: shortess depth of extinction
+   rn_si1      =   23.0    !  2 bands: longest depth of extinction
+/
+!-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf =T)
+!-----------------------------------------------------------------------
+!              !  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_rnf      = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc',        -1         , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc',         0         , 'socoeff' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+   ln_rnf_mouth = .false.    !  specific treatment at rivers mouths
+   ln_rnf_depth = .false.    !  read in depth information for runoff
+   ln_rnf_tem   = .false.    !  read in temperature information for runoff
+   ln_rnf_sal   = .false.    !  read in salinity information for runoff
+   ln_rnf_depth_ini = .false. !.true. !  compute depth at initialisation from runoff file
+   rn_rnf_max   = 0.05       !  max value of the runoff climatology over global domain ( if ln_rnf_depth_ini = .true )
+   rn_dep_max = 150.         !  depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
+   nn_rnf_depth_file = 0     ! create (=1) a runoff depth file or not (=0)
+/
+!-----------------------------------------------------------------------
+&namsbc_isf    !  Top boundary layer (ISF)                              (nn_isf >0)
+!-----------------------------------------------------------------------
+!              ! 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_rnfisf     = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ,   -12             ,'sornfisf'     , .false. , .true. , 'yearly'  ,  ''     ,   ''     ,  ''
+   sn_depmax_isf = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ,   -12             ,'sodepmax_isf' , .false. , .true. , 'yearly'  ,  ''     ,   ''     ,  ''
+   sn_depmin_isf = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ,   -12             ,'sodepmin_isf' , .false. , .true. , 'yearly'  ,  ''     ,   ''     ,  ''
+   nn_isf      = 3         !  ice shelf melting/freezing
+                           !  1 = presence of ISF    2 = bg03 parametrisation 
+                           !  3 = rnf file for isf   4 = ISF fwf specified
+                           !  option 1 and 4 need ln_isfcav = .true. (domzgr)
+/
+!-----------------------------------------------------------------------
+&namsbc_iscpl  !   land ice / ocean coupling option                     
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_apr    !   Atmospheric pressure used as ocean forcing           (ln_apr_dyn =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr =T)
+!-----------------------------------------------------------------------
+!              ! 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_sss      = 'sss_absolute_salinity_WOA13_decav_Reg1L75_clim', -1. , 'sosaline', .true. , .true. , 'yearly' , 'weights_WOA13d1_2_eorca1_bilinear.nc' , '' , ''
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+      rn_deds     =  -166.67  !  magnitude of the damping on salinity   [mm/day]
+      ln_sssr_bnd =  .true.   !  flag to bound erp term (associated with nn_sssr=2)
+      rn_sssr_bnd =   4.e0    !  ABS(Max/Min) value of the damping erp term [mm/day]
+/
+!-----------------------------------------------------------------------
+&namsbc_wave   ! External fields from wave model                        (ln_wave=T)
+!-----------------------------------------------------------------------
+!              !  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_cdg      =  'sdw_wave' ,        1          , 'drag_coeff' ,     .true.   , .false. , 'yearly'   ,  ''      , ''       , ''
+   sn_usd      =  'ust' ,        6          , 'ust'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bicubic.nc'    , 'U1'     , ''
+   sn_vsd      =  'vst' ,        6          , 'vst'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bicubic.nc'    , 'V1'     , ''
+   sn_hsw      =  'swh' ,        6          , 'swh'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bilin.nc'      , ''       , ''
+   sn_wmp      =  'mwp' ,        6          , 'mwp'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bilin.nc'      , ''       , ''
+!   sn_wnum     =  'sdw_wave' ,        1          , 'wave_num'   ,     .true.   , .false. , 'yearly'   ,  ''      , ''       , ''
+!   sn_tauoc    =  'sdw_wave' ,        1          , 'wave_stress',     .true.   , .false. , 'yearly'   ,  ''      , ''       , ''
+!
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/ERA_INTERIM/WAVES/'      !  root directory for the location of the flux files
+/
+!-----------------------------------------------------------------------
+&namberg       !   iceberg parameters                                   (default: No iceberg)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namlbc        !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+   !                       !  free slip  !   partial slip  !   no slip   ! strong slip
+   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
+   ln_vorlat   = .false.   !  consistency of vorticity boundary condition with analytical Eqs.
+/
+!-----------------------------------------------------------------------
+&namagrif      !  AGRIF zoom                                            ("key_agrif")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_tide      !   tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta    !  open boundaries - external data
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_tide   !  tidal forcing at open boundaries
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdrg        !   top/bottom drag coefficient                          (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_lin = .true.    !   linear  drag: Cd = Cd0 Uc0
+/
+!-----------------------------------------------------------------------
+&namdrg_top    !   TOP friction                                         (ln_isfcav=T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdrg_bot        !   BOTTOM friction
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+!              !  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_qgh      ='Goutorbe_ghflux.nc',  -12.  , 'gh_flux'    ,   .false.     , .true. , 'yearly'  , 'weights_Goutorbe1_2_eorca1_bilinear.nc'       , ''       , ''
+   !
+   ln_trabbc   = .true.   !  Apply a geothermal heating at the ocean bottom
+      nn_geoflx   =    2      !  geothermal heat flux: = 0 no flux
+      !                       !     = 1 constant flux
+      !                       !     = 2 variable flux (read in geothermal_heating.nc in mW/m2)
+      rn_geoflx_cst = 86.4e-3 !  Constant value of geothermal heat flux [W/m2]
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nameos        !   ocean Equation Of Seawater                           (default: NO)
+!-----------------------------------------------------------------------
+   ln_teos10    = .true.         !  = Use TEOS-10 equation of state
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer                          (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_traadv_fct = .true. !  FCT scheme
+      nn_fct_h   =  2            !  =2/4, horizontal 2nd / 4th order 
+      nn_fct_v   =  2            !  =2/4, vertical   2nd / COMPACT 4th order 
+/
+!-----------------------------------------------------------------------
+&namtra_mle !   mixed layer eddy parametrisation (Fox-Kemper param) (default: NO)
+!-----------------------------------------------------------------------
+   ln_mle      = .true.   ! (T) use the Mixed Layer Eddy (MLE) parameterisation
+   rn_ce       = 0.04      ! magnitude of the MLE (typical value: 0.06 to 0.08)
+
+/
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers
+!----------------------------------------------------------------------------------
+   !                       !  Operator type:
+   ln_traldf_lap   =  .true.   !    laplacian operator
+   ln_traldf_blp   =  .false.  !  bilaplacian operator
+   !
+   !                       !  Direction of action:
+   ln_traldf_iso   =  .true.  !  iso-neutral (standard operator)
+   ln_traldf_triad =  .false.  !  iso-neutral (triad    operator)
+   !
+   !		       	         !  iso-neutral options:        
+   ln_traldf_msc   =  .true.   !  Method of Stabilizing Correction (both operators)
+   rn_slpmax       =   0.01    !  slope limit                      (both operators)
+   ln_triad_iso    =  .false.  !  pure horizontal mixing in ML              (triad only)
+   rn_sw_triad     =  1        !  =1 switching triad ; =0 all 4 triads used (triad only)
+   ln_botmix_triad =  .false.  !  lateral mixing on bottom                  (triad only)
+   !
+   !                       !  Coefficients:
+   nn_aht_ijk_t    = 20        !  space/time variation of eddy coefficient:
+      !                             !   =-20 (=-30)    read in eddy_diffusivity_2D.nc (..._3D.nc) file
+      !                             !   =  0           constant 
+      !                             !   = 10 F(k)      =ldf_c1d 
+      !                             !   = 20 F(i,j)    =ldf_c2d 
+      !                             !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
+      !                             !   = 30 F(i,j,k)  =ldf_c2d * ldf_c1d
+      !                             !   = 31 F(i,j,k,t)=F(local velocity and grid-spacing)
+      !                        !  time invariant coefficients:  aht0 = 1/2  Ud*Ld   (lap case) 
+      !                             !                           or   = 1/12 Ud*Ld^3 (blp case)
+/
+!-----------------------------------------------------------------------
+&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
+!-----------------------------------------------------------------------
+    ln_ldfeiv     = .true. ! use eddy induced velocity parameterization
+      rn_aeiv_0     = 1000.   ! eddy induced velocity coefficient   [m2/s]
+      nn_aei_ijk_t  = 21      ! space/time variation of the eiv coeficient
+      !                             !   =-20 (=-30)    read in eddy_induced_velocity_2D.nc (..._3D.nc) file
+      !                             !   =  0           constant 
+      !                             !   = 10 F(k)      =ldf_c1d 
+      !                             !   = 20 F(i,j)    =ldf_c2d 
+      !                             !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
+      !                             !   = 30 F(i,j,k)  =ldf_c2d + ldf_c1d
+      ln_ldfeiv_dia =.true.  ! diagnose eiv stream function and velocities
+/
+!-----------------------------------------------------------------------
+&namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
+!-----------------------------------------------------------------------
+   ln_tradmp   =  .false.
+/
+!-----------------------------------------------------------------------
+&nam_vvl       !   vertical coordinate options                          (default: z-star)
+!-----------------------------------------------------------------------
+   ln_vvl_zstar  = .true.           !  z-star vertical coordinate
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_vec = .true. !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2 = .false. !  flux form - 2nd order centered scheme
+/
+!-----------------------------------------------------------------------
+&namdyn_vor    !   Vorticity / Coriolis scheme                          (default: NO)
+!-----------------------------------------------------------------------
+   ln_dynvor_een = .true.  !  energy & enstrophy scheme
+      nn_een_e3f = 1             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
+/
+!-----------------------------------------------------------------------
+&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_hpg_sco  = .true.   !  s-coordinate (standard jacobian formulation)
+/
+!-----------------------------------------------------------------------
+&namdyn_spg    !   surface pressure gradient                            (default: NO)
+!-----------------------------------------------------------------------
+   ln_dynspg_ts   = .true.   ! split-explicit free surface
+      ln_bt_fw      = .false.     ! Forward integration of barotropic Eqs.
+      ln_bt_av      = .true.     ! Time filtering of barotropic variables
+         nn_bt_flt     = 1          ! Time filter choice  = 0 None
+         !                          !                     = 1 Boxcar over   nn_baro sub-steps
+         !                          !                     = 2 Boxcar over 2*nn_baro  "    "
+      ln_bt_auto    = .true.     ! Number of sub-step defined from:
+         rn_bt_cmax   =  0.8        ! =T : the Maximum Courant Number allowed
+         nn_baro      = 30          ! =F : the number of sub-step in rn_rdt seconds
+      rn_bt_alpha   = 0.         ! Temporal diffusion parameter (if ln_bt_av=F)
+/
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       !  Type of the operator :
+   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_lap =  .true.     !    laplacian operator
+   !                       !  Direction of action  :
+   ln_dynldf_lev =  .true.     !  iso-level
+   !                       !  Coefficient
+   nn_ahm_ijk_t  =  30         !  space/time variation of eddy coef
+   !                                !  =-30  read in eddy_viscosity_3D.nc file
+   !                                !  =-20  read in eddy_viscosity_2D.nc file
+   !                                !  =  0  constant 
+   !                                !  = 10  F(k)=c1d
+   !                                !  = 20  F(i,j)=F(grid spacing)=c2d
+   !                                !  = 30  F(i,j,k)=c2d*c1d
+   !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   !                           !  time invariant coefficients :  ahm = 1/2  Uv*Lv   (lap case) 
+   !                                !                            or  = 1/12 Uv*Lv^3 (blp case)
+/
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_zdfosm   = .true.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   ln_zdftke = .false.
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.    !  enhanced vertical diffusion
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
+!-----------------------------------------------------------------------
+   !
+   nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to NIWs
+                              !        = 0 none ; = 1 add a tke source below the ML
+                              !        = 2 add a tke source just at the base of the ML
+                              !        = 3 as = 1 applied on HF part of the stress           (ln_cpl=T)
+/
+!-----------------------------------------------------------------------
+&namzdf_gls    !   GLS vertical diffusion                               (ln_zdfgls =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_osm    !   OSM vertical diffusion                               (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+   ln_use_osm_la = .false.      !  Use namelist  rn_osm_la
+   rn_osm_la     = 0.3         !  Turbulent Langmuir number
+   rn_osm_dstokes     = 5.     !  Depth scale of Stokes drift (m)
+   nn_ave = 0                  ! choice of horizontal averaging on avt, avmu, avmv
+   ln_dia_osm = .true.         ! output OSMOSIS-OBL variables
+   rn_osm_hbl0 = 10.           ! initial hbl value
+   ln_kpprimix = .true.        ! Use KPP-style Ri# mixing below BL
+   rn_riinfty  = 0.7           ! Highest local Ri_g permitting shear instability
+   rn_difri  =  0.005          ! max Ri# diffusivity at Ri_g = 0 (m^2/s)
+   ln_convmix  = .true.        ! Use convective instability mixing below BL
+   rn_difconv = 1. !0.01 !1.             ! diffusivity when unstable below BL  (m2/s)
+   nn_osm_wave = 2             ! Method used to calculate Stokes drift
+                               !  = 2: Use ECMWF wave fields
+                               !  = 1: Pierson Moskowitz wave spectrum
+                               !  = 0: Constant La# = 0.3
+!========================only if key_FK_osm is set =================================
+   ln_osm_mle = .true.        !  Use integrated FK-OSM model
+/
+!-----------------------------------------------------------------------
+&namosm_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
+   rn_osm_mle_ce       = 0.04      ! magnitude of the MLE (typical value: 0.06 to 0.08)
+   nn_osm_mle      = 0         ! MLE type: =0 standard Fox-Kemper ; =1 new formulation
+   rn_osm_mle_lf       = 5.e+3     ! typical scale of mixed layer front (meters)                      (case rn_osm_mle=0)
+   rn_osm_mle_time     = 43200 !172800.   ! time scale for mixing momentum across the mixed layer (seconds)  (case rn_osm_mle=0)
+   rn_osm_mle_lat      = 20.       ! reference latitude (degrees) of MLE coef.                        (case rn_mle=1)
+   rn_osm_mle_rho_c = 0.03 ! 0.01      ! delta rho criterion used to calculate MLD for FK
+   rn_osm_mle_thresh = 0.0001      ! delta b criterion used for FK MLD criterion
+   rn_osm_mle_tau     = 172800.   ! time scale for FK-OSM (seconds)  (case rn_osm_mle=0)
+!========================only if key_FK_osm is set =================================
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi")
+!-----------------------------------------------------------------------
+  ln_nnogather = .true.  !  activate code to avoid mpi_allgather use at the northfold
+  jpni         = 16 !12 !16 !12 !16 !12 !16      ! 12 jpni   number of processors following i (set automatically if < 1)
+  jpnj         = 15 !6 !15 !6 !15 !6 ! 15      ! 8 jpnj   number of processors following j (set automatically if < 1)
+/
+!-----------------------------------------------------------------------
+&namctl        !   Control prints 
+!-----------------------------------------------------------------------
+   ln_ctl = .false.                 ! Toggle all report printing on/off (T/F); Ignored if sn_cfctl%l_config is T
+/
+!-----------------------------------------------------------------------
+&namsto        ! Stochastic parametrization of EOS                      (default: NO)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtrd        !   trend diagnostics                                    (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namptr        !   Poleward Transport Diagnostic                        (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namhsb        !  Heat and salt budgets                                 (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namhth        !  Extra ML depth and thermocline depth diagnostics      (default F)
+!-----------------------------------------------------------------------
+   ln_diahth   = .true.   !  produce extra diagnostics of BL and thermocline depth
+/
+!-----------------------------------------------------------------------
+&namdiu        !   Cool skin and warm layer models                      (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namflo        !   float parameters                                     ("key_float")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diaharm   !   Harmonic analysis of tidal constituents              ("key_diaharm")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdct        ! transports through some sections                       ("key_diadct")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diatmb    !  Top Middle Bottom Output                              (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_dia25h    !  25h Mean Output                                       (default F)
+!-----------------------------------------------------------------------
+   ln_dia25h   = .false.   ! Choose 25h mean output or not
+/
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_cfg_start_N
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_cfg_start_N	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_cfg_start_N	(revision 13402)
@@ -0,0 +1,530 @@
+!-----------------------------------------------------------------------
+&namrun        !   parameters of the run
+!-----------------------------------------------------------------------
+   nn_no       =       0   !  job number (no more used...)
+   cn_exp      =  "eORCA1L3_OSM_N"  !  experience name
+   nn_it000    =       1 !8993 !33 !8992   !  first time step
+   nn_itend    =     35040 !72 !35040 !35040 !6 4 !11680 !32 !2464 !35040  !64 !9000 !116800  !  last  time step (std 5475)
+   nn_date0    =  19800101 !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_leapy    =       0   !  Leap year calendar (1) or not (0)
+   ln_rstart   = .false. !.false.   !  start from rest (F) or from a restart file (T)
+   !
+   nn_rstctl   =   2 !0 ! 2            !  restart control ==> activated only if ln_rstart=T
+   cn_ocerst_in    =  "restart"  ! "eORCA1L3_OSM_no_w_00000032_restart" !  suffix of ocean restart name (input)
+   cn_ocerst_indir = "RESTARTS"         !  directory from which to read input ocean restarts
+   cn_ocerst_outdir = "RESTARTS"         !  directory from which to read input ocean restarts
+   nn_istate   =      0 !1   !  output the initial state (1) or not (0)
+   ln_rst_list = .false.   !  output restarts at list of times using nn_stocklist (T) or at set frequency with nn_stock (F)
+   nn_stock    =    11680 !8892 ! 32 !8892 !11680   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_stocklist = 8892,11680,0,0,0,0,0,0 ! List of timesteps when a restart file is to be written
+   nn_write    =    11680   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
+   ln_cfmeta   = .false.   !  output additional data to netCDF files required for compliance with the CF metadata standard
+   nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
+/
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration                      (default: user defined GYRE)
+!-----------------------------------------------------------------------
+   ln_read_cfg = .true.    !  (=T) read the domain configuration file
+      !                    !  (=F) user defined configuration  ==>>>  see usrdef(_...) modules
+      cn_domcfg = "eORCA_R1_zps_domcfg"    ! domain configuration filename
+/
+!-----------------------------------------------------------------------
+&namdom        !   time and space domain
+!-----------------------------------------------------------------------
+   rn_rdt      =  2700.     !  time step for the dynamics 
+   ln_meshmask = .false. !.true.    ! create meshfile  
+/
+!-----------------------------------------------------------------------
+&namtsd        !   data : Temperature  & Salinity
+!-----------------------------------------------------------------------
+   !                       ! =T  read T-S fields for:
+   ln_tsd_init = .true.         !  ocean initialisation
+   ln_tsd_dmp  = .false.         !  T-S restoring   (see namtra_dmp)
+   
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the T-S data location
+   !___________!_________________________!___________________!___________!_____________!________!___________!__________________!__________!_______________!
+   !           !  file name              ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights filename ! rotation ! land/sea mask !
+   !           !                         !  (if <0  months)  !   name    !   (logical) !  (T/F) ! 'monthly' !                  ! pairing  !    filename   !
+   sn_tem  = 'conservative_temperature_WOA13_decav_Reg1L75_clim', -1 ,'votemper' , .true. , .true. , 'yearly' , 'weights_3D_WOA13d1_2_eorca1_bilinear.nc'  ,   ''    ,    ''
+   sn_sal  = 'absolute_salinity_WOA13_decav_Reg1L75_clim'       , -1 ,'vosaline' , .true. , .true. , 'yearly' , 'weights_3D_WOA13d1_2_eorca1_bilinear.nc'  ,   ''    ,    ''
+/
+!-----------------------------------------------------------------------
+&namwad        !   Wetting and drying  default is no WAD
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namcrs        !   coarsened grid (for outputs and/or TOP)              (ln_crs =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namc1d_dyndmp !   U & V newtonian damping                              ("key_c1d")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc        !   Surface Boundary Condition (surface module)
+!-----------------------------------------------------------------------
+   nn_fsbc     = 1         !  frequency of surface boundary condition computation
+                           !     (also = the frequency of sea-ice & iceberg model call)
+                     ! Type of air-sea fluxes 
+   ln_blk      = .true.    !  Bulk formulation                          (T => fill namsbc_blk )
+   nn_ice      = 2         !  =0 no ice boundary condition    
+                           !  =1 use observed ice-cover                 (  => fill namsbc_iif )
+                           !  =2 or 3 automatically for LIM3 or CICE    ("key_lim3" or "key_cice")
+                           !          except in AGRIF zoom where it has to be specified
+   ln_ice_embd = .false.   !  =T embedded sea-ice (pressure + mass and salt exchanges)
+                           !  =F levitating ice (no pressure, mass and salt exchanges)
+                     ! Misc. options of sbc : 
+   ln_traqsr   = .true.    !  Light penetration in the ocean            (T => fill namtra_qsr)
+   ln_dm2dc    = .true.   !  daily mean to diurnal cycle on short wave
+   ln_rnf      = .true.    !  runoffs                                   (T => fill namsbc_rnf)
+   ln_ssr      = .true.    !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
+   nn_fwb      = 2         !  FreshWater Budget: =0 unchecked
+                           !     =1 global mean of e-p-r set to zero at each time step
+                           !     =2 annual global mean of e-p-r set to zero
+   ln_isf      = .true.   !  ice shelf                                 (T   => fill namsbc_isf)
+   ln_wave     = .true.   !  Activate coupling with wave  (T => fill namsbc_wave)
+   ln_cdgw     = .false.   !  Neutral drag coefficient read from wave model (T => ln_wave=.true. & fill namsbc_wave)
+   ln_sdw      = .true. !.false.   !  Read 2D Surf Stokes Drift & Computation of 3D stokes drift (T => ln_wave=.true. & fill namsbc_wave) 
+   nn_sdrift   =  1        !  Parameterization for the calculation of 3D-Stokes drift from the surface Stokes drift
+                           !   = 0 Breivik 2015 parameterization: v_z=v_0*[exp(2*k*z)/(1-8*k*z)]
+                           !   = 1 Phillips:                      v_z=v_o*[exp(2*k*z)-beta*sqrt(-2*k*pi*z)*erfc(sqrt(-2*k*z))]
+                           !   = 2 Phillips as (1) but using the wave frequency from a wave model
+   ln_tauwoc    = .false.   !  Activate ocean stress modified by external wave induced stress (T => ln_wave=.true. & fill namsbc_wave)
+   ln_stcor    = .true.   !  Activate Stokes Coriolis term (T => ln_wave=.true. & ln_sdw=.true. & fill namsbc_wave)
+   nn_lsm      = 0         !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
+                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
+/
+!-----------------------------------------------------------------------
+&namsbc_flx    !   surface boundary condition : flux formulation
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_blk   !   namsbc_blk  generic Bulk formula                      (ln_blk =T)
+!-----------------------------------------------------------------------
+!              !  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_wndi     = 'u_10_core_oonly'       ,         6         , 'U_10_MOD',   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bicubic.nc'  , 'U1'    , ''
+   sn_wndj     = 'v_10_core_oonly'       ,         6         , 'V_10_MOD',   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bicubic.nc'  , 'V1'    , ''
+   sn_qsr      = 'rad_core_oonly'        ,        24         , 'SWDN_MOD',   .false.    ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_qlw      = 'rad_core_oonly'        ,        24         , 'LWDN_MOD',   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_tair     = 't_10_core_oonly'       ,         6         , 'T_10_MOD',   .false.    ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_humi     = 'q_10_core_oonly'       ,         6         , 'Q_10_MOD',   .false.    ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_prec     = 'tprecip_core_oonly'    ,        -1         , 'TPRECIP' ,   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_snow     = 'tprecip_core_oonly'    ,        -1         , 'SNOW'    ,   .true.     ,  .false. , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   sn_slp      = 'slp_core_oonly'        ,         6         , 'SLP'     ,   .true.     , .false.  , 'yearly'  , 'weights_coreII_2_eorca1_bilinear.nc' , ''      , ''
+   ln_NCAR     = .true.   ! "NCAR"      algorithm   (Large and Yeager 2008)
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/IAF_CORE/'      !  root directory for the location of the flux files
+/
+!-----------------------------------------------------------------------
+&namsbc_cpl    !   coupled ocean/atmosphere model                       ("key_oasis3")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_sas    !   Stand-Alone Surface boundary condition
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_iif    !   Ice-IF : use observed ice cover                      (nn_ice = 1)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr =T)
+!-----------------------------------------------------------------------
+!              !  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_chl      ='merged_ESACCI_BIOMER4V1R1_CHL_REG05',  -1  , 'CHLA' , .true. , .true. , 'yearly' , 'weights_reg05_2_eorca1_bilinear.nc' , '' , ''
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+   ln_qsr_rgb  = .false.   !  RGB (Red-Green-Blue) light penetration
+   ln_qsr_2bd  = .true.  !  2 bands              light penetration
+   ln_qsr_bio  = .false.  !  bio-model light penetration
+   nn_chldta   =      1    !  RGB : Chl data (=1) or cst value (=0)
+   rn_abs      =   0.58    !  RGB & 2 bands: fraction of light (rn_si1)
+   rn_si0      =   0.35    !  RGB & 2 bands: shortess depth of extinction
+   rn_si1      =   23.0    !  2 bands: longest depth of extinction
+/
+!-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf =T)
+!-----------------------------------------------------------------------
+!              !  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_rnf      = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc',        -1         , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc',         0         , 'socoeff' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+   ln_rnf_mouth = .false.    !  specific treatment at rivers mouths
+   ln_rnf_depth = .false.    !  read in depth information for runoff
+   ln_rnf_tem   = .false.    !  read in temperature information for runoff
+   ln_rnf_sal   = .false.    !  read in salinity information for runoff
+   ln_rnf_depth_ini = .false. !.true. !  compute depth at initialisation from runoff file
+   rn_rnf_max   = 0.05       !  max value of the runoff climatology over global domain ( if ln_rnf_depth_ini = .true )
+   rn_dep_max = 150.         !  depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
+   nn_rnf_depth_file = 0     ! create (=1) a runoff depth file or not (=0)
+/
+!-----------------------------------------------------------------------
+&namsbc_isf    !  Top boundary layer (ISF)                              (nn_isf >0)
+!-----------------------------------------------------------------------
+!              ! 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_rnfisf     = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ,   -12             ,'sornfisf'     , .false. , .true. , 'yearly'  ,  ''     ,   ''     ,  ''
+   sn_depmax_isf = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ,   -12             ,'sodepmax_isf' , .false. , .true. , 'yearly'  ,  ''     ,   ''     ,  ''
+   sn_depmin_isf = 'runoff-icb_DaiTrenberth_Depoorter_eORCA1_JD.nc' ,   -12             ,'sodepmin_isf' , .false. , .true. , 'yearly'  ,  ''     ,   ''     ,  ''
+   nn_isf      = 3         !  ice shelf melting/freezing
+                           !  1 = presence of ISF    2 = bg03 parametrisation 
+                           !  3 = rnf file for isf   4 = ISF fwf specified
+                           !  option 1 and 4 need ln_isfcav = .true. (domzgr)
+/
+!-----------------------------------------------------------------------
+&namsbc_iscpl  !   land ice / ocean coupling option                     
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_apr    !   Atmospheric pressure used as ocean forcing           (ln_apr_dyn =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr =T)
+!-----------------------------------------------------------------------
+!              ! 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_sss      = 'sss_absolute_salinity_WOA13_decav_Reg1L75_clim', -1. , 'sosaline', .true. , .true. , 'yearly' , 'weights_WOA13d1_2_eorca1_bilinear.nc' , '' , ''
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+      rn_deds     =  -166.67  !  magnitude of the damping on salinity   [mm/day]
+      ln_sssr_bnd =  .true.   !  flag to bound erp term (associated with nn_sssr=2)
+      rn_sssr_bnd =   4.e0    !  ABS(Max/Min) value of the damping erp term [mm/day]
+/
+!-----------------------------------------------------------------------
+&namsbc_wave   ! External fields from wave model                        (ln_wave=T)
+!-----------------------------------------------------------------------
+!              !  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_cdg      =  'sdw_wave' ,        1          , 'drag_coeff' ,     .true.   , .false. , 'yearly'   ,  ''      , ''       , ''
+   sn_usd      =  'ust' ,        6          , 'ust'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bicubic.nc'    , 'U1'     , ''
+   sn_vsd      =  'vst' ,        6          , 'vst'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bicubic.nc'    , 'V1'     , ''
+   sn_hsw      =  'swh' ,        6          , 'swh'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bilin.nc'      , ''       , ''
+   sn_wmp      =  'mwp' ,        6          , 'mwp'     ,     .true.   , .false. , 'monthly'   ,  'weights_grid05_eORCA1_bilin.nc'      , ''       , ''
+!   sn_wnum     =  'sdw_wave' ,        1          , 'wave_num'   ,     .true.   , .false. , 'yearly'   ,  ''      , ''       , ''
+!   sn_tauoc    =  'sdw_wave' ,        1          , 'wave_stress',     .true.   , .false. , 'yearly'   ,  ''      , ''       , ''
+!
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/ERA_INTERIM/WAVES/'      !  root directory for the location of the flux files
+/
+!-----------------------------------------------------------------------
+&namberg       !   iceberg parameters                                   (default: No iceberg)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namlbc        !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+   !                       !  free slip  !   partial slip  !   no slip   ! strong slip
+   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
+   ln_vorlat   = .false.   !  consistency of vorticity boundary condition with analytical Eqs.
+/
+!-----------------------------------------------------------------------
+&namagrif      !  AGRIF zoom                                            ("key_agrif")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_tide      !   tide parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_dta    !  open boundaries - external data
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambdy_tide   !  tidal forcing at open boundaries
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdrg        !   top/bottom drag coefficient                          (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_lin = .true.    !   linear  drag: Cd = Cd0 Uc0
+/
+!-----------------------------------------------------------------------
+&namdrg_top    !   TOP friction                                         (ln_isfcav=T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdrg_bot        !   BOTTOM friction
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+!              !  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_qgh      ='Goutorbe_ghflux.nc',  -12.  , 'gh_flux'    ,   .false.     , .true. , 'yearly'  , 'weights_Goutorbe1_2_eorca1_bilinear.nc'       , ''       , ''
+   !
+   ln_trabbc   = .true.   !  Apply a geothermal heating at the ocean bottom
+      nn_geoflx   =    2      !  geothermal heat flux: = 0 no flux
+      !                       !     = 1 constant flux
+      !                       !     = 2 variable flux (read in geothermal_heating.nc in mW/m2)
+      rn_geoflx_cst = 86.4e-3 !  Constant value of geothermal heat flux [W/m2]
+   cn_dir      = '/hpcdata/scratch/agn/OSMOSIS/FORCING/SHACONEMO_eORCA_LIM3/'      !  root directory for the location of the flux files
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         (default: NO)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nameos        !   ocean Equation Of Seawater                           (default: NO)
+!-----------------------------------------------------------------------
+   ln_teos10    = .true.         !  = Use TEOS-10 equation of state
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer                          (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_traadv_fct = .true. !  FCT scheme
+      nn_fct_h   =  2            !  =2/4, horizontal 2nd / 4th order 
+      nn_fct_v   =  2            !  =2/4, vertical   2nd / COMPACT 4th order 
+/
+!-----------------------------------------------------------------------
+&namtra_mle !   mixed layer eddy parametrisation (Fox-Kemper param) (default: NO)
+!-----------------------------------------------------------------------
+   ln_mle      = .true.   ! (T) use the Mixed Layer Eddy (MLE) parameterisation
+   rn_ce       = 0.04      ! magnitude of the MLE (typical value: 0.06 to 0.08)
+
+/
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers
+!----------------------------------------------------------------------------------
+   !                       !  Operator type:
+   ln_traldf_lap   =  .true.   !    laplacian operator
+   ln_traldf_blp   =  .false.  !  bilaplacian operator
+   !
+   !                       !  Direction of action:
+   ln_traldf_iso   =  .true.  !  iso-neutral (standard operator)
+   ln_traldf_triad =  .false.  !  iso-neutral (triad    operator)
+   !
+   !		       	         !  iso-neutral options:        
+   ln_traldf_msc   =  .true.   !  Method of Stabilizing Correction (both operators)
+   rn_slpmax       =   0.01    !  slope limit                      (both operators)
+   ln_triad_iso    =  .false.  !  pure horizontal mixing in ML              (triad only)
+   rn_sw_triad     =  1        !  =1 switching triad ; =0 all 4 triads used (triad only)
+   ln_botmix_triad =  .false.  !  lateral mixing on bottom                  (triad only)
+   !
+   !                       !  Coefficients:
+   nn_aht_ijk_t    = 20        !  space/time variation of eddy coefficient:
+      !                             !   =-20 (=-30)    read in eddy_diffusivity_2D.nc (..._3D.nc) file
+      !                             !   =  0           constant 
+      !                             !   = 10 F(k)      =ldf_c1d 
+      !                             !   = 20 F(i,j)    =ldf_c2d 
+      !                             !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
+      !                             !   = 30 F(i,j,k)  =ldf_c2d * ldf_c1d
+      !                             !   = 31 F(i,j,k,t)=F(local velocity and grid-spacing)
+      !                        !  time invariant coefficients:  aht0 = 1/2  Ud*Ld   (lap case) 
+      !                             !                           or   = 1/12 Ud*Ld^3 (blp case)
+/
+!-----------------------------------------------------------------------
+&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
+!-----------------------------------------------------------------------
+    ln_ldfeiv     = .true. ! use eddy induced velocity parameterization
+      rn_aeiv_0     = 1000.   ! eddy induced velocity coefficient   [m2/s]
+      nn_aei_ijk_t  = 21      ! space/time variation of the eiv coeficient
+      !                             !   =-20 (=-30)    read in eddy_induced_velocity_2D.nc (..._3D.nc) file
+      !                             !   =  0           constant 
+      !                             !   = 10 F(k)      =ldf_c1d 
+      !                             !   = 20 F(i,j)    =ldf_c2d 
+      !                             !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
+      !                             !   = 30 F(i,j,k)  =ldf_c2d + ldf_c1d
+      ln_ldfeiv_dia =.true.  ! diagnose eiv stream function and velocities
+/
+!-----------------------------------------------------------------------
+&namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
+!-----------------------------------------------------------------------
+   ln_tradmp   =  .false.
+/
+!-----------------------------------------------------------------------
+&nam_vvl       !   vertical coordinate options                          (default: z-star)
+!-----------------------------------------------------------------------
+   ln_vvl_zstar  = .true.           !  z-star vertical coordinate
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_vec = .true. !  vector form - 2nd centered scheme
+     nn_dynkeg     = 0        ! grad(KE) scheme: =0   C2  ;  =1   Hollingsworth correction
+   ln_dynadv_cen2 = .false. !  flux form - 2nd order centered scheme
+/
+!-----------------------------------------------------------------------
+&namdyn_vor    !   Vorticity / Coriolis scheme                          (default: NO)
+!-----------------------------------------------------------------------
+   ln_dynvor_een = .true.  !  energy & enstrophy scheme
+      nn_een_e3f = 1             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
+/
+!-----------------------------------------------------------------------
+&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_hpg_sco  = .true.   !  s-coordinate (standard jacobian formulation)
+/
+!-----------------------------------------------------------------------
+&namdyn_spg    !   surface pressure gradient                            (default: NO)
+!-----------------------------------------------------------------------
+   ln_dynspg_ts   = .true.   ! split-explicit free surface
+      ln_bt_fw      = .false.     ! Forward integration of barotropic Eqs.
+      ln_bt_av      = .true.     ! Time filtering of barotropic variables
+         nn_bt_flt     = 1          ! Time filter choice  = 0 None
+         !                          !                     = 1 Boxcar over   nn_baro sub-steps
+         !                          !                     = 2 Boxcar over 2*nn_baro  "    "
+      ln_bt_auto    = .true.     ! Number of sub-step defined from:
+         rn_bt_cmax   =  0.8        ! =T : the Maximum Courant Number allowed
+         nn_baro      = 30          ! =F : the number of sub-step in rn_rdt seconds
+      rn_bt_alpha   = 0.         ! Temporal diffusion parameter (if ln_bt_av=F)
+/
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       !  Type of the operator :
+   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_lap =  .true.     !    laplacian operator
+   !                       !  Direction of action  :
+   ln_dynldf_lev =  .true.     !  iso-level
+   !                       !  Coefficient
+   nn_ahm_ijk_t  =  30         !  space/time variation of eddy coef
+   !                                !  =-30  read in eddy_viscosity_3D.nc file
+   !                                !  =-20  read in eddy_viscosity_2D.nc file
+   !                                !  =  0  constant 
+   !                                !  = 10  F(k)=c1d
+   !                                !  = 20  F(i,j)=F(grid spacing)=c2d
+   !                                !  = 30  F(i,j,k)=c2d*c1d
+   !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
+   !                                !  = 32  F(i,j,k)=F(local gridscale and deformation rate)
+   !                           !  time invariant coefficients :  ahm = 1/2  Uv*Lv   (lap case) 
+   !                                !                            or  = 1/12 Uv*Lv^3 (blp case)
+/
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_zdfosm   = .true.      !  OSMOSIS BL closure                     (T =>   fill namzdf_osm)
+   ln_zdftke = .false.
+   !
+   !                       ! convection
+   ln_zdfevd   = .false.    !  enhanced vertical diffusion
+   rn_avm0     =   1.2e-4     !  vertical eddy viscosity   [m2/s]       (background Kz if ln_zdfcst=F)
+   rn_avt0     =   1.2e-5     !  vertical eddy diffusivity [m2/s]       (background Kz if ln_zdfcst=F)
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       (ln_zdfric =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
+!-----------------------------------------------------------------------
+   !
+   nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to NIWs
+                              !        = 0 none ; = 1 add a tke source below the ML
+                              !        = 2 add a tke source just at the base of the ML
+                              !        = 3 as = 1 applied on HF part of the stress           (ln_cpl=T)
+/
+!-----------------------------------------------------------------------
+&namzdf_gls    !   GLS vertical diffusion                               (ln_zdfgls =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_osm    !   OSM vertical diffusion                               (ln_zdfosm =T)
+!-----------------------------------------------------------------------
+   ln_use_osm_la = .false.      !  Use namelist  rn_osm_la
+   rn_osm_la     = 0.3         !  Turbulent Langmuir number
+   rn_osm_dstokes     = 5.     !  Depth scale of Stokes drift (m)
+   nn_ave = 0                  ! choice of horizontal averaging on avt, avmu, avmv
+   ln_dia_osm = .true.         ! output OSMOSIS-OBL variables
+   rn_osm_hbl0 = 10.           ! initial hbl value
+   ln_kpprimix = .true.        ! Use KPP-style Ri# mixing below BL
+   rn_riinfty  = 0.7           ! Highest local Ri_g permitting shear instability
+   rn_difri  =  0.005          ! max Ri# diffusivity at Ri_g = 0 (m^2/s)
+   ln_convmix  = .true.        ! Use convective instability mixing below BL
+   rn_difconv = 1. !0.01 !1.             ! diffusivity when unstable below BL  (m2/s)
+   nn_osm_wave = 2             ! Method used to calculate Stokes drift
+                               !  = 2: Use ECMWF wave fields
+                               !  = 1: Pierson Moskowitz wave spectrum
+                               !  = 0: Constant La# = 0.3
+!========================only if key_FK_osm is set =================================
+   ln_osm_mle = .true.        !  Use integrated FK-OSM model
+/
+!-----------------------------------------------------------------------
+&namosm_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
+   rn_osm_mle_ce       = 0.04      ! magnitude of the MLE (typical value: 0.06 to 0.08)
+   nn_osm_mle      = 0         ! MLE type: =0 standard Fox-Kemper ; =1 new formulation
+   rn_osm_mle_lf       = 5.e+3     ! typical scale of mixed layer front (meters)                      (case rn_osm_mle=0)
+   rn_osm_mle_time     = 43200 !172800.   ! time scale for mixing momentum across the mixed layer (seconds)  (case rn_osm_mle=0)
+   rn_osm_mle_lat      = 20.       ! reference latitude (degrees) of MLE coef.                        (case rn_mle=1)
+   rn_osm_mle_rho_c = 0.03 ! 0.01      ! delta rho criterion used to calculate MLD for FK
+   rn_osm_mle_thresh = 0.0001      ! delta b criterion used for FK MLD criterion
+   rn_osm_mle_tau     = 172800.   ! time scale for FK-OSM (seconds)  (case rn_osm_mle=0)
+!========================only if key_FK_osm is set =================================
+/
+!-----------------------------------------------------------------------
+&namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi")
+!-----------------------------------------------------------------------
+  ln_nnogather = .true.  !  activate code to avoid mpi_allgather use at the northfold
+  jpni         = 16 !12 !16 !12 !16 !12 !16      ! 12 jpni   number of processors following i (set automatically if < 1)
+  jpnj         = 15 !6 !15 !6 !15 !6 ! 15      ! 8 jpnj   number of processors following j (set automatically if < 1)
+/
+!-----------------------------------------------------------------------
+&namctl        !   Control prints 
+!-----------------------------------------------------------------------
+   ln_ctl = .false.                 ! Toggle all report printing on/off (T/F); Ignored if sn_cfctl%l_config is T
+/
+!-----------------------------------------------------------------------
+&namsto        ! Stochastic parametrization of EOS                      (default: NO)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtrd        !   trend diagnostics                                    (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namptr        !   Poleward Transport Diagnostic                        (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namhsb        !  Heat and salt budgets                                 (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namhth        !  Extra ML depth and thermocline depth diagnostics      (default F)
+!-----------------------------------------------------------------------
+   ln_diahth   = .true.   !  produce extra diagnostics of BL and thermocline depth
+/
+!-----------------------------------------------------------------------
+&namdiu        !   Cool skin and warm layer models                      (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namflo        !   float parameters                                     ("key_float")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diaharm   !   Harmonic analysis of tidal constituents              ("key_diaharm")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdct        ! transports through some sections                       ("key_diadct")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_diatmb    !  Top Middle Bottom Output                              (default F)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_dia25h    !  25h Mean Output                                       (default F)
+!-----------------------------------------------------------------------
+   ln_dia25h   = .false.   ! Choose 25h mean output or not
+/
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_ice_cfg
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_ice_cfg	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/EXPREF/namelist_ice_cfg	(revision 13402)
@@ -0,0 +1,60 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! ESIM namelist:  
+!!              1 - Generic parameters                 (nampar)
+!!              2 - Ice thickness discretization       (namitd)
+!!              3 - Ice dynamics                       (namdyn)
+!!              4 - Ice ridging/rafting                (namdyn_rdgrft)
+!!              5 - Ice rheology                       (namdyn_rhg)
+!!              6 - Ice advection                      (namdyn_adv)
+!!              7 - Ice surface forcing                (namforcing)
+!!              8 - Ice thermodynamics                 (namthd)
+!!              9 - Ice heat diffusion                 (namthd_zdf)
+!!             10 - Ice lateral melting                (namthd_da)
+!!             11 - Ice growth in open water           (namthd_do)
+!!             12 - Ice salinity                       (namthd_sal)
+!!             13 - Ice melt ponds                     (namthd_pnd)
+!!             14 - Ice initialization                 (namini)
+!!             15 - Ice/snow albedos                   (namalb)
+!!             16 - Ice diagnostics                    (namdia)
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!------------------------------------------------------------------------------
+&nampar         !   Generic parameters
+!------------------------------------------------------------------------------
+   jpl              =   5             !  number of ice  categories
+   nlay_i           =   2             !  number of ice  layers
+   nlay_s           =   1             !  number of snow layers (only 1 is working)
+   ln_virtual_itd   =   .false.       !  virtual ITD mono-category parameterization (jpl=1 only)
+                                      !     i.e. enhanced thermal conductivity & virtual thin ice melting
+   ln_icedyn        = .true.          !  ice dynamics (T) or not (F)
+   ln_icethd        = .true.          !  ice thermo   (T) or not (F)
+   rn_amax_n        =   0.997         !  maximum tolerated ice concentration NH
+   rn_amax_s        =   0.997         !  maximum tolerated ice concentration SH
+   cn_icerst_in     = "restart_ice" ! suffix of ice restart name (input)
+   cn_icerst_out    = "restart_ice" !  suffix of ice restart name (output)
+   cn_icerst_indir  = "RESTARTS"           !  directory to read   input ice restarts
+   cn_icerst_outdir = "RESTARTS"           !  directory to write output ice restarts
+/
+!------------------------------------------------------------------------------
+&namitd     !   Ice discretization
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namdyn     !   Ice dynamics
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd     !   Ice thermodynamics
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namthd_sal     !   Ice salinity
+!------------------------------------------------------------------------------
+/
+!------------------------------------------------------------------------------
+&namdyn_adv     !   Ice advection
+!------------------------------------------------------------------------------
+   ln_adv_Pra       = .true.         !  Advection scheme (Prather)
+   ln_adv_UMx       = .false.          !  Advection scheme (Ultimate-Macho)
+      nn_UMx        =   5             !     order of the scheme for UMx (1-5 ; 20=centered 2nd order)
+/
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/cpp_eORCA1.fcm
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/cpp_eORCA1.fcm	(revision 13402)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/eORCA1/cpp_eORCA1.fcm	(revision 13402)
@@ -0,0 +1,1 @@
+bld::tool::fppkeys key_si3 key_mpp_mpi key_iomput
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/ref_cfgs.txt
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/ref_cfgs.txt	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/cfgs/ref_cfgs.txt	(revision 13402)
@@ -9,2 +9,3 @@
 ORCA2_ICE_PISCES OCE TOP ICE NST
 SPITZ12 OCE ICE
+eORCA1 OCE ICE
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/C1D/step_c1d.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/C1D/step_c1d.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/C1D/step_c1d.F90	(revision 13402)
@@ -58,5 +58,8 @@
 
                              indic = 0                ! reset to no error condition
-      IF( kstp == nit000 )   CALL iom_init( "nemo")   ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
+                             IF( kstp == nit000 )   THEN
+                                CALL iom_init( "nemo")   ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
+                                CALL dia_hth_init    ! extra ML depth diagnostics, thermocline depths
+                             END IF
       IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
                              CALL iom_setkt( kstp - nit000 + 1, "nemo" )   ! say to iom that we are at time step kstp
@@ -86,5 +89,5 @@
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                          CALL dia_wri( kstp )       ! ocean model: outputs
-      IF( lk_diahth  )   CALL dia_hth( kstp )       ! Thermocline depth (20°C)
+      IF( ll_diahth  )   CALL dia_hth( kstp )       ! Thermocline depth (20°C)
 
 
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/DIA/diahth.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/DIA/diahth.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/DIA/diahth.F90	(revision 13402)
@@ -5,13 +5,10 @@
    !!======================================================================
    !! History :  OPA  !  1994-09  (J.-P. Boulanger)  Original code
-   !!                 !  1996-11  (E. Guilyardi)  OPA8 
+   !!                 !  1996-11  (E. Guilyardi)  OPA8
    !!                 !  1997-08  (G. Madec)  optimization
-   !!                 !  1999-07  (E. Guilyardi)  hd28 + heat content 
+   !!                 !  1999-07  (E. Guilyardi)  hd28 + heat content
    !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
    !!            3.2  !  2009-07  (S. Masson) hc300 bugfix + cleaning + add new diag
-   !!----------------------------------------------------------------------
-#if   defined key_diahth
-   !!----------------------------------------------------------------------
-   !!   'key_diahth' :                              thermocline depth diag.
+   !!            4.0.1!  2020-01  (G. Nurser) remove need for key lk_diahth
    !!----------------------------------------------------------------------
    !!   dia_hth      : Compute varius diagnostics associated with the mixed layer
@@ -24,5 +21,4 @@
    USE lib_mpp         ! MPP library
    USE iom             ! I/O library
-   USE timing          ! preformance summary
 
    IMPLICIT NONE
@@ -30,13 +26,7 @@
 
    PUBLIC   dia_hth       ! routine called by step.F90
-   PUBLIC   dia_hth_alloc ! routine called by nemogcm.F90
-
-   LOGICAL , PUBLIC, PARAMETER ::   lk_diahth = .TRUE.    !: thermocline-20d depths flag
-   
-   ! note: following variables should move to local variables once iom_put is always used 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hth    !: depth of the max vertical temperature gradient [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hd20   !: depth of 20 C isotherm                         [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   hd28   !: depth of 28 C isotherm                         [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   htc3   !: heat content of first 300 m                    [W]
+   PUBLIC   dia_hth_init  ! routine called by nemogcm.F90
+
+   LOGICAL, PUBLIC ::   ll_diahth   !: Compute further diagnostics of ML and thermocline depth
 
    !!----------------------------------------------------------------------
@@ -47,306 +37,299 @@
 CONTAINS
 
-   FUNCTION dia_hth_alloc()
-      !!---------------------------------------------------------------------
-      INTEGER :: dia_hth_alloc
-      !!---------------------------------------------------------------------
+
+   SUBROUTINE dia_hth( kt )
+     !!---------------------------------------------------------------------
+     !!                  ***  ROUTINE dia_hth  ***
+     !!
+     !! ** Purpose : Computes
+     !!      the mixing layer depth (turbocline): avt = 5.e-4
+     !!      the depth of strongest vertical temperature gradient
+     !!      the mixed layer depth with density     criteria: rho = rho(10m or surf) + 0.03(or 0.01)
+     !!      the mixed layer depth with temperature criteria: abs( tn - tn(10m) ) = 0.2
+     !!      the top of the thermochine: tn = tn(10m) - ztem2
+     !!      the pycnocline depth with density criteria equivalent to a temperature variation
+     !!                rho = rho10m + (dr/dT)(T,S,10m)*(-0.2 degC)
+     !!      the barrier layer thickness
+     !!      the maximal verical inversion of temperature and its depth max( 0, max of tn - tn(10m) )
+     !!      the depth of the 20 degree isotherm (linear interpolation)
+     !!      the depth of the 28 degree isotherm (linear interpolation)
+     !!      the heat content of first 300 m
+     !!
+     !! ** Method :
+     !!-------------------------------------------------------------------
+     INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+     !!
+     INTEGER                          ::   ji, jj, jk            ! dummy loop arguments
+     INTEGER                          ::   iid, ilevel           ! temporary integers
+     INTEGER, DIMENSION(jpi,jpj) ::   ik20, ik28  ! levels
+     REAL(wp)                         ::   zavt5 = 5.e-4_wp      ! Kz criterion for the turbocline depth
+     REAL(wp)                         ::   zrho3 = 0.03_wp       ! density     criterion for mixed layer depth
+     REAL(wp)                         ::   zrho1 = 0.01_wp       ! density     criterion for mixed layer depth
+     REAL(wp)                         ::   ztem2 = 0.2_wp        ! temperature criterion for mixed layer depth
+     REAL(wp)                         ::   zthick_0, zcoef       ! temporary scalars
+     REAL(wp)                         ::   zztmp, zzdep          ! temporary scalars inside do loop
+     REAL(wp)                         ::   zu, zv, zw, zut, zvt  ! temporary workspace
+     REAL(wp), DIMENSION(jpi,jpj) ::   zabs2      ! MLD: abs( tn - tn(10m) ) = ztem2
+     REAL(wp), DIMENSION(jpi,jpj) ::   ztm2       ! Top of thermocline: tn = tn(10m) - ztem2
+     REAL(wp), DIMENSION(jpi,jpj) ::   zrho10_3   ! MLD: rho = rho10m + zrho3
+     REAL(wp), DIMENSION(jpi,jpj) ::   zpycn      ! pycnocline: rho = rho10m + (dr/dT)(T,S,10m)*(-0.2 degC)
+     REAL(wp), DIMENSION(jpi,jpj) ::   ztinv      ! max of temperature inversion
+     REAL(wp), DIMENSION(jpi,jpj) ::   zdepinv    ! depth of temperature inversion
+     REAL(wp), DIMENSION(jpi,jpj) ::   zrho0_3    ! MLD rho = rho(surf) = 0.03
+     REAL(wp), DIMENSION(jpi,jpj) ::   zrho0_1    ! MLD rho = rho(surf) = 0.01
+     REAL(wp), DIMENSION(jpi,jpj) ::   zmaxdzT    ! max of dT/dz
+     REAL(wp), DIMENSION(jpi,jpj) ::   zthick     ! vertical integration thickness
+     REAL(wp), DIMENSION(jpi,jpj) ::   zdelr      ! delta rho equivalent to deltaT = 0.2
+   ! note: following variables should move to local variables once iom_put is always used
+     REAL(wp), DIMENSION(jpi,jpj) ::   zhth    !: depth of the max vertical temperature gradient [m]
+     REAL(wp), DIMENSION(jpi,jpj) ::   zhd20   !: depth of 20 C isotherm                         [m]
+     REAL(wp), DIMENSION(jpi,jpj) ::   zhd28   !: depth of 28 C isotherm                         [m]
+     REAL(wp), DIMENSION(jpi,jpj) ::   zhtc3   !: heat content of first 300 m                    [W]
+
+     IF (iom_use("mlddzt") .OR. iom_use("mldr0_3") .OR. iom_use("mldr0_1")) THEN
+        ! ------------------------------------------------------------- !
+        ! thermocline depth: strongest vertical gradient of temperature !
+        ! turbocline depth (mixing layer depth): avt = zavt5            !
+        ! MLD: rho = rho(1) + zrho3                                     !
+        ! MLD: rho = rho(1) + zrho1                                     !
+        ! ------------------------------------------------------------- !
+        zmaxdzT(:,:) = 0._wp
+        IF( nla10 > 1 ) THEN
+           DO jj = 1, jpj
+              DO ji = 1, jpi
+                 zztmp = gdepw_n(ji,jj,mbkt(ji,jj)+1)
+                 zrho0_3(ji,jj) = zztmp
+                 zrho0_1(ji,jj) = zztmp
+                 zhth(ji,jj) = zztmp
+              END DO
+           END DO
+        ELSE IF (iom_use("mlddzt")) THEN
+           DO jj = 1, jpj
+              DO ji = 1, jpi
+                 zztmp = gdepw_n(ji,jj,mbkt(ji,jj)+1)
+                 zhth(ji,jj) = zztmp
+              END DO
+           END DO
+        ELSE
+           zhth(:,:) = 0._wp
+
+        ENDIF
+
+        DO jk = jpkm1, 2, -1   ! loop from bottom to 2
+           DO jj = 1, jpj
+              DO ji = 1, jpi
+                 !
+                 zzdep = gdepw_n(ji,jj,jk)
+                 zztmp = ( tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) ) / zzdep * tmask(ji,jj,jk)   ! vertical gradient of temperature (dT/dz)
+                 zzdep = zzdep * tmask(ji,jj,1)
+
+                 IF( zztmp > zmaxdzT(ji,jj) ) THEN
+                    zmaxdzT(ji,jj) = zztmp   ;   zhth    (ji,jj) = zzdep                ! max and depth of dT/dz
+                 ENDIF
+
+                 IF( nla10 > 1 ) THEN
+                    zztmp = rhop(ji,jj,jk) - rhop(ji,jj,1)                             ! delta rho(1)
+                    IF( zztmp > zrho3 )          zrho0_3(ji,jj) = zzdep                ! > 0.03
+                    IF( zztmp > zrho1 )          zrho0_1(ji,jj) = zzdep                ! > 0.01
+                 ENDIF
+
+              END DO
+           END DO
+        END DO
+
+        IF (iom_use("mlddzt")) CALL iom_put( "mlddzt", zhth*tmask(:,:,1) )            ! depth of the thermocline
+        IF( nla10 > 1 ) THEN
+           IF (iom_use("mldr0_3")) CALL iom_put( "mldr0_3", zrho0_3*tmask(:,:,1) )   ! MLD delta rho(surf) = 0.03
+           IF (iom_use("mldr0_1")) CALL iom_put( "mldr0_1", zrho0_1*tmask(:,:,1) )   ! MLD delta rho(surf) = 0.01
+        ENDIF
+     ENDIF
+
+     IF (iom_use("mld_dt02") .OR. iom_use("topthdep") .OR. iom_use("mldr10_3") .OR.  &
+          & iom_use("pycndep") .OR. iom_use("tinv") .OR. iom_use("depti")) THEN
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              zztmp = gdepw_n(ji,jj,mbkt(ji,jj)+1)
+              zabs2   (ji,jj) = zztmp
+              ztm2    (ji,jj) = zztmp
+              zrho10_3(ji,jj) = zztmp
+              zpycn   (ji,jj) = zztmp
+           END DO
+        END DO
+        ztinv  (:,:) = 0._wp
+        zdepinv(:,:) = 0._wp
+
+        IF (iom_use("pycndep")) THEN
+           ! Preliminary computation
+           ! computation of zdelr = (dr/dT)(T,S,10m)*(-0.2 degC)
+           DO jj = 1, jpj
+              DO ji = 1, jpi
+                 IF( tmask(ji,jj,nla10) == 1. ) THEN
+                    zu  =  1779.50 + 11.250 * tsn(ji,jj,nla10,jp_tem) - 3.80   * tsn(ji,jj,nla10,jp_sal)                             &
+                         &                                              - 0.0745 * tsn(ji,jj,nla10,jp_tem) * tsn(ji,jj,nla10,jp_tem)   &
+                         &                                              - 0.0100 * tsn(ji,jj,nla10,jp_tem) * tsn(ji,jj,nla10,jp_sal)
+                    zv  =  5891.00 + 38.000 * tsn(ji,jj,nla10,jp_tem) + 3.00   * tsn(ji,jj,nla10,jp_sal)                             &
+                         &                                              - 0.3750 * tsn(ji,jj,nla10,jp_tem) * tsn(ji,jj,nla10,jp_tem)
+                    zut =    11.25 -  0.149 * tsn(ji,jj,nla10,jp_tem) - 0.01   * tsn(ji,jj,nla10,jp_sal)
+                    zvt =    38.00 -  0.750 * tsn(ji,jj,nla10,jp_tem)
+                    zw  = (zu + 0.698*zv) * (zu + 0.698*zv)
+                    zdelr(ji,jj) = ztem2 * (1000.*(zut*zv - zvt*zu)/zw)
+                 ELSE
+                    zdelr(ji,jj) = 0._wp
+                 ENDIF
+              END DO
+           END DO
+        ELSE
+           zdelr(:,:) = 0._wp
+        ENDIF
+
+        ! ------------------------------------------------------------- !
+        ! MLD: abs( tn - tn(10m) ) = ztem2                              !
+        ! Top of thermocline: tn = tn(10m) - ztem2                      !
+        ! MLD: rho = rho10m + zrho3                                     !
+        ! pycnocline: rho = rho10m + (dr/dT)(T,S,10m)*(-0.2 degC)       !
+        ! temperature inversion: max( 0, max of tn - tn(10m) )          !
+        ! depth of temperature inversion                                !
+        ! ------------------------------------------------------------- !
+        DO jk = jpkm1, nlb10, -1   ! loop from bottom to nlb10
+           DO jj = 1, jpj
+              DO ji = 1, jpi
+                 !
+                 zzdep = gdepw_n(ji,jj,jk) * tmask(ji,jj,1)
+                 !
+                 zztmp = tsn(ji,jj,nla10,jp_tem) - tsn(ji,jj,jk,jp_tem)  ! - delta T(10m)
+                 IF( ABS(zztmp) > ztem2 )      zabs2   (ji,jj) = zzdep   ! abs > 0.2
+                 IF(     zztmp  > ztem2 )      ztm2    (ji,jj) = zzdep   ! > 0.2
+                 zztmp = -zztmp                                          ! delta T(10m)
+                 IF( zztmp >  ztinv(ji,jj) ) THEN                        ! temperature inversion
+                    ztinv(ji,jj) = zztmp   ;   zdepinv (ji,jj) = zzdep   ! max value and depth
+                 ENDIF
+
+                 zztmp = rhop(ji,jj,jk) - rhop(ji,jj,nla10)              ! delta rho(10m)
+                 IF( zztmp > zrho3        )    zrho10_3(ji,jj) = zzdep   ! > 0.03
+                 IF( zztmp > zdelr(ji,jj) )    zpycn   (ji,jj) = zzdep   ! > equi. delta T(10m) - 0.2
+                 !
+              END DO
+           END DO
+        END DO
+
+        IF (iom_use("mld_dt02")) CALL iom_put( "mld_dt02", zabs2*tmask(:,:,1)        )   ! MLD abs(delta t) - 0.2
+        IF (iom_use("topthdep")) CALL iom_put( "topthdep", ztm2*tmask(:,:,1)         )   ! T(10) - 0.2
+        IF (iom_use("mldr10_3")) CALL iom_put( "mldr10_3", zrho10_3*tmask(:,:,1)     )   ! MLD delta rho(10m) = 0.03
+        IF (iom_use("pycndep")) CALL iom_put( "pycndep" , zpycn*tmask(:,:,1)        )   ! MLD delta rho equi. delta T(10m) = 0.2
+        IF (iom_use("tinv")) CALL iom_put( "tinv"    , ztinv*tmask(:,:,1)        )   ! max. temp. inv. (t10 ref)
+        IF (iom_use("depti")) CALL iom_put( "depti"   , zdepinv*tmask(:,:,1)      )   ! depth of max. temp. inv. (t10 ref)
+     ENDIF
+
+     IF(iom_use("20d") .OR. iom_use("28d")) THEN
+        ! ----------------------------------- !
+        ! search deepest level above 20C/28C  !
+        ! ----------------------------------- !
+        ik20(:,:) = 1
+        ik28(:,:) = 1
+        DO jk = 1, jpkm1   ! beware temperature is not always decreasing with depth => loop from top to bottom
+           DO jj = 1, jpj
+              DO ji = 1, jpi
+                 zztmp = tsn(ji,jj,jk,jp_tem)
+                 IF( zztmp >= 20. )   ik20(ji,jj) = jk
+                 IF( zztmp >= 28. )   ik28(ji,jj) = jk
+              END DO
+           END DO
+        END DO
+
+        ! --------------------------- !
+        !  Depth of 20C/28C isotherm  !
+        ! --------------------------- !
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              !
+              zzdep = gdepw_n(ji,jj,mbkt(ji,jj)+1)       ! depth of the oean bottom
+              !
+              iid = ik20(ji,jj)
+              IF( iid /= 1 ) THEN
+                 zztmp =      gdept_n(ji,jj,iid  )   &                     ! linear interpolation
+                      &  + (    gdept_n(ji,jj,iid+1) - gdept_n(ji,jj,iid)                       )   &
+                      &  * ( 20.*tmask(ji,jj,iid+1) - tsn(ji,jj,iid,jp_tem)                       )   &
+                      &  / ( tsn(ji,jj,iid+1,jp_tem) - tsn(ji,jj,iid,jp_tem) + (1.-tmask(ji,jj,1)) )
+                 zhd20(ji,jj) = MIN( zztmp , zzdep) * tmask(ji,jj,1)       ! bound by the ocean depth
+              ELSE
+                 zhd20(ji,jj) = 0._wp
+              ENDIF
+              !
+              iid = ik28(ji,jj)
+              IF( iid /= 1 ) THEN
+                 zztmp =      gdept_n(ji,jj,iid  )   &                     ! linear interpolation
+                      &  + (    gdept_n(ji,jj,iid+1) - gdept_n(ji,jj,iid)                       )   &
+                      &  * ( 28.*tmask(ji,jj,iid+1) -    tsn(ji,jj,iid,jp_tem)                       )   &
+                      &  / (  tsn(ji,jj,iid+1,jp_tem) -    tsn(ji,jj,iid,jp_tem) + (1.-tmask(ji,jj,1)) )
+                 zhd28(ji,jj) = MIN( zztmp , zzdep ) * tmask(ji,jj,1)      ! bound by the ocean depth
+              ELSE
+                 zhd28(ji,jj) = 0._wp
+              ENDIF
+
+           END DO
+        END DO
+        CALL iom_put( "20d", zhd20 )   ! depth of the 20 isotherm
+        CALL iom_put( "28d", zhd28 )   ! depth of the 28 isotherm
+     ENDIF
+
+     ! ----------------------------- !
+     !  Heat content of first 300 m  !
+     ! ----------------------------- !
+     IF (iom_use("hc300")) THEN
+        ! find ilevel with (ilevel+1) the deepest W-level above 300m (we assume we can use e3t_1d to do this search...)
+        ilevel   = 0
+        zthick_0 = 0._wp
+        DO jk = 1, jpkm1
+           zthick_0 = zthick_0 + e3t_1d(jk)
+           IF( zthick_0 < 300. )   ilevel = jk
+        END DO
+        ! surface boundary condition
+        IF( ln_linssh ) THEN   ;   zthick(:,:) = sshn(:,:)   ;   zhtc3(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:) * tmask(:,:,1)
+        ELSE                   ;   zthick(:,:) = 0._wp       ;   zhtc3(:,:) = 0._wp
+        ENDIF
+        ! integration down to ilevel
+        DO jk = 1, ilevel
+           zthick(:,:) = zthick(:,:) + e3t_n(:,:,jk)
+           zhtc3  (:,:) = zhtc3  (:,:) + e3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) * tmask(:,:,jk)
+        END DO
+        ! deepest layer
+        zthick(:,:) = 300. - zthick(:,:)   !   remaining thickness to reach 300m
+        DO jj = 1, jpj
+           DO ji = 1, jpi
+              zhtc3(ji,jj) = zhtc3(ji,jj) + tsn(ji,jj,ilevel+1,jp_tem)                  &
+                   &                      * MIN( e3t_n(ji,jj,ilevel+1), zthick(ji,jj) ) * tmask(ji,jj,ilevel+1)
+           END DO
+        END DO
+        ! from temperature to heat contain
+        zcoef = rau0 * rcp
+        zhtc3(:,:) = zcoef * zhtc3(:,:)
+        CALL iom_put( "hc300", zhtc3*tmask(:,:,1) )      ! first 300m heat content
+     ENDIF
+     !
+   END SUBROUTINE dia_hth
+
+
+   SUBROUTINE dia_hth_init
+      !!---------------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_hth_init  ***
+      !!
+      !! ** Purpose: Initialization for ML and thermocline depths
+      !!
+      !! ** Action : If any upper ocean diagnostic required by xml file, set in dia_hth
+      !!---------------------------------------------------------------------------
+       !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'dia_hth_init : heat and salt budgets diagnostics'
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+      ENDIF
+      ll_diahth = iom_use("mlddzt") .OR. iom_use("mldr0_3") .OR. iom_use("mldr0_1") .OR.  &
+           & iom_use("mld_dt02") .OR. iom_use("topthdep") .OR. iom_use("mldr10_3") .OR.  &
+           & iom_use("pycndep") .OR. iom_use("tinv") .OR. iom_use("depti").OR. &
+           & iom_use("20d") .OR. iom_use("28d") .OR. iom_use("hc300")
+      IF(lwp) THEN
+         WRITE(numout,*) '   output upper ocean diagnostics (T) or not (F)       ll_diahth = ', ll_diahth
+      ENDIF
       !
-      ALLOCATE( hth(jpi,jpj), hd20(jpi,jpj), hd28(jpi,jpj), htc3(jpi,jpj), STAT=dia_hth_alloc )
-      !
-      CALL mpp_sum ( 'diahth', dia_hth_alloc )
-      IF(dia_hth_alloc /= 0)   CALL ctl_stop( 'STOP', 'dia_hth_alloc: failed to allocate arrays.' )
-      !
-   END FUNCTION dia_hth_alloc
-
-
-   SUBROUTINE dia_hth( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_hth  ***
-      !!
-      !! ** Purpose : Computes
-      !!      the mixing layer depth (turbocline): avt = 5.e-4
-      !!      the depth of strongest vertical temperature gradient
-      !!      the mixed layer depth with density     criteria: rho = rho(10m or surf) + 0.03(or 0.01)
-      !!      the mixed layer depth with temperature criteria: abs( tn - tn(10m) ) = 0.2       
-      !!      the top of the thermochine: tn = tn(10m) - ztem2 
-      !!      the pycnocline depth with density criteria equivalent to a temperature variation 
-      !!                rho = rho10m + (dr/dT)(T,S,10m)*(-0.2 degC) 
-      !!      the barrier layer thickness
-      !!      the maximal verical inversion of temperature and its depth max( 0, max of tn - tn(10m) )
-      !!      the depth of the 20 degree isotherm (linear interpolation)
-      !!      the depth of the 28 degree isotherm (linear interpolation)
-      !!      the heat content of first 300 m
-      !!
-      !! ** Method : 
-      !!-------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      !!
-      INTEGER                          ::   ji, jj, jk            ! dummy loop arguments
-      INTEGER                          ::   iid, ilevel           ! temporary integers
-      INTEGER, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ik20, ik28  ! levels
-      REAL(wp)                         ::   zavt5 = 5.e-4_wp      ! Kz criterion for the turbocline depth
-      REAL(wp)                         ::   zrho3 = 0.03_wp       ! density     criterion for mixed layer depth
-      REAL(wp)                         ::   zrho1 = 0.01_wp       ! density     criterion for mixed layer depth
-      REAL(wp)                         ::   ztem2 = 0.2_wp        ! temperature criterion for mixed layer depth
-      REAL(wp)                         ::   zthick_0, zcoef       ! temporary scalars
-      REAL(wp)                         ::   zztmp, zzdep          ! temporary scalars inside do loop
-      REAL(wp)                         ::   zu, zv, zw, zut, zvt  ! temporary workspace
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zabs2      ! MLD: abs( tn - tn(10m) ) = ztem2 
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ztm2       ! Top of thermocline: tn = tn(10m) - ztem2     
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zrho10_3   ! MLD: rho = rho10m + zrho3      
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zpycn      ! pycnocline: rho = rho10m + (dr/dT)(T,S,10m)*(-0.2 degC)
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ztinv      ! max of temperature inversion
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zdepinv    ! depth of temperature inversion
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zrho0_3    ! MLD rho = rho(surf) = 0.03
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zrho0_1    ! MLD rho = rho(surf) = 0.01
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zmaxdzT    ! max of dT/dz
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zthick     ! vertical integration thickness 
-      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zdelr      ! delta rho equivalent to deltaT = 0.2
-      !!----------------------------------------------------------------------
-      IF( ln_timing )   CALL timing_start('dia_hth')
-
-      IF( kt == nit000 ) THEN
-         !                                      ! allocate dia_hth array
-         IF( dia_hth_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_hth : unable to allocate standard arrays' )
-
-         IF(.NOT. ALLOCATED(ik20) ) THEN
-            ALLOCATE(ik20(jpi,jpj), ik28(jpi,jpj), &
-               &      zabs2(jpi,jpj),   &
-               &      ztm2(jpi,jpj),    &
-               &      zrho10_3(jpi,jpj),&
-               &      zpycn(jpi,jpj),   &
-               &      ztinv(jpi,jpj),   &
-               &      zdepinv(jpi,jpj), &
-               &      zrho0_3(jpi,jpj), &
-               &      zrho0_1(jpi,jpj), &
-               &      zmaxdzT(jpi,jpj), &
-               &      zthick(jpi,jpj),  &
-               &      zdelr(jpi,jpj), STAT=ji)
-            CALL mpp_sum('diahth', ji)
-            IF( ji /= 0 )   CALL ctl_stop( 'STOP', 'dia_hth : unable to allocate standard ocean arrays' )
-         END IF
-
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dia_hth : diagnostics of the thermocline depth'
-         IF(lwp) WRITE(numout,*) '~~~~~~~ '
-         IF(lwp) WRITE(numout,*)
-      ENDIF
-
-      ! initialization
-      ztinv  (:,:) = 0._wp  
-      zdepinv(:,:) = 0._wp  
-      zmaxdzT(:,:) = 0._wp  
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            zztmp = gdepw_n(ji,jj,mbkt(ji,jj)+1) 
-            hth     (ji,jj) = zztmp
-            zabs2   (ji,jj) = zztmp
-            ztm2    (ji,jj) = zztmp
-            zrho10_3(ji,jj) = zztmp
-            zpycn   (ji,jj) = zztmp
-        END DO
-      END DO
-      IF( nla10 > 1 ) THEN 
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zztmp = gdepw_n(ji,jj,mbkt(ji,jj)+1) 
-               zrho0_3(ji,jj) = zztmp
-               zrho0_1(ji,jj) = zztmp
-            END DO
-         END DO
-      ENDIF
-      
-      ! Preliminary computation
-      ! computation of zdelr = (dr/dT)(T,S,10m)*(-0.2 degC)
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            IF( tmask(ji,jj,nla10) == 1. ) THEN
-               zu  =  1779.50 + 11.250 * tsn(ji,jj,nla10,jp_tem) - 3.80   * tsn(ji,jj,nla10,jp_sal)                             &
-                  &                                              - 0.0745 * tsn(ji,jj,nla10,jp_tem) * tsn(ji,jj,nla10,jp_tem)   &
-                  &                                              - 0.0100 * tsn(ji,jj,nla10,jp_tem) * tsn(ji,jj,nla10,jp_sal)
-               zv  =  5891.00 + 38.000 * tsn(ji,jj,nla10,jp_tem) + 3.00   * tsn(ji,jj,nla10,jp_sal)                             &
-                  &                                              - 0.3750 * tsn(ji,jj,nla10,jp_tem) * tsn(ji,jj,nla10,jp_tem)
-               zut =    11.25 -  0.149 * tsn(ji,jj,nla10,jp_tem) - 0.01   * tsn(ji,jj,nla10,jp_sal)
-               zvt =    38.00 -  0.750 * tsn(ji,jj,nla10,jp_tem)
-               zw  = (zu + 0.698*zv) * (zu + 0.698*zv)
-               zdelr(ji,jj) = ztem2 * (1000.*(zut*zv - zvt*zu)/zw)
-            ELSE
-               zdelr(ji,jj) = 0._wp
-            ENDIF
-         END DO
-      END DO
-
-      ! ------------------------------------------------------------- !
-      ! thermocline depth: strongest vertical gradient of temperature !
-      ! turbocline depth (mixing layer depth): avt = zavt5            !
-      ! MLD: rho = rho(1) + zrho3                                     !
-      ! MLD: rho = rho(1) + zrho1                                     !
-      ! ------------------------------------------------------------- !
-      DO jk = jpkm1, 2, -1   ! loop from bottom to 2
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               !
-               zzdep = gdepw_n(ji,jj,jk)
-               zztmp = ( tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) ) / zzdep * tmask(ji,jj,jk)   ! vertical gradient of temperature (dT/dz)
-               zzdep = zzdep * tmask(ji,jj,1)
-
-               IF( zztmp > zmaxdzT(ji,jj) ) THEN                        
-                  zmaxdzT(ji,jj) = zztmp   ;   hth    (ji,jj) = zzdep                ! max and depth of dT/dz
-               ENDIF
-               
-               IF( nla10 > 1 ) THEN 
-                  zztmp = rhop(ji,jj,jk) - rhop(ji,jj,1)                             ! delta rho(1)
-                  IF( zztmp > zrho3 )          zrho0_3(ji,jj) = zzdep                ! > 0.03
-                  IF( zztmp > zrho1 )          zrho0_1(ji,jj) = zzdep                ! > 0.01
-               ENDIF
-
-            END DO
-         END DO
-      END DO
-      
-      CALL iom_put( "mlddzt", hth )            ! depth of the thermocline
-      IF( nla10 > 1 ) THEN 
-         CALL iom_put( "mldr0_3", zrho0_3 )   ! MLD delta rho(surf) = 0.03
-         CALL iom_put( "mldr0_1", zrho0_1 )   ! MLD delta rho(surf) = 0.01
-      ENDIF
-
-      ! ------------------------------------------------------------- !
-      ! MLD: abs( tn - tn(10m) ) = ztem2                              !
-      ! Top of thermocline: tn = tn(10m) - ztem2                      !
-      ! MLD: rho = rho10m + zrho3                                     !
-      ! pycnocline: rho = rho10m + (dr/dT)(T,S,10m)*(-0.2 degC)       !
-      ! temperature inversion: max( 0, max of tn - tn(10m) )          !
-      ! depth of temperature inversion                                !
-      ! ------------------------------------------------------------- !
-      DO jk = jpkm1, nlb10, -1   ! loop from bottom to nlb10
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               !
-               zzdep = gdepw_n(ji,jj,jk) * tmask(ji,jj,1)
-               !
-               zztmp = tsn(ji,jj,nla10,jp_tem) - tsn(ji,jj,jk,jp_tem)  ! - delta T(10m)
-               IF( ABS(zztmp) > ztem2 )      zabs2   (ji,jj) = zzdep   ! abs > 0.2
-               IF(     zztmp  > ztem2 )      ztm2    (ji,jj) = zzdep   ! > 0.2
-               zztmp = -zztmp                                          ! delta T(10m)
-               IF( zztmp >  ztinv(ji,jj) ) THEN                        ! temperature inversion
-                  ztinv(ji,jj) = zztmp   ;   zdepinv (ji,jj) = zzdep   ! max value and depth
-               ENDIF
-
-               zztmp = rhop(ji,jj,jk) - rhop(ji,jj,nla10)              ! delta rho(10m)
-               IF( zztmp > zrho3        )    zrho10_3(ji,jj) = zzdep   ! > 0.03
-               IF( zztmp > zdelr(ji,jj) )    zpycn   (ji,jj) = zzdep   ! > equi. delta T(10m) - 0.2
-               !
-            END DO
-         END DO
-      END DO
-
-      CALL iom_put( "mld_dt02", zabs2        )   ! MLD abs(delta t) - 0.2
-      CALL iom_put( "topthdep", ztm2         )   ! T(10) - 0.2
-      CALL iom_put( "mldr10_3", zrho10_3     )   ! MLD delta rho(10m) = 0.03
-      CALL iom_put( "pycndep" , zpycn        )   ! MLD delta rho equi. delta T(10m) = 0.2
-      CALL iom_put( "tinv"    , ztinv        )   ! max. temp. inv. (t10 ref) 
-      CALL iom_put( "depti"   , zdepinv      )   ! depth of max. temp. inv. (t10 ref) 
-
-
-      ! ----------------------------------- !
-      ! search deepest level above 20C/28C  !
-      ! ----------------------------------- !
-      ik20(:,:) = 1
-      ik28(:,:) = 1
-      DO jk = 1, jpkm1   ! beware temperature is not always decreasing with depth => loop from top to bottom
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zztmp = tsn(ji,jj,jk,jp_tem)
-               IF( zztmp >= 20. )   ik20(ji,jj) = jk
-               IF( zztmp >= 28. )   ik28(ji,jj) = jk
-            END DO
-         END DO
-      END DO
-
-      ! --------------------------- !
-      !  Depth of 20C/28C isotherm  !
-      ! --------------------------- !
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            !
-            zzdep = gdepw_n(ji,jj,mbkt(ji,jj)+1)       ! depth of the oean bottom
-            !
-            iid = ik20(ji,jj)
-            IF( iid /= 1 ) THEN 
-               zztmp =      gdept_n(ji,jj,iid  )   &                     ! linear interpolation
-                  &  + (    gdept_n(ji,jj,iid+1) - gdept_n(ji,jj,iid)                       )   &
-                  &  * ( 20.*tmask(ji,jj,iid+1) - tsn(ji,jj,iid,jp_tem)                       )   &
-                  &  / ( tsn(ji,jj,iid+1,jp_tem) - tsn(ji,jj,iid,jp_tem) + (1.-tmask(ji,jj,1)) )
-               hd20(ji,jj) = MIN( zztmp , zzdep) * tmask(ji,jj,1)       ! bound by the ocean depth
-            ELSE 
-               hd20(ji,jj) = 0._wp
-            ENDIF
-            !
-            iid = ik28(ji,jj)
-            IF( iid /= 1 ) THEN 
-               zztmp =      gdept_n(ji,jj,iid  )   &                     ! linear interpolation
-                  &  + (    gdept_n(ji,jj,iid+1) - gdept_n(ji,jj,iid)                       )   &
-                  &  * ( 28.*tmask(ji,jj,iid+1) -    tsn(ji,jj,iid,jp_tem)                       )   &
-                  &  / (  tsn(ji,jj,iid+1,jp_tem) -    tsn(ji,jj,iid,jp_tem) + (1.-tmask(ji,jj,1)) )
-               hd28(ji,jj) = MIN( zztmp , zzdep ) * tmask(ji,jj,1)      ! bound by the ocean depth
-            ELSE 
-               hd28(ji,jj) = 0._wp
-            ENDIF
-
-         END DO
-      END DO
-      CALL iom_put( "20d", hd20 )   ! depth of the 20 isotherm
-      CALL iom_put( "28d", hd28 )   ! depth of the 28 isotherm
-
-      ! ----------------------------- !
-      !  Heat content of first 300 m  !
-      ! ----------------------------- !
-
-      ! find ilevel with (ilevel+1) the deepest W-level above 300m (we assume we can use e3t_1d to do this search...)
-      ilevel   = 0
-      zthick_0 = 0._wp
-      DO jk = 1, jpkm1                      
-         zthick_0 = zthick_0 + e3t_1d(jk)
-         IF( zthick_0 < 300. )   ilevel = jk
-      END DO
-      ! surface boundary condition
-      IF( ln_linssh ) THEN   ;   zthick(:,:) = sshn(:,:)   ;   htc3(:,:) = tsn(:,:,1,jp_tem) * sshn(:,:) * tmask(:,:,1)  
-      ELSE                   ;   zthick(:,:) = 0._wp       ;   htc3(:,:) = 0._wp                                   
-      ENDIF
-      ! integration down to ilevel
-      DO jk = 1, ilevel
-         zthick(:,:) = zthick(:,:) + e3t_n(:,:,jk)
-         htc3  (:,:) = htc3  (:,:) + e3t_n(:,:,jk) * tsn(:,:,jk,jp_tem) * tmask(:,:,jk)
-      END DO
-      ! deepest layer
-      zthick(:,:) = 300. - zthick(:,:)   !   remaining thickness to reach 300m
-      DO jj = 1, jpj
-         DO ji = 1, jpi
-            htc3(ji,jj) = htc3(ji,jj) + tsn(ji,jj,ilevel+1,jp_tem)                  &
-               &                      * MIN( e3t_n(ji,jj,ilevel+1), zthick(ji,jj) ) * tmask(ji,jj,ilevel+1)
-         END DO
-      END DO
-      ! from temperature to heat contain
-      zcoef = rau0 * rcp
-      htc3(:,:) = zcoef * htc3(:,:)
-      CALL iom_put( "hc300", htc3 )      ! first 300m heat content
-      !
-      IF( ln_timing )   CALL timing_stop('dia_hth')
-      !
-   END SUBROUTINE dia_hth
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                       Empty module
-   !!----------------------------------------------------------------------
-   LOGICAL , PUBLIC, PARAMETER ::   lk_diahth = .FALSE.  !: thermocline-20d depths flag
-CONTAINS
-   SUBROUTINE dia_hth( kt )         ! Empty routine
-      IMPLICIT NONE
-      INTEGER, INTENT( in ) :: kt
-      WRITE(*,*) 'dia_hth: You should not have seen this print! error?', kt
-   END SUBROUTINE dia_hth
-#endif
-
-   !!======================================================================
+   END SUBROUTINE dia_hth_init
 END MODULE diahth
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/DIA/diawri.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/DIA/diawri.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/DIA/diawri.F90	(revision 13402)
@@ -43,4 +43,5 @@
    USE zdfdrg         ! ocean vertical physics: top/bottom friction
    USE zdfmxl         ! mixed layer
+   USE zdfosm         ! mixed layer
    !
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
@@ -926,4 +927,18 @@
          CALL iom_rstput( 0, 0, inum, 'sdvecrtz', wsd            )    ! now StokesDrift k-velocity
       ENDIF
+
+      IF( ln_zdfosm ) THEN
+         CALL iom_rstput( 0, 0, inum, 'hbl', hbl*tmask(:,:,1)   )    ! now boundary-layer depth
+         CALL iom_rstput( 0, 0, inum, 'hml', hml*tmask(:,:,1)    )    ! now mixed-layer depth
+         CALL iom_rstput( 0, 0, inum, 'avt_k', avt_k*wmask       )    ! w-level diffusion
+         CALL iom_rstput( 0, 0, inum, 'avm_k', avm_k*wmask       )    ! now w-level viscosity
+         CALL iom_rstput( 0, 0, inum, 'ghamt', ghamt*wmask       )    ! non-local t forcing
+         CALL iom_rstput( 0, 0, inum, 'ghams', ghams*wmask       )    ! non-local s forcing
+         CALL iom_rstput( 0, 0, inum, 'ghamu', ghamu*wmask       )    ! non-local u forcing
+         CALL iom_rstput( 0, 0, inum, 'ghamv', ghamu*wmask       )    ! non-local v forcing
+         IF( ln_osm_mle ) THEN
+            CALL iom_rstput( 0, 0, inum, 'hmle', hmle*tmask(:,:,1)   )    ! now transition-layer depth
+         END IF
+      ENDIF
  
 #if defined key_si3
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/IOM/iom.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/IOM/iom.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/IOM/iom.F90	(revision 13402)
@@ -856,4 +856,6 @@
       ELSE                         ;   llstop = .TRUE.
       ENDIF
+      WRITE(numout,*)'iom_varid 1: entering routine for variable '//TRIM(cdvar)
+      WRITE(numout,*)'iom_varid 1: kiomid = ',kiomid
       !
       IF( kiomid > 0 ) THEN
@@ -869,4 +871,7 @@
                ll_fnd  = ( TRIM(cdvar) == TRIM(iom_file(kiomid)%cn_var(iiv)) )
             END DO
+
+            WRITE(numout,*)'iom_varid 2: ll_fnd, iiv, nvars, llstop = ',ll_fnd, ' ', iiv, ' ', iom_file(kiomid)%nvars, ' ', llstop
+
             !
             IF( .NOT.ll_fnd ) THEN
@@ -878,4 +883,8 @@
                         &                      'increase the parameter jpmax_vars')
                ENDIF
+               WRITE(numout,*)'iom_varid: cdvar = '//TRIM(cdvar)
+               IF( PRESENT(ldstop) ) WRITE(numout,*)'iom_varid: ldstop = ',ldstop
+               WRITE(numout,*)'iom_varid: llstop = ',llstop
+               WRITE(numout,*)'iom_varid: iom_varid = ',iom_varid
                IF( llstop .AND. iom_varid == -1 )   CALL ctl_stop( TRIM(clinfo)//' not found' ) 
             ELSE
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/SBC/sbcblk.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/SBC/sbcblk.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/SBC/sbcblk.F90	(revision 13402)
@@ -124,4 +124,7 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   cdn_oce, chn_oce, cen_oce ! needed by Lupkes 2015 bulk scheme
 
+   LOGICAL  ::   ln_humi_dpt = .FALSE.                                        ! calculate specific hunidity from dewpoint
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qair                      ! specific humidity of air at input height
+
    INTEGER  ::   nblk           ! choice of the bulk algorithm
    !                            ! associated indices:
@@ -145,5 +148,5 @@
       !!-------------------------------------------------------------------
       ALLOCATE( Cd_atm (jpi,jpj), Ch_atm (jpi,jpj), Ce_atm (jpi,jpj), t_zu(jpi,jpj), q_zu(jpi,jpj), &
-         &      cdn_oce(jpi,jpj), chn_oce(jpi,jpj), cen_oce(jpi,jpj), STAT=sbc_blk_alloc )
+         &      cdn_oce(jpi,jpj), chn_oce(jpi,jpj), cen_oce(jpi,jpj), qair(jpi,jpj), STAT=sbc_blk_alloc )
       !
       CALL mpp_sum ( 'sbcblk', sbc_blk_alloc )
@@ -171,5 +174,5 @@
       NAMELIST/namsbc_blk/ sn_wndi, sn_wndj, sn_humi, sn_qsr, sn_qlw ,                &   ! input fields
          &                 sn_tair, sn_prec, sn_snow, sn_slp, sn_tdif,                &
-         &                 ln_NCAR, ln_COARE_3p0, ln_COARE_3p5, ln_ECMWF,             &   ! bulk algorithm
+         &                 ln_NCAR, ln_COARE_3p0, ln_COARE_3p5, ln_ECMWF, ln_humi_dpt,&   ! bulk algorithm
          &                 cn_dir , ln_taudif, rn_zqt, rn_zu,                         & 
          &                 rn_pfac, rn_efac, rn_vfac, ln_Cd_L12, ln_Cd_L15
@@ -323,4 +326,11 @@
       !
       !                                            ! compute the surface ocean fluxes using bulk formulea
+      ! ..... if dewpoint supplied instead of specific humidaity, calculate specific humidity
+      IF(ln_humi_dpt) THEN
+         qair(:,:) = q_sat( sf(jp_humi)%fnow(:,:,1), sf(jp_slp)%fnow(:,:,1) )
+      ELSE
+         qair(:,:) = sf(jp_humi)%fnow(:,:,1)
+      END IF
+      
       IF( MOD( kt - 1, nn_fsbc ) == 0 )   CALL blk_oce( kt, sf, sst_m, ssu_m, ssv_m )
 
@@ -332,5 +342,5 @@
          ENDIF 
          tatm_ice(:,:)    = sf(jp_tair)%fnow(:,:,1)
-         qatm_ice(:,:)    = sf(jp_humi)%fnow(:,:,1)
+         qatm_ice(:,:)    = qair(:,:)
          tprecip(:,:)     = sf(jp_prec)%fnow(:,:,1) * rn_pfac
          sprecip(:,:)     = sf(jp_snow)%fnow(:,:,1) * rn_pfac
@@ -434,15 +444,15 @@
       !!    (see Josey, Gulev & Yu, 2013) / doi=10.1016/B978-0-12-391851-2.00005-2
       !!    (since reanalysis products provide T at z, not theta !)
-      ztpot = sf(jp_tair)%fnow(:,:,1) + gamma_moist( sf(jp_tair)%fnow(:,:,1), sf(jp_humi)%fnow(:,:,1) ) * rn_zqt
+      ztpot(:,:) = sf(jp_tair)%fnow(:,:,1) + gamma_moist( sf(jp_tair)%fnow(:,:,1), qair(:,:) ) * rn_zqt
 
       SELECT CASE( nblk )        !==  transfer coefficients  ==!   Cd, Ch, Ce at T-point
       !
-      CASE( np_NCAR      )   ;   CALL turb_ncar    ( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! NCAR-COREv2
+      CASE( np_NCAR      )   ;   CALL turb_ncar    ( rn_zqt, rn_zu, zst, ztpot, zsq, qair, wndm,   &  ! NCAR-COREv2
          &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
-      CASE( np_COARE_3p0 )   ;   CALL turb_coare   ( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! COARE v3.0
+      CASE( np_COARE_3p0 )   ;   CALL turb_coare   ( rn_zqt, rn_zu, zst, ztpot, zsq, qair, wndm,   &  ! COARE v3.0
          &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
-      CASE( np_COARE_3p5 )   ;   CALL turb_coare3p5( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! COARE v3.5
+      CASE( np_COARE_3p5 )   ;   CALL turb_coare3p5( rn_zqt, rn_zu, zst, ztpot, zsq, qair, wndm,   &  ! COARE v3.5
          &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
-      CASE( np_ECMWF     )   ;   CALL turb_ecmwf   ( rn_zqt, rn_zu, zst, ztpot, zsq, sf(jp_humi)%fnow, wndm,   &  ! ECMWF
+      CASE( np_ECMWF     )   ;   CALL turb_ecmwf   ( rn_zqt, rn_zu, zst, ztpot, zsq, qair, wndm,   &  ! ECMWF
          &                                           Cd_atm, Ch_atm, Ce_atm, t_zu, q_zu, zU_zu, cdn_oce, chn_oce, cen_oce )
       CASE DEFAULT
@@ -454,5 +464,5 @@
          zrhoa(:,:) = rho_air( t_zu(:,:)              , q_zu(:,:)              , sf(jp_slp)%fnow(:,:,1) )
       ELSE                                      ! At zt:
-         zrhoa(:,:) = rho_air( sf(jp_tair)%fnow(:,:,1), sf(jp_humi)%fnow(:,:,1), sf(jp_slp)%fnow(:,:,1) )
+         zrhoa(:,:) = rho_air( sf(jp_tair)%fnow(:,:,1), qair(:,:), sf(jp_slp)%fnow(:,:,1) )
       END IF
 
@@ -495,11 +505,11 @@
       IF( ABS( rn_zu - rn_zqt) < 0.01_wp ) THEN
          !! q_air and t_air are given at 10m (wind reference height)
-         zevap(:,:) = rn_efac*MAX( 0._wp,             zqla(:,:)*Ce_atm(:,:)*(zsq(:,:) - sf(jp_humi)%fnow(:,:,1)) ) ! Evaporation, using bulk wind speed
-         zqsb (:,:) = cp_air(sf(jp_humi)%fnow(:,:,1))*zqla(:,:)*Ch_atm(:,:)*(zst(:,:) - ztpot(:,:)             )   ! Sensible Heat, using bulk wind speed
+         zevap(:,:) = rn_efac*MAX( 0._wp,             zqla(:,:)*Ce_atm(:,:)*(zsq(:,:) - qair(:,:)) ) ! Evaporation, using bulk wind speed
+         zqsb (:,:) = cp_air(qair(:,:))*zqla(:,:)*Ch_atm(:,:)*(zst(:,:) - ztpot(:,:)             )   ! Sensible Heat, using bulk wind speed
       ELSE
          !! q_air and t_air are not given at 10m (wind reference height)
          ! Values of temp. and hum. adjusted to height of wind during bulk algorithm iteration must be used!!!
          zevap(:,:) = rn_efac*MAX( 0._wp,             zqla(:,:)*Ce_atm(:,:)*(zsq(:,:) - q_zu(:,:) ) ) ! Evaporation, using bulk wind speed
-         zqsb (:,:) = cp_air(sf(jp_humi)%fnow(:,:,1))*zqla(:,:)*Ch_atm(:,:)*(zst(:,:) - t_zu(:,:) )   ! Sensible Heat, using bulk wind speed
+         zqsb (:,:) = cp_air(qair(:,:))*zqla(:,:)*Ch_atm(:,:)*(zst(:,:) - t_zu(:,:) )   ! Sensible Heat, using bulk wind speed
       ENDIF
 
@@ -742,5 +752,5 @@
       ! local scalars ( place there for vector optimisation purposes)
       ! Computing density of air! Way denser that 1.2 over sea-ice !!!
-      zrhoa (:,:) =  rho_air(sf(jp_tair)%fnow(:,:,1), sf(jp_humi)%fnow(:,:,1), sf(jp_slp)%fnow(:,:,1))
+      zrhoa (:,:) =  rho_air(sf(jp_tair)%fnow(:,:,1), qair(:,:), sf(jp_slp)%fnow(:,:,1))
 
       !!gm brutal....
@@ -806,5 +816,5 @@
       zcoef_dqla = -Ls * 11637800. * (-5897.8)
       !
-      zrhoa(:,:) = rho_air( sf(jp_tair)%fnow(:,:,1), sf(jp_humi)%fnow(:,:,1), sf(jp_slp)%fnow(:,:,1) )
+      zrhoa(:,:) = rho_air( sf(jp_tair)%fnow(:,:,1), qair(:,:), sf(jp_slp)%fnow(:,:,1) )
       !
       zztmp = 1. / ( 1. - albo )
@@ -837,5 +847,5 @@
                ! Latent Heat
                qla_ice(ji,jj,jl) = rn_efac * MAX( 0.e0, zrhoa(ji,jj) * Ls  * Ch_atm(ji,jj) * wndm_ice(ji,jj) *  &
-                  &                ( 11637800. * EXP( -5897.8 * z1_st(ji,jj,jl) ) / zrhoa(ji,jj) - sf(jp_humi)%fnow(ji,jj,1) ) )
+                  &                ( 11637800. * EXP( -5897.8 * z1_st(ji,jj,jl) ) / zrhoa(ji,jj) - qair(ji,jj) ) )
                ! Latent heat sensitivity for ice (Dqla/Dt)
                IF( qla_ice(ji,jj,jl) > 0._wp ) THEN
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRA/tramle.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRA/tramle.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRA/tramle.F90	(revision 13402)
@@ -21,4 +21,8 @@
    USE lbclnk         ! lateral boundary condition / mpp link
 
+   ! where OSMOSIS_OBL is used with integrated FK
+   USE zdf_oce, ONLY : ln_zdfosm
+   USE zdfosm, ONLY  : ln_osm_mle, hmle, dbdx_mle, dbdy_mle, mld_prof
+
    IMPLICIT NONE
    PRIVATE
@@ -56,197 +60,257 @@
 CONTAINS
 
-   SUBROUTINE tra_mle_trp( kt, kit000, pu, pv, pw, cdtype )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_mle_trp  ***
-      !!
-      !! ** Purpose :   Add to the transport the Mixed Layer Eddy induced transport
-      !!
-      !! ** Method  :   The 3 components of the Mixed Layer Eddy (MLE) induced
-      !!              transport are computed as follows :
-      !!                zu_mle = dk[ zpsi_uw ]
-      !!                zv_mle = dk[ zpsi_vw ]
-      !!                zw_mle = - di[ zpsi_uw ] - dj[ zpsi_vw ]
-      !!                where zpsi is the MLE streamfunction at uw and vw points (see the doc)
-      !!              and added to the input velocity :
-      !!                p.n = p.n + z._mle
-      !!
-      !! ** Action  : - (pun,pvn,pwn) increased by the mle transport
-      !!                CAUTION, the transport is not updated at the last line/raw
-      !!                         this may be a problem for some advection schemes
-      !!
-      !! References: Fox-Kemper et al., JPO, 38, 1145-1165, 2008
-      !!             Fox-Kemper and Ferrari, JPO, 38, 1166-1179, 2008
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt         ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   kit000     ! first time step index
-      CHARACTER(len=3)                , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu         ! in : 3 ocean transport components
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pv         ! out: same 3  transport components
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pw         !   increased by the MLE induced transport
-      !
-      INTEGER  ::   ji, jj, jk          ! dummy loop indices
-      INTEGER  ::   ii, ij, ik, ikmax   ! local integers
-      REAL(wp) ::   zcuw, zmuw, zc      ! local scalar
-      REAL(wp) ::   zcvw, zmvw          !   -      -
-      INTEGER , DIMENSION(jpi,jpj)     :: inml_mle
-      REAL(wp), DIMENSION(jpi,jpj)     :: zpsim_u, zpsim_v, zmld, zbm, zhu, zhv, zn2, zLf_NH, zLf_MH
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zpsi_uw, zpsi_vw
-      !!----------------------------------------------------------------------
-      !
-      !                                      !==  MLD used for MLE  ==!
-      !                                                ! compute from the 10m density to deal with the diurnal cycle
-      inml_mle(:,:) = mbkt(:,:) + 1                    ! init. to number of ocean w-level (T-level + 1)
-      IF ( nla10 > 0 ) THEN                            ! avoid case where first level is thicker than 10m
-         DO jk = jpkm1, nlb10, -1                      ! from the bottom to nlb10 (10m)
-            DO jj = 1, jpj
-               DO ji = 1, jpi                          ! index of the w-level at the ML based
-                  IF( rhop(ji,jj,jk) > rhop(ji,jj,nla10) + rn_rho_c_mle )   inml_mle(ji,jj) = jk      ! Mixed layer
-               END DO
-            END DO
-         END DO
-      ENDIF
-      ikmax = MIN( MAXVAL( inml_mle(:,:) ), jpkm1 )                  ! max level of the computation
-      !
-      !
-      zmld(:,:) = 0._wp                      !==   Horizontal shape of the MLE  ==!
-      zbm (:,:) = 0._wp
-      zn2 (:,:) = 0._wp
-      DO jk = 1, ikmax                                 ! MLD and mean buoyancy and N2 over the mixed layer
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zc = e3t_n(ji,jj,jk) * REAL( MIN( MAX( 0, inml_mle(ji,jj)-jk ) , 1  )  )    ! zc being 0 outside the ML t-points
-               zmld(ji,jj) = zmld(ji,jj) + zc
-               zbm (ji,jj) = zbm (ji,jj) + zc * (rau0 - rhop(ji,jj,jk) ) * r1_rau0
-               zn2 (ji,jj) = zn2 (ji,jj) + zc * (rn2(ji,jj,jk)+rn2(ji,jj,jk+1))*0.5_wp
-            END DO
-         END DO
-      END DO
-
-      SELECT CASE( nn_mld_uv )                         ! MLD at u- & v-pts
-      CASE ( 0 )                                               != min of the 2 neighbour MLDs
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zhu(ji,jj) = MIN( zmld(ji+1,jj), zmld(ji,jj) )
-               zhv(ji,jj) = MIN( zmld(ji,jj+1), zmld(ji,jj) )
-            END DO
-         END DO
-      CASE ( 1 )                                               != average of the 2 neighbour MLDs
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zhu(ji,jj) = ( zmld(ji+1,jj) + zmld(ji,jj) ) * 0.5_wp
-               zhv(ji,jj) = ( zmld(ji,jj+1) + zmld(ji,jj) ) * 0.5_wp
-            END DO
-         END DO
-      CASE ( 2 )                                               != max of the 2 neighbour MLDs
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zhu(ji,jj) = MAX( zmld(ji+1,jj), zmld(ji,jj) )
-               zhv(ji,jj) = MAX( zmld(ji,jj+1), zmld(ji,jj) )
-            END DO
-         END DO
-      END SELECT
-      !                                                ! convert density into buoyancy
-      zbm(:,:) = + grav * zbm(:,:) / MAX( e3t_n(:,:,1), zmld(:,:) )
-      !
-      !
-      !                                      !==  Magnitude of the MLE stream function  ==!
-      !
-      !                 di[bm]  Ds
-      ! Psi = Ce  H^2 ---------------- e2u  mu(z)   where fu Lf = MAX( fu*rn_fl , (Db H)^1/2 )
-      !                  e1u   Lf fu                      and the e2u for the "transport"
-      !                                                      (not *e3u as divided by e3u at the end)
-      !
-      IF( nn_mle == 0 ) THEN           ! Fox-Kemper et al. 2010 formulation
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zpsim_u(ji,jj) = rn_ce * zhu(ji,jj) * zhu(ji,jj)  * e2_e1u(ji,jj)                                            &
-                  &           * ( zbm(ji+1,jj) - zbm(ji,jj) ) * MIN( 111.e3_wp , e1u(ji,jj) )   &
-                  &           / (  MAX( rn_lf * rfu(ji,jj) , SQRT( rb_c * zhu(ji,jj) ) )   )
-                  !
-               zpsim_v(ji,jj) = rn_ce * zhv(ji,jj) * zhv(ji,jj)  * e1_e2v(ji,jj)                                            &
-                  &           * ( zbm(ji,jj+1) - zbm(ji,jj) ) * MIN( 111.e3_wp , e2v(ji,jj) )   &
-                  &           / (  MAX( rn_lf * rfv(ji,jj) , SQRT( rb_c * zhv(ji,jj) ) )   )
-            END DO
-         END DO
-         !
-      ELSEIF( nn_mle == 1 ) THEN       ! New formulation (Lf = 5km fo/ff with fo=Coriolis parameter at latitude rn_lat)
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zpsim_u(ji,jj) = rc_f *   zhu(ji,jj)   * zhu(ji,jj)   * e2_e1u(ji,jj)               &
-                  &                  * ( zbm(ji+1,jj) - zbm(ji,jj) ) * MIN( 111.e3_wp , e1u(ji,jj) )
-                  !
-               zpsim_v(ji,jj) = rc_f *   zhv(ji,jj)   * zhv(ji,jj)   * e1_e2v(ji,jj)               &
-                  &                  * ( zbm(ji,jj+1) - zbm(ji,jj) ) * MIN( 111.e3_wp , e2v(ji,jj) )
-            END DO
-         END DO
-      ENDIF
-      !
-      IF( nn_conv == 1 ) THEN              ! No MLE in case of convection
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               IF( MIN( zn2(ji,jj) , zn2(ji+1,jj) ) < 0._wp )   zpsim_u(ji,jj) = 0._wp
-               IF( MIN( zn2(ji,jj) , zn2(ji,jj+1) ) < 0._wp )   zpsim_v(ji,jj) = 0._wp
-            END DO
-         END DO
-      ENDIF
-      !
-      !                                      !==  structure function value at uw- and vw-points  ==!
-      DO jj = 1, jpjm1
-         DO ji = 1, fs_jpim1   ! vector opt.
-            zhu(ji,jj) = 1._wp / zhu(ji,jj)                   ! hu --> 1/hu
-            zhv(ji,jj) = 1._wp / zhv(ji,jj)
-         END DO
-      END DO
-      !
-      zpsi_uw(:,:,:) = 0._wp
-      zpsi_vw(:,:,:) = 0._wp
-      !
-      DO jk = 2, ikmax                                ! start from 2 : surface value = 0
-         DO jj = 1, jpjm1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               zcuw = 1._wp - ( gdepw_n(ji+1,jj,jk) + gdepw_n(ji,jj,jk) ) * zhu(ji,jj)
-               zcvw = 1._wp - ( gdepw_n(ji,jj+1,jk) + gdepw_n(ji,jj,jk) ) * zhv(ji,jj)
-               zcuw = zcuw * zcuw
-               zcvw = zcvw * zcvw
-               zmuw = MAX(  0._wp , ( 1._wp - zcuw ) * ( 1._wp + r5_21 * zcuw )  )
-               zmvw = MAX(  0._wp , ( 1._wp - zcvw ) * ( 1._wp + r5_21 * zcvw )  )
-               !
-               zpsi_uw(ji,jj,jk) = zpsim_u(ji,jj) * zmuw * umask(ji,jj,jk)
-               zpsi_vw(ji,jj,jk) = zpsim_v(ji,jj) * zmvw * vmask(ji,jj,jk)
-            END DO
-         END DO
-      END DO
-      !
-      !                                      !==  transport increased by the MLE induced transport ==!
-      DO jk = 1, ikmax
-         DO jj = 1, jpjm1                          ! CAUTION pu,pv must be defined at row/column i=1 / j=1
-            DO ji = 1, fs_jpim1   ! vector opt.
-               pu(ji,jj,jk) = pu(ji,jj,jk) + ( zpsi_uw(ji,jj,jk) - zpsi_uw(ji,jj,jk+1) )
-               pv(ji,jj,jk) = pv(ji,jj,jk) + ( zpsi_vw(ji,jj,jk) - zpsi_vw(ji,jj,jk+1) )
-            END DO
-         END DO
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               pw(ji,jj,jk) = pw(ji,jj,jk) - ( zpsi_uw(ji,jj,jk) - zpsi_uw(ji-1,jj,jk)   &
+  SUBROUTINE tra_mle_trp( kt, kit000, pu, pv, pw, cdtype )
+    !!----------------------------------------------------------------------
+    !!                  ***  ROUTINE tra_mle_trp  ***
+    !!
+    !! ** Purpose :   Add to the transport the Mixed Layer Eddy induced transport
+    !!
+    !! ** Method  :   The 3 components of the Mixed Layer Eddy (MLE) induced
+    !!              transport are computed as follows :
+    !!                zu_mle = dk[ zpsi_uw ]
+    !!                zv_mle = dk[ zpsi_vw ]
+    !!                zw_mle = - di[ zpsi_uw ] - dj[ zpsi_vw ]
+    !!                where zpsi is the MLE streamfunction at uw and vw points (see the doc)
+    !!              and added to the input velocity :
+    !!                p.n = p.n + z._mle
+    !!
+    !! ** Action  : - (pun,pvn,pwn) increased by the mle transport
+    !!                CAUTION, the transport is not updated at the last line/raw
+    !!                         this may be a problem for some advection schemes
+    !!
+    !! References: Fox-Kemper et al., JPO, 38, 1145-1165, 2008
+    !!             Fox-Kemper and Ferrari, JPO, 38, 1166-1179, 2008
+    !!----------------------------------------------------------------------
+    INTEGER                         , INTENT(in   ) ::   kt         ! ocean time-step index
+    INTEGER                         , INTENT(in   ) ::   kit000     ! first time step index
+    CHARACTER(len=3)                , INTENT(in   ) ::   cdtype     ! =TRA or TRC (tracer indicator)
+    REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu         ! in : 3 ocean transport components
+    REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pv         ! out: same 3  transport components
+    REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pw         !   increased by the MLE induced transport
+    !
+    INTEGER  ::   ji, jj, jk          ! dummy loop indices
+    INTEGER  ::   ii, ij, ik, ikmax   ! local integers
+    REAL(wp) ::   zcuw, zmuw, zc      ! local scalar
+    REAL(wp) ::   zcvw, zmvw          !   -      -
+    INTEGER , DIMENSION(jpi,jpj)     :: inml_mle
+    REAL(wp), DIMENSION(jpi,jpj)     :: zpsim_u, zpsim_v, zmld, zbm, zhu, zhv, zn2, zLf_NH, zLf_MH
+    REAL(wp), DIMENSION(jpi,jpj,jpk) :: zpsi_uw, zpsi_vw
+    !!----------------------------------------------------------------------
+    !
+    !
+    IF(ln_osm_mle.and.ln_zdfosm) THEN
+       ikmax = MIN( MAXVAL( mld_prof(:,:) ), jpkm1 )                  ! max level of the computation
+       !
+       !
+       SELECT CASE( nn_mld_uv )                         ! MLD at u- & v-pts
+       CASE ( 0 )                                               != min of the 2 neighbour MLDs
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zhu(ji,jj) = MIN( hmle(ji+1,jj), hmle(ji,jj) )
+                zhv(ji,jj) = MIN( hmle(ji,jj+1), hmle(ji,jj) )
+             END DO
+          END DO
+       CASE ( 1 )                                               != average of the 2 neighbour MLDs
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zhu(ji,jj) = MAX( hmle(ji+1,jj), hmle(ji,jj) )
+                zhv(ji,jj) = MAX( hmle(ji,jj+1), hmle(ji,jj) )
+             END DO
+          END DO
+       CASE ( 2 )                                               != max of the 2 neighbour MLDs
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zhu(ji,jj) = MAX( hmle(ji+1,jj), hmle(ji,jj) )
+                zhv(ji,jj) = MAX( hmle(ji,jj+1), hmle(ji,jj) )
+             END DO
+          END DO
+       END SELECT
+       IF( nn_mle == 0 ) THEN           ! Fox-Kemper et al. 2010 formulation
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zpsim_u(ji,jj) = rn_ce * zhu(ji,jj) * zhu(ji,jj)  * e2u(ji,jj)                                            &
+                     &           * dbdx_mle(ji,jj) * MIN( 111.e3_wp , e1u(ji,jj) )   &
+                     &           / (  MAX( rn_lf * rfu(ji,jj) , SQRT( rb_c * zhu(ji,jj) ) )   )
+                !
+                zpsim_v(ji,jj) = rn_ce * zhv(ji,jj) * zhv(ji,jj)  * e1v(ji,jj)                                            &
+                     &           * dbdy_mle(ji,jj)  * MIN( 111.e3_wp , e2v(ji,jj) )   &
+                     &           / (  MAX( rn_lf * rfv(ji,jj) , SQRT( rb_c * zhv(ji,jj) ) )   )
+             END DO
+          END DO
+          !
+       ELSEIF( nn_mle == 1 ) THEN       ! New formulation (Lf = 5km fo/ff with fo=Coriolis parameter at latitude rn_lat)
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zpsim_u(ji,jj) = rc_f *   zhu(ji,jj)   * zhu(ji,jj)   * e2u(ji,jj)               &
+                     &                  * dbdx_mle(ji,jj) * MIN( 111.e3_wp , e1u(ji,jj) )
+                !
+                zpsim_v(ji,jj) = rc_f *   zhv(ji,jj)   * zhv(ji,jj)   * e1v(ji,jj)               &
+                     &                  * dbdy_mle(ji,jj) * MIN( 111.e3_wp , e2v(ji,jj) )
+             END DO
+          END DO
+       ENDIF
+
+    ELSE !do not use osn_mle
+       !                                      !==  MLD used for MLE  ==!
+       !                                                ! compute from the 10m density to deal with the diurnal cycle
+       inml_mle(:,:) = mbkt(:,:) + 1                    ! init. to number of ocean w-level (T-level + 1)
+       IF ( nla10 > 0 ) THEN                            ! avoid case where first level is thicker than 10m
+          DO jk = jpkm1, nlb10, -1                      ! from the bottom to nlb10 (10m)
+             DO jj = 1, jpj
+                DO ji = 1, jpi                          ! index of the w-level at the ML based
+                   IF( rhop(ji,jj,jk) > rhop(ji,jj,nla10) + rn_rho_c_mle )   inml_mle(ji,jj) = jk      ! Mixed layer
+                END DO
+             END DO
+          END DO
+       ENDIF
+       ikmax = MIN( MAXVAL( inml_mle(:,:) ), jpkm1 )                  ! max level of the computation
+
+       !
+       !
+       zmld(:,:) = 0._wp                      !==   Horizontal shape of the MLE  ==!
+       zbm (:,:) = 0._wp
+       zn2 (:,:) = 0._wp
+       DO jk = 1, ikmax                                 ! MLD and mean buoyancy and N2 over the mixed layer
+          DO jj = 1, jpj
+             DO ji = 1, jpi
+                zc = e3t_n(ji,jj,jk) * REAL( MIN( MAX( 0, inml_mle(ji,jj)-jk ) , 1  )  )    ! zc being 0 outside the ML t-points
+                zmld(ji,jj) = zmld(ji,jj) + zc
+                zbm (ji,jj) = zbm (ji,jj) + zc * (rau0 - rhop(ji,jj,jk) ) * r1_rau0
+                zn2 (ji,jj) = zn2 (ji,jj) + zc * (rn2(ji,jj,jk)+rn2(ji,jj,jk+1))*0.5_wp
+             END DO
+          END DO
+       END DO
+
+       SELECT CASE( nn_mld_uv )                         ! MLD at u- & v-pts
+       CASE ( 0 )                                               != min of the 2 neighbour MLDs
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zhu(ji,jj) = MIN( zmld(ji+1,jj), zmld(ji,jj) )
+                zhv(ji,jj) = MIN( zmld(ji,jj+1), zmld(ji,jj) )
+             END DO
+          END DO
+       CASE ( 1 )                                               != average of the 2 neighbour MLDs
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zhu(ji,jj) = ( zmld(ji+1,jj) + zmld(ji,jj) ) * 0.5_wp
+                zhv(ji,jj) = ( zmld(ji,jj+1) + zmld(ji,jj) ) * 0.5_wp
+             END DO
+          END DO
+       CASE ( 2 )                                               != max of the 2 neighbour MLDs
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zhu(ji,jj) = MAX( zmld(ji+1,jj), zmld(ji,jj) )
+                zhv(ji,jj) = MAX( zmld(ji,jj+1), zmld(ji,jj) )
+             END DO
+          END DO
+       END SELECT
+       !                                                ! convert density into buoyancy
+       zbm(:,:) = + grav * zbm(:,:) / MAX( e3t_n(:,:,1), zmld(:,:) )
+       !
+       !
+       !                                      !==  Magnitude of the MLE stream function  ==!
+       !
+       !                 di[bm]  Ds
+       ! Psi = Ce  H^2 ---------------- e2u  mu(z)   where fu Lf = MAX( fu*rn_fl , (Db H)^1/2 )
+       !                  e1u   Lf fu                      and the e2u for the "transport"
+       !                                                      (not *e3u as divided by e3u at the end)
+       !
+       IF( nn_mle == 0 ) THEN           ! Fox-Kemper et al. 2010 formulation
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zpsim_u(ji,jj) = rn_ce * zhu(ji,jj) * zhu(ji,jj)  * e2_e1u(ji,jj)                                            &
+                     &           * ( zbm(ji+1,jj) - zbm(ji,jj) ) * MIN( 111.e3_wp , e1u(ji,jj) )   &
+                     &           / (  MAX( rn_lf * rfu(ji,jj) , SQRT( rb_c * zhu(ji,jj) ) )   )
+                !
+                zpsim_v(ji,jj) = rn_ce * zhv(ji,jj) * zhv(ji,jj)  * e1_e2v(ji,jj)                                            &
+                     &           * ( zbm(ji,jj+1) - zbm(ji,jj) ) * MIN( 111.e3_wp , e2v(ji,jj) )   &
+                     &           / (  MAX( rn_lf * rfv(ji,jj) , SQRT( rb_c * zhv(ji,jj) ) )   )
+             END DO
+          END DO
+          !
+       ELSEIF( nn_mle == 1 ) THEN       ! New formulation (Lf = 5km fo/ff with fo=Coriolis parameter at latitude rn_lat)
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                zpsim_u(ji,jj) = rc_f *   zhu(ji,jj)   * zhu(ji,jj)   * e2_e1u(ji,jj)               &
+                     &                  * ( zbm(ji+1,jj) - zbm(ji,jj) ) * MIN( 111.e3_wp , e1u(ji,jj) )
+                !
+                zpsim_v(ji,jj) = rc_f *   zhv(ji,jj)   * zhv(ji,jj)   * e1_e2v(ji,jj)               &
+                     &                  * ( zbm(ji,jj+1) - zbm(ji,jj) ) * MIN( 111.e3_wp , e2v(ji,jj) )
+             END DO
+          END DO
+       ENDIF
+       !
+       IF( nn_conv == 1 ) THEN              ! No MLE in case of convection
+          DO jj = 1, jpjm1
+             DO ji = 1, fs_jpim1   ! vector opt.
+                IF( MIN( zn2(ji,jj) , zn2(ji+1,jj) ) < 0._wp )   zpsim_u(ji,jj) = 0._wp
+                IF( MIN( zn2(ji,jj) , zn2(ji,jj+1) ) < 0._wp )   zpsim_v(ji,jj) = 0._wp
+             END DO
+          END DO
+       ENDIF
+       !
+    ENDIF  ! end of lm_osm_mle loop
+    !                                      !==  structure function value at uw- and vw-points  ==!
+    DO jj = 1, jpjm1
+       DO ji = 1, fs_jpim1   ! vector opt.
+          zhu(ji,jj) = 1._wp / MAX(zhu(ji,jj), rsmall)                   ! hu --> 1/hu
+          zhv(ji,jj) = 1._wp / MAX(zhv(ji,jj), rsmall) 
+       END DO
+    END DO
+    !
+    zpsi_uw(:,:,:) = 0._wp
+    zpsi_vw(:,:,:) = 0._wp
+    !
+    DO jk = 2, ikmax                                ! start from 2 : surface value = 0
+       DO jj = 1, jpjm1
+          DO ji = 1, fs_jpim1   ! vector opt.
+             zcuw = 1._wp - ( gdepw_n(ji+1,jj,jk) + gdepw_n(ji,jj,jk) ) * zhu(ji,jj)
+             zcvw = 1._wp - ( gdepw_n(ji,jj+1,jk) + gdepw_n(ji,jj,jk) ) * zhv(ji,jj)
+             zcuw = zcuw * zcuw
+             zcvw = zcvw * zcvw
+             zmuw = MAX(  0._wp , ( 1._wp - zcuw ) * ( 1._wp + r5_21 * zcuw )  )
+             zmvw = MAX(  0._wp , ( 1._wp - zcvw ) * ( 1._wp + r5_21 * zcvw )  )
+             !
+             zpsi_uw(ji,jj,jk) = zpsim_u(ji,jj) * zmuw * umask(ji,jj,jk)
+             zpsi_vw(ji,jj,jk) = zpsim_v(ji,jj) * zmvw * vmask(ji,jj,jk)
+          END DO
+       END DO
+    END DO
+    !
+    !                                      !==  transport increased by the MLE induced transport ==!
+    DO jk = 1, ikmax
+       DO jj = 1, jpjm1                          ! CAUTION pu,pv must be defined at row/column i=1 / j=1
+          DO ji = 1, fs_jpim1   ! vector opt.
+             pu(ji,jj,jk) = pu(ji,jj,jk) + ( zpsi_uw(ji,jj,jk) - zpsi_uw(ji,jj,jk+1) )
+             pv(ji,jj,jk) = pv(ji,jj,jk) + ( zpsi_vw(ji,jj,jk) - zpsi_vw(ji,jj,jk+1) )
+          END DO
+       END DO
+       DO jj = 2, jpjm1
+          DO ji = fs_2, fs_jpim1   ! vector opt.
+             pw(ji,jj,jk) = pw(ji,jj,jk) - ( zpsi_uw(ji,jj,jk) - zpsi_uw(ji-1,jj,jk)   &
                   &                          + zpsi_vw(ji,jj,jk) - zpsi_vw(ji,jj-1,jk) )
-            END DO
-         END DO
-      END DO
-
-      IF( cdtype == 'TRA') THEN              !==  outputs  ==!
-         !
-         zLf_NH(:,:) = SQRT( rb_c * zmld(:,:) ) * r1_ft(:,:)      ! Lf = N H / f
-         CALL iom_put( "Lf_NHpf" , zLf_NH  )    ! Lf = N H / f
-         !
-         ! divide by cross distance to give streamfunction with dimensions m^2/s
-         DO jk = 1, ikmax+1
-            zpsi_uw(:,:,jk) = zpsi_uw(:,:,jk) * r1_e2u(:,:)
-            zpsi_vw(:,:,jk) = zpsi_vw(:,:,jk) * r1_e1v(:,:)
-         END DO
-         CALL iom_put( "psiu_mle", zpsi_uw )    ! i-mle streamfunction
-         CALL iom_put( "psiv_mle", zpsi_vw )    ! j-mle streamfunction
-      ENDIF
-      !
-   END SUBROUTINE tra_mle_trp
+          END DO
+       END DO
+    END DO
+
+    IF( cdtype == 'TRA') THEN              !==  outputs  ==!
+       !
+       IF (ln_osm_mle.and.ln_zdfosm) THEN
+          zLf_NH(:,:) = SQRT( rb_c * hmle(:,:) ) * r1_ft(:,:)      ! Lf = N H / f
+       ELSE
+          zLf_NH(:,:) = SQRT( rb_c * zmld(:,:) ) * r1_ft(:,:)      ! Lf = N H / f
+       END IF
+       CALL iom_put( "Lf_NHpf" , zLf_NH  )    ! Lf = N H / f
+       !
+       ! divide by cross distance to give streamfunction with dimensions m^2/s
+       DO jk = 1, ikmax+1
+          zpsi_uw(:,:,jk) = zpsi_uw(:,:,jk) * r1_e2u(:,:)
+          zpsi_vw(:,:,jk) = zpsi_vw(:,:,jk) * r1_e1v(:,:)
+       END DO
+       CALL iom_put( "psiu_mle", zpsi_uw )    ! i-mle streamfunction
+       CALL iom_put( "psiv_mle", zpsi_vw )    ! j-mle streamfunction
+    ENDIF
+    !
+  END SUBROUTINE tra_mle_trp
 
 
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRD/trd_oce.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRD/trd_oce.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRD/trd_oce.F90	(revision 13402)
@@ -33,5 +33,5 @@
 # endif
    !                                                  !!!* Active tracers trends indexes
-   INTEGER, PUBLIC, PARAMETER ::   jptot_tra  = 20     !: Total trend nb: change it when adding/removing one indice below
+   INTEGER, PUBLIC, PARAMETER ::   jptot_tra  = 21     !: Total trend nb: change it when adding/removing one indice below
    !                               ===============     !  
    INTEGER, PUBLIC, PARAMETER ::   jptra_xad  =  1     !: x- horizontal advection
@@ -46,4 +46,5 @@
    INTEGER, PUBLIC, PARAMETER ::   jptra_bbc  = 10     !: Bottom Boundary Condition (geoth. heating) 
    INTEGER, PUBLIC, PARAMETER ::   jptra_bbl  = 11     !: Bottom Boundary Layer (diffusive and/or advective)
+   INTEGER, PUBLIC, PARAMETER ::   jptra_osm  = 21     !: Non-local terms from OSMOSIS OBL model
    INTEGER, PUBLIC, PARAMETER ::   jptra_npc  = 12     !: non-penetrative convection treatment
    INTEGER, PUBLIC, PARAMETER ::   jptra_dmp  = 13     !: internal restoring (damping)
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRD/trdtra.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRD/trdtra.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/TRD/trdtra.F90	(revision 13402)
@@ -346,4 +346,6 @@
          CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl"  , ptrdx )        ! bottom boundary layer
                                   CALL iom_put( "strd_bbl"  , ptrdy )
+         CASE( jptra_osm  )   ;   CALL iom_put( "ttrd_osm"  , ptrdx )        ! OSMOSIS non-local forcing
+                                  CALL iom_put( "strd_osm"  , ptrdy )
          CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc"  , ptrdx )        ! static instability mixing
                                   CALL iom_put( "strd_npc"  , ptrdy )
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/ZDF/zdfosm.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/ZDF/zdfosm.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/ZDF/zdfosm.F90	(revision 13402)
@@ -25,8 +25,13 @@
    !!            (12) Replace zwstrl with zvstr in calculation of eddy viscosity.
    !! 27/09/2017 (13) Calculate Stokes drift and Stokes penetration depth from wave information
-   !!            (14) Bouyancy flux due to entrainment changed to include contribution from shear turbulence (for testing commented out).
+   !!            (14) Buoyancy flux due to entrainment changed to include contribution from shear turbulence.
    !! 28/09/2017 (15) Calculation of Stokes drift moved into separate do-loops to allow for different options for the determining the Stokes drift to be added.
    !!            (16) Calculation of Stokes drift from windspeed for PM spectrum (for testing, commented out)
    !!            (17) Modification to Langmuir velocity scale to include effects due to the Stokes penetration depth (for testing, commented out)
+   !! ??/??/2018 (18) Revision to code structure, selected using key_osmldpth1. Inline code moved into subroutines. Changes to physics made,
+   !!                  (a) Pycnocline temperature and salinity profies changed for unstable layers
+   !!                  (b) The stable OSBL depth parametrization changed.
+   !! 16/05/2019 (19) Fox-Kemper parametrization of restratification through mixed layer eddies added to revised code.
+   !! 23/05/19   (20) Old code where key_osmldpth1` is *not* set removed, together with the key key_osmldpth1
    !!----------------------------------------------------------------------
 
@@ -40,4 +45,6 @@
    !!   trc_osm       : compute and add to the passive tracer trend the non-local flux (TBD)
    !!   dyn_osm       : compute and add to u & v trensd the non-local flux
+   !!
+   !! Subroutines in revised code.
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and active tracers
@@ -69,5 +76,7 @@
    PUBLIC   tra_osm       ! routine called by step.F90
    PUBLIC   trc_osm       ! routine called by trcstp.F90
-   PUBLIC   dyn_osm       ! routine called by 'step.F90'
+   PUBLIC   dyn_osm       ! routine called by step.F90
+
+   PUBLIC   ln_osm_mle    ! logical needed by tra_mle_init in tramle.F90
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ghamu    !: non-local u-momentum flux
@@ -77,9 +86,19 @@
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   etmean   !: averaging operator for avt
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hbl      !: boundary layer depth
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hbli     !: intial boundary layer depth for stable blayer
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dh       ! depth of pycnocline
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hml      ! ML depth
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dstokes  !: penetration depth of the Stokes drift.
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)           ::   r1_ft    ! inverse of the modified Coriolis parameter at t-pts
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hmle     ! Depth of layer affexted by mixed layer eddies in Fox-Kemper parametrization
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dbdx_mle ! zonal buoyancy gradient in ML
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   dbdy_mle ! meridional buoyancy gradient in ML
+   INTEGER,  PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   mld_prof ! level of base of MLE layer.
 
    !                      !!** Namelist  namzdf_osm  **
    LOGICAL  ::   ln_use_osm_la      ! Use namelist  rn_osm_la
+
+   LOGICAL  ::   ln_osm_mle           !: flag to activate the Mixed Layer Eddy (MLE) parameterisation
+
    REAL(wp) ::   rn_osm_la          ! Turbulent Langmuir number
    REAL(wp) ::   rn_osm_dstokes     ! Depth scale of Stokes drift
@@ -96,6 +115,23 @@
    REAL(wp) ::   rn_difconv = 1._wp     ! diffusivity when unstable below BL  (m2/s)
 
+! OSMOSIS mixed layer eddy parametrization constants
+   INTEGER  ::   nn_osm_mle             ! = 0/1 flag for horizontal average on avt
+   REAL(wp) ::   rn_osm_mle_ce           ! MLE coefficient
+   !                                        ! parameters used in nn_osm_mle = 0 case
+   REAL(wp) ::   rn_osm_mle_lf               ! typical scale of mixed layer front
+   REAL(wp) ::   rn_osm_mle_time             ! time scale for mixing momentum across the mixed layer
+   !                                        ! parameters used in nn_osm_mle = 1 case
+   REAL(wp) ::   rn_osm_mle_lat              ! reference latitude for a 5 km scale of ML front
+   REAL(wp) ::   rn_osm_mle_rho_c        ! Density criterion for definition of MLD used by FK
+   REAL(wp) ::   r5_21 = 5.e0 / 21.e0   ! factor used in mle streamfunction computation
+   REAL(wp) ::   rb_c                   ! ML buoyancy criteria = g rho_c /rau0 where rho_c is defined in zdfmld
+   REAL(wp) ::   rc_f                   ! MLE coefficient (= rn_ce / (5 km * fo) ) in nn_osm_mle=1 case
+   REAL(wp) ::   rn_osm_mle_thresh          ! Threshold buoyancy for deepening of MLE layer below OSBL base.
+   REAL(wp) ::   rn_osm_mle_tau             ! Adjustment timescale for MLE.
+
+
    !                                    !!! ** General constants  **
-   REAL(wp) ::   epsln   = 1.0e-20_wp   ! a small positive number
+   REAL(wp) ::   epsln   = 1.0e-20_wp   ! a small positive number to ensure no div by zero
+   REAL(wp) ::   depth_tol = 1.0e-6_wp  ! a small-ish positive number to give a hbl slightly shallower than gdepw
    REAL(wp) ::   pthird  = 1._wp/3._wp  ! 1/3
    REAL(wp) ::   p2third = 2._wp/3._wp  ! 2/3
@@ -105,5 +141,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id$
+   !! $Id: zdfosm.F90 12317 2020-01-14 12:40:47Z agn $
    !! Software governed by the CeCILL license (see ./LICENSE)
    !!----------------------------------------------------------------------
@@ -114,7 +150,20 @@
       !!                 ***  FUNCTION zdf_osm_alloc  ***
       !!----------------------------------------------------------------------
-     ALLOCATE( ghamu(jpi,jpj,jpk), ghamv(jpi,jpj,jpk), ghamt(jpi,jpj,jpk), ghams(jpi,jpj,jpk), &
-          &      hbl(jpi,jpj)    ,  hbli(jpi,jpj)    , dstokes(jpi, jpj) ,                     &
-          &   etmean(jpi,jpj,jpk),  STAT= zdf_osm_alloc )
+     ALLOCATE( ghamu(jpi,jpj,jpk), ghamv(jpi,jpj,jpk), ghamt(jpi,jpj,jpk),ghams(jpi,jpj,jpk), &
+          &       hbl(jpi,jpj), dh(jpi,jpj), hml(jpi,jpj), dstokes(jpi, jpj), &
+          &       etmean(jpi,jpj,jpk), STAT= zdf_osm_alloc )
+
+     ALLOCATE(  hmle(jpi,jpj), r1_ft(jpi,jpj), dbdx_mle(jpi,jpj), dbdy_mle(jpi,jpj), &
+          &       mld_prof(jpi,jpj), STAT= zdf_osm_alloc )
+
+!     ALLOCATE( ghamu(jpi,jpj,jpk), ghamv(jpi,jpj,jpk), ghamt(jpi,jpj,jpk),ghams(jpi,jpj,jpk), &    ! would ths be better ?
+!          &       hbl(jpi,jpj), dh(jpi,jpj), hml(jpi,jpj), dstokes(jpi, jpj), &
+!          &       etmean(jpi,jpj,jpk), STAT= zdf_osm_alloc )
+!     IF( zdf_osm_alloc /= 0 )   CALL ctl_warn('zdf_osm_alloc: failed to allocate zdf_osm arrays')
+!     IF ( ln_osm_mle ) THEN
+!        Allocate( hmle(jpi,jpj), r1_ft(jpi,jpj), STAT= zdf_osm_alloc )
+!        IF( zdf_osm_alloc /= 0 )   CALL ctl_warn('zdf_osm_alloc: failed to allocate zdf_osm mle arrays')
+!     ENDIF
+
      IF( zdf_osm_alloc /= 0 )   CALL ctl_warn('zdf_osm_alloc: failed to allocate zdf_osm arrays')
      CALL mpp_sum ( 'zdfosm', zdf_osm_alloc )
@@ -161,4 +210,7 @@
       !!
       INTEGER ::   ji, jj, jk                   ! dummy loop indices
+
+      INTEGER ::   jl                   ! dummy loop indices
+
       INTEGER ::   ikbot, jkmax, jkm1, jkp2     !
 
@@ -166,5 +218,6 @@
       REAL(wp) ::   zbeta, zthermal                                  !
       REAL(wp) ::   zehat, zeta, zhrib, zsig, zscale, zwst, zws, zwm ! Velocity scales
-      REAL(wp) ::   zwsun, zwmun, zcons, zconm, zwcons, zwconm       !
+      REAL(wp) ::   zwsun, zwmun, zcons, zconm, zwcons, zwconm      !
+
       REAL(wp) ::   zsr, zbw, ze, zb, zd, zc, zaw, za, zb1, za1, zkw, zk0, zcomp , zrhd,zrhdr,zbvzed   ! In situ density
       INTEGER  ::   jm                          ! dummy loop indices
@@ -191,4 +244,11 @@
       REAL(wp), DIMENSION(jpi,jpj) :: zwbav     ! Buoyancy flux - bl average
       REAL(wp), DIMENSION(jpi,jpj) :: zwb_ent   ! Buoyancy entrainment flux
+
+
+      REAL(wp), DIMENSION(jpi,jpj) :: zwb_fk_b  ! MLE buoyancy flux averaged over OSBL
+      REAL(wp), DIMENSION(jpi,jpj) :: zwb_fk    ! max MLE buoyancy flux
+      REAL(wp), DIMENSION(jpi,jpj) :: zdiff_mle ! extra MLE vertical diff
+      REAL(wp), DIMENSION(jpi,jpj) :: zvel_mle  ! velocity scale for dhdt with stable ML and FK
+
       REAL(wp), DIMENSION(jpi,jpj) :: zustke    ! Surface Stokes drift
       REAL(wp), DIMENSION(jpi,jpj) :: zla       ! Trubulent Langmuir number
@@ -196,5 +256,5 @@
       REAL(wp), DIMENSION(jpi,jpj) :: zsin_wind ! Sin angle of surface stress
       REAL(wp), DIMENSION(jpi,jpj) :: zhol      ! Stability parameter for boundary layer
-      LOGICAL, DIMENSION(:,:), ALLOCATABLE :: lconv ! unstable/stable bl
+      LOGICAL, DIMENSION(jpi,jpj)  :: lconv     ! unstable/stable bl
 
       ! mixed-layer variables
@@ -208,6 +268,15 @@
       REAL(wp), DIMENSION(jpi,jpj) :: zhbl  ! bl depth - grid
       REAL(wp), DIMENSION(jpi,jpj) :: zhml  ! ml depth - grid
+
+      REAL(wp), DIMENSION(jpi,jpj) :: zhmle ! MLE depth - grid
+      REAL(wp), DIMENSION(jpi,jpj) :: zmld  ! ML depth on grid
+
       REAL(wp), DIMENSION(jpi,jpj) :: zdh   ! pycnocline depth - grid
       REAL(wp), DIMENSION(jpi,jpj) :: zdhdt ! BL depth tendency
+      REAL(wp), DIMENSION(jpi,jpj) :: zdhdt_2                                    ! correction to dhdt due to internal structure.
+      REAL(wp), DIMENSION(jpi,jpj) :: zdtdz_ext,zdsdz_ext,zdbdz_ext              ! external temperature/salinity and buoyancy gradients
+
+      REAL(wp), DIMENSION(jpi,jpj) :: zdtdx, zdtdy, zdsdx, zdsdy      ! horizontal gradients for Fox-Kemper parametrization.
+
       REAL(wp), DIMENSION(jpi,jpj) :: zt_bl,zs_bl,zu_bl,zv_bl,zrh_bl  ! averages over the depth of the blayer
       REAL(wp), DIMENSION(jpi,jpj) :: zt_ml,zs_ml,zu_ml,zv_ml,zrh_ml  ! averages over the depth of the mixed layer
@@ -238,5 +307,4 @@
       ! Temporary variables
       INTEGER :: inhml
-      INTEGER :: i_lconv_alloc
       REAL(wp) :: znd,znd_d,zznd_ml,zznd_pyc,zznd_d ! temporary non-dimensional depths used in various routines
       REAL(wp) :: ztemp, zari, zpert, zzdhdt, zdb   ! temporary variables
@@ -248,11 +316,14 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdiffut ! t-diffusivity
 
+      INTEGER :: ibld_ext=0                          ! does not have to be zero for modified scheme
+      REAL(wp) :: zwb_min, zgamma_b_nd, zgamma_b, zdhoh, ztau, zddhdt
+      REAL(wp) :: zzeta_s = 0._wp
+      REAL(wp) :: zzeta_v = 0.46
+      REAL(wp) :: zabsstke
+
       ! For debugging
       INTEGER :: ikt
       !!--------------------------------------------------------------------
       !
-      ALLOCATE( lconv(jpi,jpj),  STAT= i_lconv_alloc )
-      IF( i_lconv_alloc /= 0 )   CALL ctl_warn('zdf_osm: failed to allocate lconv')
-
       ibld(:,:)   = 0     ; imld(:,:)  = 0
       zrad0(:,:)  = 0._wp ; zradh(:,:) = 0._wp ; zradav(:,:)    = 0._wp ; zustar(:,:)    = 0._wp
@@ -268,4 +339,5 @@
       zt_bl(:,:)   = 0._wp ; zs_bl(:,:)   = 0._wp ; zu_bl(:,:)    = 0._wp ; zv_bl(:,:)   = 0._wp
       zrh_bl(:,:)  = 0._wp ; zt_ml(:,:)   = 0._wp ; zs_ml(:,:)    = 0._wp ; zu_ml(:,:)   = 0._wp
+
       zv_ml(:,:)   = 0._wp ; zrh_ml(:,:)  = 0._wp ; zdt_bl(:,:)   = 0._wp ; zds_bl(:,:)  = 0._wp
       zdu_bl(:,:)  = 0._wp ; zdv_bl(:,:)  = 0._wp ; zdrh_bl(:,:)  = 0._wp ; zdb_bl(:,:)  = 0._wp
@@ -277,4 +349,14 @@
       zdudz_pyc(:,:,:) = 0._wp ; zdvdz_pyc(:,:,:) = 0._wp
       !
+      zdtdz_ext(:,:) = 0._wp ; zdsdz_ext(:,:) = 0._wp ; zdbdz_ext(:,:) = 0._wp
+
+      IF ( ln_osm_mle ) THEN  ! only initialise arrays if needed
+         zdtdx(:,:) = 0._wp ; zdtdy(:,:) = 0._wp ; zdsdx(:,:) = 0._wp
+         zdsdy(:,:) = 0._wp ; dbdx_mle(:,:) = 0._wp ; dbdy_mle(:,:) = 0._wp
+         zwb_fk(:,:) = 0._wp ; zvel_mle(:,:) = 0._wp; zdiff_mle(:,:) = 0._wp
+         zhmle(:,:) = 0._wp  ; zmld(:,:) = 0._wp
+      ENDIF
+      zwb_fk_b(:,:) = 0._wp   ! must be initialised even with ln_osm_mle=F as used in zdf_osm_calculate_dhdt
+
       ! Flux-Gradient arrays.
       zdifml_sc(:,:)  = 0._wp ; zvisml_sc(:,:)  = 0._wp ; zdifpyc_sc(:,:) = 0._wp
@@ -287,4 +369,5 @@
       ghams(:,:,:)   = 0._wp ; ghamu(:,:,:)   = 0._wp ; ghamv(:,:,:) = 0._wp
 
+      zdhdt_2(:,:) = 0._wp
       ! hbl = MAX(hbl,epsln)
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -350,5 +433,5 @@
               ! Use wind speed wndm included in sbc_oce module
               zustke(ji,jj) = MAX ( 0.016 * wndm(ji,jj), 1.0e-8 )
-              dstokes(ji,jj) = 0.12 * wndm(ji,jj)**2 / grav
+              dstokes(ji,jj) = MAX( 0.12 * wndm(ji,jj)**2 / grav, 5.e-1)
            END DO
         END DO
@@ -362,7 +445,7 @@
               ! It could represent the effects of the spread of wave directions
               ! around the mean wind. The effect of this adjustment needs to be tested.
-              zustke(ji,jj) = MAX ( 1.0 * ( zcos_wind(ji,jj) * ut0sd(ji,jj ) + zsin_wind(ji,jj)  * vt0sd(ji,jj) ), &
-                   &                zustar(ji,jj) / ( 0.45 * 0.45 )                                                  )
-              dstokes(ji,jj) = MAX(zfac * hsw(ji,jj)*hsw(ji,jj) / ( MAX(zustke(ji,jj)*wmp(ji,jj), 1.0e-7 ) ), 5.0e-1) !rn_osm_dstokes !
+              zabsstke = SQRT(ut0sd(ji,jj)**2 + vt0sd(ji,jj)**2)
+              zustke(ji,jj) = MAX (0.8 * ( zcos_wind(ji,jj) * ut0sd(ji,jj) + zsin_wind(ji,jj)  * vt0sd(ji,jj) ), 1.0e-8)
+              dstokes(ji,jj) = MAX(zfac * hsw(ji,jj)*hsw(ji,jj) / ( MAX(zabsstke*wmp(ji,jj), 1.0e-7 ) ), 5.0e-1) !rn_osm_dstokes !
            END DO
         END DO
@@ -375,12 +458,6 @@
            ! Langmuir velocity scale (zwstrl), at T-point
            zwstrl(ji,jj) = ( zustar(ji,jj) * zustar(ji,jj) * zustke(ji,jj) )**pthird
-           ! Modify zwstrl to allow for small and large values of dstokes/hbl.
-           ! Intended as a possible test. Doesn't affect LES results for entrainment,
-           !  but hasn't been shown to be correct as dstokes/h becomes large or small.
-           zwstrl(ji,jj) = zwstrl(ji,jj) *  &
-                & (1.12 * ( 1.0 - ( 1.0 - EXP( -hbl(ji,jj) / dstokes(ji,jj) ) ) * dstokes(ji,jj) / hbl(ji,jj) ))**pthird * &
-                & ( 1.0 - EXP( -15.0 * dstokes(ji,jj) / hbl(ji,jj) ))
-           ! define La this way so effects of Stokes penetration depth on velocity scale are included
-           zla(ji,jj) = SQRT ( zustar(ji,jj) / zwstrl(ji,jj) )**3
+           zla(ji,jj) = MAX(MIN(SQRT ( zustar(ji,jj) / ( zwstrl(ji,jj) + epsln ) )**3, 4.0), 0.2)
+           IF(zla(ji,jj) > 0.45) dstokes(ji,jj) = MIN(dstokes(ji,jj), 0.5_wp*hbl(ji,jj))
            ! Velocity scale that tends to zustar for large Langmuir numbers
            zvstr(ji,jj) = ( zwstrl(ji,jj)**3  + &
@@ -389,5 +466,4 @@
            ! limit maximum value of Langmuir number as approximate treatment for shear turbulence.
            ! Note zustke and zwstrl are not amended.
-           IF ( zla(ji,jj) >= 0.45 ) zla(ji,jj) = 0.45
            !
            ! get convective velocity (zwstrc), stabilty scale (zhol) and logical conection flag lconv
@@ -406,10 +482,13 @@
      ! Mixed-layer model - calculate averages over the boundary layer, and the change in the boundary layer depth
      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-     ! BL must be always 2 levels deep.
-      hbl(:,:) = MAX(hbl(:,:), gdepw_n(:,:,3) )
-      ibld(:,:) = 3
-      DO jk = 4, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
+     ! BL must be always 4 levels deep.
+     ! For calculation of lateral buoyancy gradients for FK in
+     ! zdf_osm_zmld_horizontal_gradients need halo values for ibld, so must
+     ! previously exist for hbl also.
+      hbl(:,:) = MAX(hbl(:,:), gdepw_n(:,:,4) )
+      ibld(:,:) = 4
+      DO jk = 5, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
                IF ( hbl(ji,jj) >= gdepw_n(ji,jj,jk) ) THEN
                   ibld(ji,jj) = MIN(mbkt(ji,jj), jk)
@@ -419,75 +498,37 @@
       END DO
 
-      DO jj = 2, jpjm1                                 !  Vertical slab
+      DO jj = 2, jpjm1
          DO ji = 2, jpim1
-               zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
-               zbeta    = rab_n(ji,jj,1,jp_sal)
-               zt   = 0._wp
-               zs   = 0._wp
-               zu   = 0._wp
-               zv   = 0._wp
-               ! average over depth of boundary layer
-               zthick=0._wp
-               DO jm = 2, ibld(ji,jj)
-                  zthick=zthick+e3t_n(ji,jj,jm)
-                  zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
-                  zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
-                  zu   = zu  + e3t_n(ji,jj,jm) &
-                     &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
-                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-                  zv   = zv  + e3t_n(ji,jj,jm) &
-                     &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
-                     &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
-               END DO
-               zt_bl(ji,jj) = zt / zthick
-               zs_bl(ji,jj) = zs / zthick
-               zu_bl(ji,jj) = zu / zthick
-               zv_bl(ji,jj) = zv / zthick
-               zdt_bl(ji,jj) = zt_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
-               zds_bl(ji,jj) = zs_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
-               zdu_bl(ji,jj) = zu_bl(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
-                     &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-               zdv_bl(ji,jj) = zv_bl(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
-                     &   / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
-               zdb_bl(ji,jj) = grav * zthermal * zdt_bl(ji,jj) - grav * zbeta * zds_bl(ji,jj)
-               IF ( lconv(ji,jj) ) THEN    ! Convective
-                      zwb_ent(ji,jj) = -( 2.0 * 0.2 * zwbav(ji,jj) &
-                           &            + 0.135 * zla(ji,jj) * zwstrl(ji,jj)**3/hbl(ji,jj) )
-
-                      zvel_max =  - ( 1.0 + 1.0 * ( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / hbl(ji,jj) ) &
-                           &   * zwb_ent(ji,jj) / ( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
-! Entrainment including component due to shear turbulence. Modified Langmuir component, but gives same result for La=0.3 For testing uncomment.
-!                      zwb_ent(ji,jj) = -( 2.0 * 0.2 * zwbav(ji,jj) &
-!                           &            + ( 0.15 * ( 1.0 - EXP( -0.5 * zla(ji,jj) ) ) + 0.03 / zla(ji,jj)**2 ) * zustar(ji,jj)**3/hbl(ji,jj) )
-
-!                      zvel_max = - ( 1.0 + 1.0 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / zhbl(ji,jj) ) * zwb_ent(ji,jj) / &
-!                           &       ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
-                      zzdhdt = - zwb_ent(ji,jj) / ( zvel_max + MAX(zdb_bl(ji,jj),0.0) )
-               ELSE                        ! Stable
-                      zzdhdt = 0.32 * ( hbli(ji,jj) / hbl(ji,jj) -1.0 ) * zwstrl(ji,jj)**3 / hbli(ji,jj) &
-                           &   + ( ( 0.32 / 3.0 ) * exp ( -2.5 * ( hbli(ji,jj) / hbl(ji,jj) - 1.0 ) ) &
-                           & - ( 0.32 / 3.0 - 0.135 * zla(ji,jj) ) * exp ( -12.5 * ( hbli(ji,jj) / hbl(ji,jj) ) ) ) &
-                           &  * zwstrl(ji,jj)**3 / hbli(ji,jj)
-                      zzdhdt = zzdhdt + zwbav(ji,jj)
-                      IF ( zzdhdt < 0._wp ) THEN
-                      ! For long timsteps factor in brackets slows the rapid collapse of the OSBL
-                         zpert   = 2.0 * ( 1.0 + 2.0 * zwstrl(ji,jj) * rn_rdt / hbl(ji,jj) ) * zwstrl(ji,jj)**2 / hbl(ji,jj)
-                      ELSE
-                         zpert   = 2.0 * ( 1.0 + 2.0 * zwstrl(ji,jj) * rn_rdt / hbl(ji,jj) ) * zwstrl(ji,jj)**2 / hbl(ji,jj) &
-                              &  + MAX( zdb_bl(ji,jj), 0.0 )
-                      ENDIF
-                      zzdhdt = 2.0 * zzdhdt / zpert
-               ENDIF
-               zdhdt(ji,jj) = zzdhdt
-           END DO
+            zhbl(ji,jj) = gdepw_n(ji,jj,ibld(ji,jj))
+            imld(ji,jj) = MAX(3,ibld(ji,jj) - MAX( INT( dh(ji,jj) / e3t_n(ji, jj, ibld(ji,jj) )) , 1 ))
+            zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
+         END DO
       END DO
-
+      ! Averages over well-mixed and boundary layer
+      ! Alan: do we need zb_nl?, zb_ml?
+      CALL zdf_osm_vertical_average(ibld, zt_bl, zs_bl, zu_bl, zv_bl, zdt_bl, zds_bl, zdb_bl, zdu_bl, zdv_bl)
+      CALL zdf_osm_vertical_average(imld, zt_ml, zs_ml, zu_ml, zv_ml, zdt_ml, zds_ml, zdb_ml, zdu_ml, zdv_ml)
+! External gradient
+      CALL zdf_osm_external_gradients( zdtdz_ext, zdsdz_ext, zdbdz_ext )
+
+
+      IF ( ln_osm_mle ) THEN
+         CALL zdf_osm_zmld_horizontal_gradients( zmld, zdtdx, zdtdy, zdsdx, zdsdy, dbdx_mle, dbdy_mle )
+         CALL zdf_osm_mle_parameters( hmle, zwb_fk, zvel_mle, zdiff_mle )
+       ENDIF
+
+! Rate of change of hbl
+      CALL zdf_osm_calculate_dhdt( zdhdt, zdhdt_2 )
       ! Calculate averages over depth of boundary layer
-      imld = ibld           ! use imld to hold previous blayer index
-      ibld(:,:) = 3
-
-      zhbl_t(:,:) = hbl(:,:) + (zdhdt(:,:) - wn(ji,jj,ibld(ji,jj)))* rn_rdt ! certainly need wb here, so subtract it
-      zhbl_t(:,:) = MIN(zhbl_t(:,:), ht_n(:,:))
-      zdhdt(:,:) = MIN(zdhdt(:,:), (zhbl_t(:,:) - hbl(:,:))/rn_rdt + wn(ji,jj,ibld(ji,jj))) ! adjustment to represent limiting by ocean bottom
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               zhbl_t(ji,jj) = hbl(ji,jj) + (zdhdt(ji,jj) - wn(ji,jj,ibld(ji,jj)))* rn_rdt ! certainly need wn here, so subtract it
+               ! adjustment to represent limiting by ocean bottom
+               zhbl_t(ji,jj) = MIN(zhbl_t(ji,jj), gdepw_n(ji,jj, mbkt(ji,jj) + 1) - depth_tol)! ht_n(:,:))
+            END DO
+         END DO
+
+      imld(:,:) = ibld(:,:)           ! use imld to hold previous blayer index
+      ibld(:,:) = 4
 
       DO jk = 4, jpkm1
@@ -495,5 +536,5 @@
             DO ji = 2, jpim1
                IF ( zhbl_t(ji,jj) >= gdepw_n(ji,jj,jk) ) THEN
-                  ibld(ji,jj) =  MIN(mbkt(ji,jj), jk)
+                  ibld(ji,jj) = jk
                ENDIF
             END DO
@@ -504,256 +545,40 @@
 ! Step through model levels taking account of buoyancy change to determine the effect on dhdt
 !
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1
-            IF ( ibld(ji,jj) - imld(ji,jj) > 1 ) THEN
+      CALL zdf_osm_timestep_hbl( zdhdt, zdhdt_2 )
+      ! Alan: do we need zb_ml?
+      CALL zdf_osm_vertical_average( ibld, zt_bl, zs_bl, zu_bl, zv_bl, zdt_bl, zds_bl, zdb_bl, zdu_bl, zdv_bl )
 !
-! If boundary layer changes by more than one level, need to check for stable layers between initial and final depths.
 !
-               zhbl_s = hbl(ji,jj)
-               jm = imld(ji,jj)
-               zthermal = rab_n(ji,jj,1,jp_tem)
-               zbeta = rab_n(ji,jj,1,jp_sal)
-               IF ( lconv(ji,jj) ) THEN
-!unstable
-                  zvel_max =  - ( 1.0 + 1.0 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / hbl(ji,jj) ) &
-                       &   * zwb_ent(ji,jj) / ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
-
-                  DO jk = imld(ji,jj), ibld(ji,jj)
-                     zdb = MAX( grav * ( zthermal * ( zt_bl(ji,jj) - tsn(ji,jj,jm,jp_tem) ) &
-                          & - zbeta * ( zs_bl(ji,jj) - tsn(ji,jj,jm,jp_sal) ) ), 0.0 ) + zvel_max
-
-                     zhbl_s = zhbl_s + MIN( - zwb_ent(ji,jj) / zdb * rn_rdt / FLOAT(ibld(ji,jj)-imld(ji,jj) ), e3w_n(ji,jj,jk) )
-                     zhbl_s = MIN(zhbl_s, ht_n(ji,jj))
-
-                     IF ( zhbl_s >= gdepw_n(ji,jj,jm+1) ) jm = jm + 1
-                  END DO
-                  hbl(ji,jj) = zhbl_s
-                  ibld(ji,jj) = jm
-                  hbli(ji,jj) = hbl(ji,jj)
-               ELSE
-! stable
-                  DO jk = imld(ji,jj), ibld(ji,jj)
-                     zdb = MAX( grav * ( zthermal * ( zt_bl(ji,jj) - tsn(ji,jj,jm,jp_tem) )          &
-                          &               - zbeta * ( zs_bl(ji,jj) - tsn(ji,jj,jm,jp_sal) ) ), 0.0 ) &
-                          & + 2.0 * zwstrl(ji,jj)**2 / zhbl_s
-
-                     zhbl_s = zhbl_s +  (                                                                                &
-                          &                     0.32         *                         ( hbli(ji,jj) / zhbl_s -1.0 )     &
-                          &               * zwstrl(ji,jj)**3 / hbli(ji,jj)                                               &
-                          &               + ( ( 0.32 / 3.0 )           * EXP( -  2.5 * ( hbli(ji,jj) / zhbl_s -1.0 ) )   &
-                          &               -   ( 0.32 / 3.0  - 0.0485 ) * EXP( - 12.5 * ( hbli(ji,jj) / zhbl_s      ) ) ) &
-                          &          * zwstrl(ji,jj)**3 / hbli(ji,jj) ) / zdb * e3w_n(ji,jj,jk) / zdhdt(ji,jj)  ! ALMG to investigate whether need to include wn here
-
-                     zhbl_s = MIN(zhbl_s, ht_n(ji,jj))
-                     IF ( zhbl_s >= gdepw_n(ji,jj,jm) ) jm = jm + 1
-                  END DO
-                  hbl(ji,jj) = MAX(zhbl_s, gdepw_n(ji,jj,3) )
-                  ibld(ji,jj) = MAX(jm, 3 )
-                  IF ( hbl(ji,jj) > hbli(ji,jj) ) hbli(ji,jj) = hbl(ji,jj)
-               ENDIF   ! IF ( lconv )
-            ELSE
-! change zero or one model level.
-               hbl(ji,jj) = zhbl_t(ji,jj)
-               IF ( lconv(ji,jj) ) THEN
-                  hbli(ji,jj) = hbl(ji,jj)
-               ELSE
-                  hbl(ji,jj) = MAX(hbl(ji,jj), gdepw_n(ji,jj,3) )
-                  IF ( hbl(ji,jj) > hbli(ji,jj) ) hbli(ji,jj) = hbl(ji,jj)
-               ENDIF
-            ENDIF
-            zhbl(ji,jj) = gdepw_n(ji,jj,ibld(ji,jj))
-         END DO
-      END DO
+      CALL zdf_osm_pycnocline_thickness( dh, zdh )
       dstokes(:,:) = MIN ( dstokes(:,:), hbl(:,:)/3. )  !  Limit delta for shallow boundary layers for calculating flux-gradient terms.
-
-! Recalculate averages over boundary layer after depth updated
-     ! Consider later  combining this into the loop above and looking for columns
-     ! where the index for base of the boundary layer have changed
-      DO jj = 2, jpjm1                                 !  Vertical slab
-         DO ji = 2, jpim1
-               zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
-               zbeta    = rab_n(ji,jj,1,jp_sal)
-               zt   = 0._wp
-               zs   = 0._wp
-               zu   = 0._wp
-               zv   = 0._wp
-               ! average over depth of boundary layer
-               zthick=0._wp
-               DO jm = 2, ibld(ji,jj)
-                  zthick=zthick+e3t_n(ji,jj,jm)
-                  zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
-                  zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
-                  zu   = zu  + e3t_n(ji,jj,jm) &
-                     &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
-                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-                  zv   = zv  + e3t_n(ji,jj,jm) &
-                     &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
-                     &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
-               END DO
-               zt_bl(ji,jj) = zt / zthick
-               zs_bl(ji,jj) = zs / zthick
-               zu_bl(ji,jj) = zu / zthick
-               zv_bl(ji,jj) = zv / zthick
-               zdt_bl(ji,jj) = zt_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
-               zds_bl(ji,jj) = zs_bl(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
-               zdu_bl(ji,jj) = zu_bl(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
-                      &   / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-               zdv_bl(ji,jj) = zv_bl(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
-                      &  / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
-               zdb_bl(ji,jj) = grav * zthermal * zdt_bl(ji,jj) - grav * zbeta * zds_bl(ji,jj)
-               zhbl(ji,jj) = gdepw_n(ji,jj,ibld(ji,jj))
-               IF ( lconv(ji,jj) ) THEN
-                  IF ( zdb_bl(ji,jj) > 0._wp )THEN
-                     IF ( ( zwstrc(ji,jj) / zvstr(ji,jj) )**3 <= 0.5 ) THEN  ! near neutral stability
-                           zari = 4.5 * ( zvstr(ji,jj)**2 ) &
-                             & / ( zdb_bl(ji,jj) * zhbl(ji,jj) ) + 0.01
-                     ELSE                                                     ! unstable
-                           zari = 4.5 * ( zwstrc(ji,jj)**2 ) &
-                             & / ( zdb_bl(ji,jj) * zhbl(ji,jj) ) + 0.01
-                     ENDIF
-                     IF ( zari > 0.2 ) THEN                                                ! This test checks for weakly stratified pycnocline
-                        zari = 0.2
-                        zwb_ent(ji,jj) = 0._wp
-                     ENDIF
-                     inhml = MAX( INT( zari * zhbl(ji,jj) / e3t_n(ji,jj,ibld(ji,jj)) ) , 1 )
-                     imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 1)
-                     zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
-                     zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
-                  ELSE  ! IF (zdb_bl)
-                     imld(ji,jj) = ibld(ji,jj) - 1
-                     zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
-                     zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
-                  ENDIF
-               ELSE   ! IF (lconv)
-                  IF ( zdhdt(ji,jj) >= 0.0 ) THEN    ! probably shouldn't include wm here
-                  ! boundary layer deepening
-                     IF ( zdb_bl(ji,jj) > 0._wp ) THEN
-                  ! pycnocline thickness set by stratification - use same relationship as for neutral conditions.
-                        zari = MIN( 4.5 * ( zvstr(ji,jj)**2 ) &
-                          & / ( zdb_bl(ji,jj) * zhbl(ji,jj) ) + 0.01  , 0.2 )
-                        inhml = MAX( INT( zari * zhbl(ji,jj) / e3t_n(ji,jj,ibld(ji,jj)) ) , 1 )
-                        imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 1)
-                        zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
-                        zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
-                     ELSE
-                        imld(ji,jj) = ibld(ji,jj) - 1
-                        zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
-                        zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
-                     ENDIF ! IF (zdb_bl > 0.0)
-                  ELSE     ! IF(dhdt >= 0)
-                  ! boundary layer collapsing.
-                     imld(ji,jj) = ibld(ji,jj)
-                     zhml(ji,jj) = zhbl(ji,jj)
-                     zdh(ji,jj) = 0._wp
-                  ENDIF    ! IF (dhdt >= 0)
-               ENDIF       ! IF (lconv)
-         END DO
-      END DO
-
-      ! Average over the depth of the mixed layer in the convective boundary layer
-      ! Also calculate entrainment fluxes for temperature and salinity
-      DO jj = 2, jpjm1                                 !  Vertical slab
-         DO ji = 2, jpim1
-            zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
-            zbeta    = rab_n(ji,jj,1,jp_sal)
-            IF ( lconv(ji,jj) ) THEN
-               zt   = 0._wp
-               zs   = 0._wp
-               zu   = 0._wp
-               zv   = 0._wp
-               ! average over depth of boundary layer
-               zthick=0._wp
-               DO jm = 2, imld(ji,jj)
-                  zthick=zthick+e3t_n(ji,jj,jm)
-                  zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
-                  zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
-                  zu   = zu  + e3t_n(ji,jj,jm) &
-                     &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
-                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-                  zv   = zv  + e3t_n(ji,jj,jm) &
-                     &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
-                     &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
-               END DO
-               zt_ml(ji,jj) = zt / zthick
-               zs_ml(ji,jj) = zs / zthick
-               zu_ml(ji,jj) = zu / zthick
-               zv_ml(ji,jj) = zv / zthick
-               zdt_ml(ji,jj) = zt_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
-               zds_ml(ji,jj) = zs_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
-               zdu_ml(ji,jj) = zu_ml(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
-                     &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-               zdv_ml(ji,jj) = zv_ml(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
-                     &    / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
-               zdb_ml(ji,jj) = grav * zthermal * zdt_ml(ji,jj) - grav * zbeta * zds_ml(ji,jj)
-            ELSE
-            ! stable, if entraining calulate average below interface layer.
-               IF ( zdhdt(ji,jj) >= 0._wp ) THEN
-                  zt   = 0._wp
-                  zs   = 0._wp
-                  zu   = 0._wp
-                  zv   = 0._wp
-                  ! average over depth of boundary layer
-                  zthick=0._wp
-                  DO jm = 2, imld(ji,jj)
-                     zthick=zthick+e3t_n(ji,jj,jm)
-                     zt   = zt  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_tem)
-                     zs   = zs  + e3t_n(ji,jj,jm) * tsn(ji,jj,jm,jp_sal)
-                     zu   = zu  + e3t_n(ji,jj,jm) &
-                        &            * ( ub(ji,jj,jm) + ub(ji - 1,jj,jm) ) &
-                        &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-                     zv   = zv  + e3t_n(ji,jj,jm) &
-                        &            * ( vb(ji,jj,jm) + vb(ji,jj - 1,jm) ) &
-                        &            / MAX( 1. , vmask(ji,jj,jm) + vmask(ji,jj - 1,jm) )
-                  END DO
-                  zt_ml(ji,jj) = zt / zthick
-                  zs_ml(ji,jj) = zs / zthick
-                  zu_ml(ji,jj) = zu / zthick
-                  zv_ml(ji,jj) = zv / zthick
-                  zdt_ml(ji,jj) = zt_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_tem)
-                  zds_ml(ji,jj) = zs_ml(ji,jj) - tsn(ji,jj,ibld(ji,jj),jp_sal)
-                  zdu_ml(ji,jj) = zu_ml(ji,jj) - ( ub(ji,jj,ibld(ji,jj)) + ub(ji-1,jj,ibld(ji,jj) ) ) &
-                        &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-                  zdv_ml(ji,jj) = zv_ml(ji,jj) - ( vb(ji,jj,ibld(ji,jj)) + vb(ji,jj-1,ibld(ji,jj) ) ) &
-                        &    / MAX(1. , vmask(ji,jj,ibld(ji,jj) ) + vmask(ji,jj-1,ibld(ji,jj) ) )
-                  zdb_ml(ji,jj) = grav * zthermal * zdt_ml(ji,jj) - grav * zbeta * zds_ml(ji,jj)
-               ENDIF
-            ENDIF
-         END DO
-      END DO
-    !
+!
+    ! Average over the depth of the mixed layer in the convective boundary layer
+    ! Alan: do we need zb_ml?
+    CALL zdf_osm_vertical_average( imld, zt_ml, zs_ml, zu_ml, zv_ml, zdt_ml, zds_ml, zdb_ml, zdu_ml, zdv_ml )
     ! rotate mean currents and changes onto wind align co-ordinates
     !
-
-      DO jj = 2, jpjm1
-         DO ji = 2, jpim1
-            ztemp = zu_ml(ji,jj)
-            zu_ml(ji,jj) = zu_ml(ji,jj) * zcos_wind(ji,jj) + zv_ml(ji,jj) * zsin_wind(ji,jj)
-            zv_ml(ji,jj) = zv_ml(ji,jj) * zcos_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
-            ztemp = zdu_ml(ji,jj)
-            zdu_ml(ji,jj) = zdu_ml(ji,jj) * zcos_wind(ji,jj) + zdv_ml(ji,jj) * zsin_wind(ji,jj)
-            zdv_ml(ji,jj) = zdv_ml(ji,jj) * zsin_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
-    !
-            ztemp = zu_bl(ji,jj)
-            zu_bl = zu_bl(ji,jj) * zcos_wind(ji,jj) + zv_bl(ji,jj) * zsin_wind(ji,jj)
-            zv_bl(ji,jj) = zv_bl(ji,jj) * zcos_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
-            ztemp = zdu_bl(ji,jj)
-            zdu_bl(ji,jj) = zdu_bl(ji,jj) * zcos_wind(ji,jj) + zdv_bl(ji,jj) * zsin_wind(ji,jj)
-            zdv_bl(ji,jj) = zdv_bl(ji,jj) * zsin_wind(ji,jj) - ztemp * zsin_wind(ji,jj)
-         END DO
-      END DO
-
+    CALL zdf_osm_velocity_rotation( zcos_wind, zsin_wind, zu_ml, zv_ml, zdu_ml, zdv_ml )
+    CALL zdf_osm_velocity_rotation( zcos_wind, zsin_wind, zu_bl, zv_bl, zdu_bl, zdv_bl )
      zuw_bse = 0._wp
      zvw_bse = 0._wp
+     zwth_ent = 0._wp
+     zws_ent = 0._wp
      DO jj = 2, jpjm1
         DO ji = 2, jpim1
-
-           IF ( lconv(ji,jj) ) THEN
-              IF ( zdb_bl(ji,jj) > 0._wp ) THEN
-                 zwth_ent(ji,jj) = zwb_ent(ji,jj) * zdt_ml(ji,jj) / (zdb_ml(ji,jj) + epsln)
-                 zws_ent(ji,jj) = zwb_ent(ji,jj) * zds_ml(ji,jj) / (zdb_ml(ji,jj) + epsln)
+           IF ( ibld(ji,jj) < mbkt(ji,jj) ) THEN
+              IF ( lconv(ji,jj) ) THEN
+         	 zuw_bse(ji,jj) = -0.0075*((zvstr(ji,jj)**3+0.5*zwstrc(ji,jj)**3)**pthird*zdu_ml(ji,jj) + &
+                      &                    1.5*zustar(ji,jj)**2*(zhbl(ji,jj)-zhml(ji,jj)) )/ &
+                      &                     ( zhml(ji,jj)*MIN(zla(ji,jj)**(8./3.),1.) + epsln)
+	         zvw_bse(ji,jj) = 0.01*(-(zvstr(ji,jj)**3+0.5*zwstrc(ji,jj)**3)**pthird*zdv_ml(ji,jj)+ &
+                      &                    2.0*ff_t(ji,jj)*zustke(ji,jj)*dstokes(ji,jj)*zla(ji,jj))
+                 IF ( zdb_ml(ji,jj) > 0._wp ) THEN
+                    zwth_ent(ji,jj) = zwb_ent(ji,jj) * zdt_ml(ji,jj) / (zdb_ml(ji,jj) + epsln)
+                    zws_ent(ji,jj) = zwb_ent(ji,jj) * zds_ml(ji,jj) / (zdb_ml(ji,jj) + epsln)
+                 ENDIF
+              ELSE
+                 zwth_ent(ji,jj) = -2.0 * zwthav(ji,jj) * ( (1.0 - 0.8) - ( 1.0 - 0.8)**(3.0/2.0) )
+                 zws_ent(ji,jj) = -2.0 * zwsav(ji,jj) * ( (1.0 - 0.8 ) - ( 1.0 - 0.8 )**(3.0/2.0) )
               ENDIF
-           ELSE
-              zwth_ent(ji,jj) = -2.0 * zwthav(ji,jj) * ( (1.0 - 0.8) - ( 1.0 - 0.8)**(3.0/2.0) )
-              zws_ent(ji,jj) = -2.0 * zwsav(ji,jj) * ( (1.0 - 0.8 ) - ( 1.0 - 0.8 )**(3.0/2.0) )
            ENDIF
         END DO
@@ -764,100 +589,11 @@
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
-       DO jj = 2, jpjm1
-          DO ji = 2, jpim1
-          !
-             IF ( lconv (ji,jj) ) THEN
-             ! Unstable conditions
-                IF( zdb_bl(ji,jj) > 0._wp ) THEN
-                ! calculate pycnocline profiles, no need if zdb_bl <= 0. since profile is zero and arrays have been initialized to zero
-                   ztgrad = ( zdt_ml(ji,jj) / zdh(ji,jj) )
-                   zsgrad = ( zds_ml(ji,jj) / zdh(ji,jj) )
-                   zbgrad = ( zdb_ml(ji,jj) / zdh(ji,jj) )
-                   DO jk = 2 , ibld(ji,jj)
-                      znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
-                      zdtdz_pyc(ji,jj,jk) =  ztgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                      zdbdz_pyc(ji,jj,jk) =  zbgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                      zdsdz_pyc(ji,jj,jk) =  zsgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                   END DO
-                ENDIF
-             ELSE
-             ! stable conditions
-             ! if pycnocline profile only defined when depth steady of increasing.
-                IF ( zdhdt(ji,jj) >= 0.0 ) THEN        ! Depth increasing, or steady.
-                   IF ( zdb_bl(ji,jj) > 0._wp ) THEN
-                     IF ( zhol(ji,jj) >= 0.5 ) THEN      ! Very stable - 'thick' pycnocline
-                         ztgrad = zdt_bl(ji,jj) / zhbl(ji,jj)
-                         zsgrad = zds_bl(ji,jj) / zhbl(ji,jj)
-                         zbgrad = zdb_bl(ji,jj) / zhbl(ji,jj)
-                         DO jk = 2, ibld(ji,jj)
-                            znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
-                            zdtdz_pyc(ji,jj,jk) =  ztgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
-                            zdbdz_pyc(ji,jj,jk) =  zbgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
-                            zdsdz_pyc(ji,jj,jk) =  zsgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
-                         END DO
-                     ELSE                                   ! Slightly stable - 'thin' pycnoline - needed when stable layer begins to form.
-                         ztgrad = zdt_bl(ji,jj) / zdh(ji,jj)
-                         zsgrad = zds_bl(ji,jj) / zdh(ji,jj)
-                         zbgrad = zdb_bl(ji,jj) / zdh(ji,jj)
-                         DO jk = 2, ibld(ji,jj)
-                            znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
-                            zdtdz_pyc(ji,jj,jk) =  ztgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                            zdbdz_pyc(ji,jj,jk) =  zbgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                            zdsdz_pyc(ji,jj,jk) =  zsgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                         END DO
-                      ENDIF ! IF (zhol >=0.5)
-                   ENDIF    ! IF (zdb_bl> 0.)
-                ENDIF       ! IF (zdhdt >= 0) zdhdt < 0 not considered since pycnocline profile is zero, profile arrays are intialized to zero
-             ENDIF          ! IF (lconv)
-            !
-          END DO
-       END DO
-!
-       DO jj = 2, jpjm1
-          DO ji = 2, jpim1
-          !
-             IF ( lconv (ji,jj) ) THEN
-             ! Unstable conditions
-                 zugrad = ( zdu_ml(ji,jj) / zdh(ji,jj) ) + 0.275 * zustar(ji,jj)*zustar(ji,jj) / &
-               & (( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * zhml(ji,jj) ) / zla(ji,jj)**(8.0/3.0)
-                zvgrad = ( zdv_ml(ji,jj) / zdh(ji,jj) ) + 3.5 * ff_t(ji,jj) * zustke(ji,jj) / &
-              & ( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
-                DO jk = 2 , ibld(ji,jj)-1
-                   znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
-                   zdudz_pyc(ji,jj,jk) =  zugrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                   zdvdz_pyc(ji,jj,jk) = zvgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
-                END DO
-             ELSE
-             ! stable conditions
-                zugrad = 3.25 * zdu_bl(ji,jj) / zhbl(ji,jj)
-                zvgrad = 2.75 * zdv_bl(ji,jj) / zhbl(ji,jj)
-                DO jk = 2, ibld(ji,jj)
-                   znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
-                   IF ( znd < 1.0 ) THEN
-                      zdudz_pyc(ji,jj,jk) = zugrad * EXP( -40.0 * ( znd - 1.0 )**2 )
-                   ELSE
-                      zdudz_pyc(ji,jj,jk) = zugrad * EXP( -20.0 * ( znd - 1.0 )**2 )
-                   ENDIF
-                   zdvdz_pyc(ji,jj,jk) = zvgrad * EXP( -20.0 * ( znd - 0.85 )**2 )
-                END DO
-             ENDIF
-            !
-          END DO
-       END DO
+      CALL zdf_osm_external_gradients( zdtdz_ext, zdsdz_ext, zdbdz_ext )
+      CALL zdf_osm_pycnocline_scalar_profiles( zdtdz_pyc, zdsdz_pyc, zdbdz_pyc )
+      CALL zdf_osm_pycnocline_shear_profiles( zdudz_pyc, zdvdz_pyc )
        !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        ! Eddy viscosity/diffusivity and non-gradient terms in the flux-gradient relationship
        !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
-      ! WHERE ( lconv )
-      !     zdifml_sc = zhml * ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird
-      !     zvisml_sc = zdifml_sc
-      !     zdifpyc_sc = 0.165 * ( zwstrl**3 + zwstrc**3 )**pthird * ( zhbl - zhml )
-      !     zvispyc_sc = 0.142 * ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * ( zhbl - zhml )
-      !     zbeta_d_sc = 1.0 - (0.165 / 0.8 * ( zhbl - zhml ) / zhbl )**p2third
-      !     zbeta_v_sc = 1.0 -  2.0 * (0.142 /0.375) * (zhbl - zhml ) / zhml
-      !  ELSEWHERE
-      !     zdifml_sc = zwstrl * zhbl * EXP ( -( zhol / 0.183_wp )**2 )
-      !     zvisml_sc = zwstrl * zhbl * EXP ( -( zhol / 0.183_wp )**2 )
-      !  ENDWHERE
        DO jj = 2, jpjm1
           DO ji = 2, jpim1
@@ -868,11 +604,11 @@
                zvispyc_sc(ji,jj) = 0.142 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * zdh(ji,jj)
                zbeta_d_sc(ji,jj) = 1.0 - (0.165 / 0.8 * zdh(ji,jj) / zhbl(ji,jj) )**p2third
-               zbeta_v_sc(ji,jj) = 1.0 -  2.0 * (0.142 /0.375) * zdh(ji,jj) / zhml(ji,jj)
+               zbeta_v_sc(ji,jj) = 1.0 -  2.0 * (0.142 /0.375) * zdh(ji,jj) / ( zhml(ji,jj) + epsln )
              ELSE
                zdifml_sc(ji,jj) = zvstr(ji,jj) * zhbl(ji,jj) * EXP ( -( zhol(ji,jj) / 0.6_wp )**2 )
                zvisml_sc(ji,jj) = zvstr(ji,jj) * zhbl(ji,jj) * EXP ( -( zhol(ji,jj) / 0.6_wp )**2 )
-            END IF
-        END DO
-    END DO
+             END IF
+          END DO
+       END DO
 !
        DO jj = 2, jpjm1
@@ -889,14 +625,23 @@
                 ! pycnocline - if present linear profile
                 IF ( zdh(ji,jj) > 0._wp ) THEN
+                   zgamma_b = 6.0
                    DO jk = imld(ji,jj)+1 , ibld(ji,jj)
                        zznd_pyc = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
                        !
-                       zdiffut(ji,jj,jk) = zdifpyc_sc(ji,jj) * ( 1.0 + zznd_pyc )
+                       zdiffut(ji,jj,jk) = zdifpyc_sc(ji,jj) * EXP( zgamma_b * zznd_pyc )
                        !
-                       zviscos(ji,jj,jk) = zvispyc_sc(ji,jj) * ( 1.0 + zznd_pyc )
+                       zviscos(ji,jj,jk) = zvispyc_sc(ji,jj) * EXP( zgamma_b * zznd_pyc )
                    END DO
+                   IF ( ibld_ext == 0 ) THEN
+                       zdiffut(ji,jj,ibld(ji,jj)) = 0._wp
+                       zviscos(ji,jj,ibld(ji,jj)) = 0._wp
+                   ELSE
+                       zdiffut(ji,jj,ibld(ji,jj)) = zdhdt(ji,jj) * ( hbl(ji,jj) - gdepw_n(ji, jj, ibld(ji,jj)-1) )
+                       zviscos(ji,jj,ibld(ji,jj)) = zdhdt(ji,jj) * ( hbl(ji,jj) - gdepw_n(ji, jj, ibld(ji,jj)-1) )
+                   ENDIF
                 ENDIF
-                ! Temporay fix to ensure zdiffut is +ve; won't be necessary with wn taken out
-                zdiffut(ji,jj,ibld(ji,jj)) = zdhdt(ji,jj)* e3t_n(ji,jj,ibld(ji,jj))
+                ! Temporary fix to ensure zdiffut is +ve; won't be necessary with wn taken out
+                zdiffut(ji,jj,ibld(ji,jj)) = MAX(zdhdt(ji,jj) * e3t_n(ji,jj,ibld(ji,jj)), 1.e-6)
+                zviscos(ji,jj,ibld(ji,jj)) = MAX(zdhdt(ji,jj) * e3t_n(ji,jj,ibld(ji,jj)), 1.e-5)
                 ! could be taken out, take account of entrainment represents as a diffusivity
                 ! should remove w from here, represents entrainment
@@ -908,6 +653,14 @@
                    zviscos(ji,jj,jk) = 0.375 * zvisml_sc(ji,jj) * zznd_ml * (1.0 - zznd_ml) * ( 1.0 - zznd_ml**2 )
                 END DO
+
+                IF ( ibld_ext == 0 ) THEN
+                   zdiffut(ji,jj,ibld(ji,jj)) = 0._wp
+                   zviscos(ji,jj,ibld(ji,jj)) = 0._wp
+                ELSE
+                   zdiffut(ji,jj,ibld(ji,jj)) = MAX(zdhdt(ji,jj), 0._wp) * e3w_n(ji, jj, ibld(ji,jj))
+                   zviscos(ji,jj,ibld(ji,jj)) = MAX(zdhdt(ji,jj), 0._wp) * e3w_n(ji, jj, ibld(ji,jj))
+                ENDIF
              ENDIF   ! end if ( lconv )
-!
+             !
           END DO  ! end of ji loop
        END DO     ! end of jj loop
@@ -952,15 +705,17 @@
        END DO     ! end of jj loop
 
-
 ! Stokes term in flux-gradient relationship (note in zsc_uw_n don't use zvstr since term needs to go to zero as zwstrl goes to zero)
        WHERE ( lconv )
-          zsc_uw_1 = ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * zustke /( 1.0 - 1.0 * 6.5 * zla**(8.0/3.0) )
-          zsc_uw_2 = ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * zustke / ( zla**(8.0/3.0) + epsln )
-          zsc_vw_1 = ff_t * zhml * zustke**3 * zla**(8.0/3.0) / ( ( zvstr**3 + 0.5 * zwstrc**3 )**(2.0/3.0) + epsln )
+          zsc_uw_1 = ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * zustke / MAX( ( 1.0 - 1.0 * 6.5 * zla**(8.0/3.0) ), 0.2 )
+          zsc_uw_2 = ( zwstrl**3 + 0.5 * zwstrc**3 )**pthird * zustke / MIN( zla**(8.0/3.0) + epsln, 0.12 )
+          zsc_vw_1 = ff_t * zhml * zustke**3 * MIN( zla**(8.0/3.0), 0.12 ) / ( ( zvstr**3 + 0.5 * zwstrc**3 )**(2.0/3.0) + epsln )
        ELSEWHERE
           zsc_uw_1 = zustar**2
-          zsc_vw_1 = ff_t * zhbl * zustke**3 * zla**(8.0/3.0) / (zvstr**2 + epsln)
+          zsc_vw_1 = ff_t * zhbl * zustke**3 * MIN( zla**(8.0/3.0), 0.12 ) / (zvstr**2 + epsln)
        ENDWHERE
-
+       IF(ln_dia_osm) THEN
+          IF ( iom_use("ghamu_00") ) CALL iom_put( "ghamu_00", wmask*ghamu )
+          IF ( iom_use("ghamv_00") ) CALL iom_put( "ghamv_00", wmask*ghamv )
+       END IF
        DO jj = 2, jpjm1
           DO ji = 2, jpim1
@@ -1007,5 +762,5 @@
                    zl_l = 2.0 * ( 1.0 - EXP ( - 2.0 * ( zznd_ml - zznd_ml**3 / 3.0 ) ) )                                           &
                         &     * ( 1.0 - EXP ( - 5.0 * (     1.0 - zznd_ml          ) ) ) * ( 1.0 + dstokes(ji,jj) / zhml (ji,jj) )
-                   zl_eps = zl_l + ( zl_c - zl_l ) / ( 1.0 + EXP ( 3.0 * LOG10 ( - zhol(ji,jj) ) ) ) ** (3.0/2.0)
+                   zl_eps = zl_l + ( zl_c - zl_l ) / ( 1.0 + EXP ( -3.0 * LOG10 ( - zhol(ji,jj) ) ) ) ** (3.0/2.0)
                    ! non-gradient buoyancy terms
                    ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 0.3 * 0.5 * zsc_wth_1(ji,jj) * zl_eps * zhml(ji,jj) / ( 0.15 + zznd_ml )
@@ -1020,5 +775,4 @@
           END DO   ! ji loop
        END DO      ! jj loop
-
 
        WHERE ( lconv )
@@ -1051,4 +805,8 @@
        END DO           ! jj loop
 
+       IF(ln_dia_osm) THEN
+          IF ( iom_use("ghamu_0") ) CALL iom_put( "ghamu_0", wmask*ghamu )
+          IF ( iom_use("zsc_uw_1_0") ) CALL iom_put( "zsc_uw_1_0", tmask(:,:,1)*zsc_uw_1 )
+       END IF
 ! Transport term in flux-gradient relationship [note : includes ROI ratio (X0.3) ]
 
@@ -1089,5 +847,4 @@
        END DO      ! jj loop
 
-
        WHERE ( lconv )
           zsc_uw_1 = zustar**2
@@ -1134,4 +891,13 @@
           END DO
        END DO
+
+       IF(ln_dia_osm) THEN
+          IF ( iom_use("ghamu_f") ) CALL iom_put( "ghamu_f", wmask*ghamu )
+          IF ( iom_use("ghamv_f") ) CALL iom_put( "ghamv_f", wmask*ghamv )
+          IF ( iom_use("zsc_uw_1_f") ) CALL iom_put( "zsc_uw_1_f", tmask(:,:,1)*zsc_uw_1 )
+          IF ( iom_use("zsc_vw_1_f") ) CALL iom_put( "zsc_vw_1_f", tmask(:,:,1)*zsc_vw_1 )
+          IF ( iom_use("zsc_uw_2_f") ) CALL iom_put( "zsc_uw_2_f", tmask(:,:,1)*zsc_uw_2 )
+          IF ( iom_use("zsc_vw_2_f") ) CALL iom_put( "zsc_vw_2_f", tmask(:,:,1)*zsc_vw_2 )
+       END IF
 !
 ! Make surface forced velocity non-gradient terms go to zero at the base of the mixed layer.
@@ -1165,4 +931,8 @@
       END DO
 
+       IF(ln_dia_osm) THEN
+          IF ( iom_use("ghamu_b") ) CALL iom_put( "ghamu_b", wmask*ghamu )
+          IF ( iom_use("ghamv_b") ) CALL iom_put( "ghamv_b", wmask*ghamv )
+       END IF
       ! pynocline contributions
        ! Temporary fix to avoid instabilities when zdb_bl becomes very very small
@@ -1170,13 +940,15 @@
        DO jj = 2, jpjm1
           DO ji = 2, jpim1
-             DO jk= 2, ibld(ji,jj)
-                znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
-                ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zdiffut(ji,jj,jk) * zdtdz_pyc(ji,jj,jk)
-                ghams(ji,jj,jk) = ghams(ji,jj,jk) + zdiffut(ji,jj,jk) * zdsdz_pyc(ji,jj,jk)
-                ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zviscos(ji,jj,jk) * zdudz_pyc(ji,jj,jk)
-                ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zsc_uw_1(ji,jj) * ( 1.0 - znd )**(7.0/4.0) * zdbdz_pyc(ji,jj,jk)
-                ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zviscos(ji,jj,jk) * zdvdz_pyc(ji,jj,jk)
-             END DO
-           END DO
+             IF ( ibld(ji,jj) + ibld_ext < mbkt(ji,jj) ) THEN
+                DO jk= 2, ibld(ji,jj)
+                   znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                   ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zdiffut(ji,jj,jk) * zdtdz_pyc(ji,jj,jk)
+                   ghams(ji,jj,jk) = ghams(ji,jj,jk) + zdiffut(ji,jj,jk) * zdsdz_pyc(ji,jj,jk)
+                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zviscos(ji,jj,jk) * zdudz_pyc(ji,jj,jk)
+                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zsc_uw_1(ji,jj) * ( 1.0 - znd )**(7.0/4.0) * zdbdz_pyc(ji,jj,jk)
+                   ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zviscos(ji,jj,jk) * zdvdz_pyc(ji,jj,jk)
+                END DO
+             END IF
+          END DO
        END DO
 
@@ -1185,9 +957,9 @@
        DO jj=2, jpjm1
           DO ji = 2, jpim1
-             IF ( lconv(ji,jj) ) THEN
+            IF ( lconv(ji,jj) .AND. ibld(ji,jj) + ibld_ext < mbkt(ji,jj)) THEN
                DO jk = 1, imld(ji,jj) - 1
                   znd=gdepw_n(ji,jj,jk) / zhml(ji,jj)
-                  ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zwth_ent(ji,jj) * znd
-                  ghams(ji,jj,jk) = ghams(ji,jj,jk) + zws_ent(ji,jj) * znd
+                  ! ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zwth_ent(ji,jj) * znd
+                  ! ghams(ji,jj,jk) = ghams(ji,jj,jk) + zws_ent(ji,jj) * znd
                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zuw_bse(ji,jj) * znd
                   ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zvw_bse(ji,jj) * znd
@@ -1195,18 +967,27 @@
                DO jk = imld(ji,jj), ibld(ji,jj)
                   znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) / zdh(ji,jj)
-                  ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zwth_ent(ji,jj) * ( 1.0 + znd )
-                  ghams(ji,jj,jk) = ghams(ji,jj,jk) + zws_ent(ji,jj) * ( 1.0 + znd )
+                  ! ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zwth_ent(ji,jj) * ( 1.0 + znd )
+                  ! ghams(ji,jj,jk) = ghams(ji,jj,jk) + zws_ent(ji,jj) * ( 1.0 + znd )
                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) + zuw_bse(ji,jj) * ( 1.0 + znd )
                   ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zvw_bse(ji,jj) * ( 1.0 + znd )
                 END DO
              ENDIF
-             ghamt(ji,jj,ibld(ji,jj)) = 0._wp
-             ghams(ji,jj,ibld(ji,jj)) = 0._wp
-             ghamu(ji,jj,ibld(ji,jj)) = 0._wp
-             ghamv(ji,jj,ibld(ji,jj)) = 0._wp
+
+             ghamt(ji,jj,ibld(ji,jj)+ibld_ext) = 0._wp
+             ghams(ji,jj,ibld(ji,jj)+ibld_ext) = 0._wp
+             ghamu(ji,jj,ibld(ji,jj)+ibld_ext) = 0._wp
+             ghamv(ji,jj,ibld(ji,jj)+ibld_ext) = 0._wp
           END DO       ! ji loop
        END DO          ! jj loop
 
-
+       IF(ln_dia_osm) THEN
+          IF ( iom_use("ghamu_1") ) CALL iom_put( "ghamu_1", wmask*ghamu )
+          IF ( iom_use("ghamv_1") ) CALL iom_put( "ghamv_1", wmask*ghamv )
+          IF ( iom_use("zuw_bse") ) CALL iom_put( "zuw_bse", tmask(:,:,1)*zuw_bse )
+          IF ( iom_use("zvw_bse") ) CALL iom_put( "zvw_bse", tmask(:,:,1)*zvw_bse )
+          IF ( iom_use("zdudz_pyc") ) CALL iom_put( "zdudz_pyc", wmask*zdudz_pyc )
+          IF ( iom_use("zdvdz_pyc") ) CALL iom_put( "zdvdz_pyc", wmask*zdvdz_pyc )
+          IF ( iom_use("zviscos") ) CALL iom_put( "zviscos", wmask*zviscos )
+       END IF
        !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        ! Need to put in code for contributions that are applied explicitly to
@@ -1232,4 +1013,6 @@
        IF(ln_dia_osm) THEN
           IF ( iom_use("zdtdz_pyc") ) CALL iom_put( "zdtdz_pyc", wmask*zdtdz_pyc )
+          IF ( iom_use("zdsdz_pyc") ) CALL iom_put( "zdsdz_pyc", wmask*zdsdz_pyc )
+          IF ( iom_use("zdbdz_pyc") ) CALL iom_put( "zdbdz_pyc", wmask*zdbdz_pyc )
        END IF
 
@@ -1286,6 +1069,55 @@
        END IF ! ln_convmix = .true.
 
+
+ 
+       IF ( ln_osm_mle ) THEN  ! set up diffusivity and non-gradient mixing
+          DO jj = 2 , jpjm1
+             DO ji = 2, jpim1
+                IF ( lconv(ji,jj) .AND. mld_prof(ji,jj) - ibld(ji,jj) > 1 ) THEN ! MLE mmixing extends below the OSBL.
+            ! Calculate MLE flux profiles
+                   ! DO jk = 1, mld_prof(ji,jj)
+                   !    znd = - gdepw_n(ji,jj,jk) / MAX(zhmle(ji,jj),epsln)
+                   !    ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + &
+                   !         & zwt_fk(ji,jj) * ( 1.0 - ( 2.0 * znd + 1.0 )**2 ) * ( 1.0 + r5_21 * ( 2.0 * znd + 1.0 )**2 )
+                   !    ghams(ji,jj,jk) = ghams(ji,jj,jk) + &
+                   !         & zws_fk(ji,jj) * ( 1.0 - ( 2.0 * znd + 1.0 )**2 ) * ( 1.0 + r5_21 * ( 2.0 * znd + 1.0 )**2 )
+                   ! END DO
+            ! Calculate MLE flux contribution from surface fluxes
+                   DO jk = 1, ibld(ji,jj)
+                     znd = gdepw_n(ji,jj,jk) / MAX(zhbl(ji,jj),epsln)
+                     ghamt(ji,jj,jk) = ghamt(ji,jj,jk) - zwth0(ji,jj) * ( 1.0 - znd )
+                     ghams(ji,jj,jk) = ghams(ji,jj,jk) - zws0(ji,jj) * ( 1.0 - znd )
+                    END DO
+                    DO jk = 1, mld_prof(ji,jj)
+                      znd = gdepw_n(ji,jj,jk) / MAX(zhmle(ji,jj),epsln)
+                      ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zwth0(ji,jj) * ( 1.0 - znd )
+                      ghams(ji,jj,jk) = ghams(ji,jj,jk) + zws0(ji,jj) * ( 1.0 -znd )
+                    END DO
+            ! Viscosity for MLEs
+                    DO jk = ibld(ji,jj), mld_prof(ji,jj)
+                      zdiffut(ji,jj,jk) = MAX( zdiffut(ji,jj,jk), zdiff_mle(ji,jj) )
+                    END DO
+            ! Iterate to find approx vertical index for depth 1.1*zhmle(ji,jj)
+                    jl = MIN(mld_prof(ji,jj) + 2, mbkt(ji,jj))
+                    jl = MIN( MAX(INT( 0.1 * zhmle(ji,jj) / e3t_n(ji,jj,jl)), 2 ) + mld_prof(ji,jj), mbkt(ji,jj))
+                    DO jk = mld_prof(ji,jj),  jl
+                       zdiffut(ji,jj,jk) = MAX( zdiffut(ji,jj,jk), zdiff_mle(ji,jj) * &
+                            & ( gdepw_n(ji,jj,jk) - gdepw_n(ji,jj,jl) ) / &
+                            & ( gdepw_n(ji,jj,mld_prof(ji,jj)) - gdepw_n(ji,jj,jl) - epsln))
+                    END DO
+                ENDIF
+            END DO
+          END DO
+       ENDIF
+
+       IF(ln_dia_osm) THEN
+          IF ( iom_use("zdtdz_pyc") ) CALL iom_put( "zdtdz_pyc", wmask*zdtdz_pyc )
+          IF ( iom_use("zdsdz_pyc") ) CALL iom_put( "zdsdz_pyc", wmask*zdsdz_pyc )
+          IF ( iom_use("zdbdz_pyc") ) CALL iom_put( "zdbdz_pyc", wmask*zdbdz_pyc )
+       END IF
+
+
        ! Lateral boundary conditions on zvicos (sign unchanged), needed to caclulate viscosities on u and v grids
-       CALL lbc_lnk( 'zdfosm', zviscos(:,:,:), 'W', 1. )
+       !CALL lbc_lnk( zviscos(:,:,:), 'W', 1. )
 
        ! GN 25/8: need to change tmask --> wmask
@@ -1316,10 +1148,12 @@
            END DO
         END DO
+        ! Lateral boundary conditions on final outputs for hbl,  on T-grid (sign unchanged)
+        CALL lbc_lnk_multi( 'zdfosm', hbl, 'T', 1., dh, 'T', 1., hmle, 'T', 1. )
         ! Lateral boundary conditions on final outputs for gham[ts],  on W-grid  (sign unchanged)
         ! Lateral boundary conditions on final outputs for gham[uv],  on [UV]-grid  (sign unchanged)
         CALL lbc_lnk_multi( 'zdfosm', ghamt, 'W', 1. , ghams, 'W', 1.,   &
-         &                  ghamu, 'U', 1. , ghamv, 'V', 1. )
-
-       IF(ln_dia_osm) THEN
+         &                  ghamu, 'U', -1. , ghamv, 'V', -1. )
+
+      IF(ln_dia_osm) THEN
          SELECT CASE (nn_osm_wave)
          ! Stokes drift set by assumimg onstant La#=0.3(=0)  or Pierson-Moskovitz spectrum (=1).
@@ -1330,6 +1164,11 @@
          ! Stokes drift read in from sbcwave  (=2).
          CASE(2)
-            IF ( iom_use("us_x") ) CALL iom_put( "us_x", ut0sd )               ! x surface Stokes drift
-            IF ( iom_use("us_y") ) CALL iom_put( "us_y", vt0sd )               ! y surface Stokes drift
+            IF ( iom_use("us_x") ) CALL iom_put( "us_x", ut0sd*umask(:,:,1) )               ! x surface Stokes drift
+            IF ( iom_use("us_y") ) CALL iom_put( "us_y", vt0sd*vmask(:,:,1) )               ! y surface Stokes drift
+            IF ( iom_use("wmp") ) CALL iom_put( "wmp", wmp*tmask(:,:,1) )                   ! wave mean period
+            IF ( iom_use("hsw") ) CALL iom_put( "hsw", hsw*tmask(:,:,1) )                   ! significant wave height
+            IF ( iom_use("wmp_NP") ) CALL iom_put( "wmp_NP", (2.*rpi*1.026/(0.877*grav) )*wndm*tmask(:,:,1) )                  ! wave mean period from NP spectrum
+            IF ( iom_use("hsw_NP") ) CALL iom_put( "hsw_NP", (0.22/grav)*wndm**2*tmask(:,:,1) )                   ! significant wave height from NP spectrum
+            IF ( iom_use("wndm") ) CALL iom_put( "wndm", wndm*tmask(:,:,1) )                   ! U_10
             IF ( iom_use("wind_wave_abs_power") ) CALL iom_put( "wind_wave_abs_power", 1000.*rau0*tmask(:,:,1)*zustar**2* &
                  & SQRT(ut0sd**2 + vt0sd**2 ) )
@@ -1342,5 +1181,12 @@
          IF ( iom_use("zws0") ) CALL iom_put( "zws0", tmask(:,:,1)*zws0 )                ! <Sw_0>
          IF ( iom_use("hbl") ) CALL iom_put( "hbl", tmask(:,:,1)*hbl )                  ! boundary-layer depth
-         IF ( iom_use("hbli") ) CALL iom_put( "hbli", tmask(:,:,1)*hbli )               ! Initial boundary-layer depth
+         IF ( iom_use("ibld") ) CALL iom_put( "ibld", tmask(:,:,1)*ibld )               ! boundary-layer max k
+         IF ( iom_use("zdt_bl") ) CALL iom_put( "zdt_bl", tmask(:,:,1)*zdt_bl )           ! dt at ml base
+         IF ( iom_use("zds_bl") ) CALL iom_put( "zds_bl", tmask(:,:,1)*zds_bl )           ! ds at ml base
+         IF ( iom_use("zdb_bl") ) CALL iom_put( "zdb_bl", tmask(:,:,1)*zdb_bl )           ! db at ml base
+         IF ( iom_use("zdu_bl") ) CALL iom_put( "zdu_bl", tmask(:,:,1)*zdu_bl )           ! du at ml base
+         IF ( iom_use("zdv_bl") ) CALL iom_put( "zdv_bl", tmask(:,:,1)*zdv_bl )           ! dv at ml base
+         IF ( iom_use("dh") ) CALL iom_put( "dh", tmask(:,:,1)*dh )               ! Initial boundary-layer depth
+         IF ( iom_use("hml") ) CALL iom_put( "hml", tmask(:,:,1)*hml )               ! Initial boundary-layer depth
          IF ( iom_use("dstokes") ) CALL iom_put( "dstokes", tmask(:,:,1)*dstokes )      ! Stokes drift penetration depth
          IF ( iom_use("zustke") ) CALL iom_put( "zustke", tmask(:,:,1)*zustke )            ! Stokes drift magnitude at T-points
@@ -1348,18 +1194,789 @@
          IF ( iom_use("zwstrl") ) CALL iom_put( "zwstrl", tmask(:,:,1)*zwstrl )         ! Langmuir velocity scale
          IF ( iom_use("zustar") ) CALL iom_put( "zustar", tmask(:,:,1)*zustar )         ! friction velocity scale
+         IF ( iom_use("zvstr") ) CALL iom_put( "zvstr", tmask(:,:,1)*zvstr )         ! mixed velocity scale
+         IF ( iom_use("zla") ) CALL iom_put( "zla", tmask(:,:,1)*zla )         ! langmuir #
          IF ( iom_use("wind_power") ) CALL iom_put( "wind_power", 1000.*rau0*tmask(:,:,1)*zustar**3 ) ! BL depth internal to zdf_osm routine
          IF ( iom_use("wind_wave_power") ) CALL iom_put( "wind_wave_power", 1000.*rau0*tmask(:,:,1)*zustar**2*zustke )
          IF ( iom_use("zhbl") ) CALL iom_put( "zhbl", tmask(:,:,1)*zhbl )               ! BL depth internal to zdf_osm routine
          IF ( iom_use("zhml") ) CALL iom_put( "zhml", tmask(:,:,1)*zhml )               ! ML depth internal to zdf_osm routine
-         IF ( iom_use("zdh") ) CALL iom_put( "zdh", tmask(:,:,1)*zdh )               ! ML depth internal to zdf_osm routine
+         IF ( iom_use("imld") ) CALL iom_put( "imld", tmask(:,:,1)*imld )               ! index for ML depth internal to zdf_osm routine
+         IF ( iom_use("zdh") ) CALL iom_put( "zdh", tmask(:,:,1)*zdh )                  ! pyc thicknessh internal to zdf_osm routine
          IF ( iom_use("zhol") ) CALL iom_put( "zhol", tmask(:,:,1)*zhol )               ! ML depth internal to zdf_osm routine
-         IF ( iom_use("zwthav") ) CALL iom_put( "zwthav", tmask(:,:,1)*zwthav )               ! ML depth internal to zdf_osm routine
-         IF ( iom_use("zwth_ent") ) CALL iom_put( "zwth_ent", tmask(:,:,1)*zwth_ent )               ! ML depth internal to zdf_osm routine
-         IF ( iom_use("zt_ml") ) CALL iom_put( "zt_ml", tmask(:,:,1)*zt_ml )               ! average T in ML
+         IF ( iom_use("zwthav") ) CALL iom_put( "zwthav", tmask(:,:,1)*zwthav )         ! upward BL-avged turb temp flux
+         IF ( iom_use("zwth_ent") ) CALL iom_put( "zwth_ent", tmask(:,:,1)*zwth_ent )   ! upward turb temp entrainment flux
+         IF ( iom_use("zwb_ent") ) CALL iom_put( "zwb_ent", tmask(:,:,1)*zwb_ent )      ! upward turb buoyancy entrainment flux
+         IF ( iom_use("zws_ent") ) CALL iom_put( "zws_ent", tmask(:,:,1)*zws_ent )      ! upward turb salinity entrainment flux
+         IF ( iom_use("zt_ml") ) CALL iom_put( "zt_ml", tmask(:,:,1)*zt_ml )            ! average T in ML
+
+         IF ( iom_use("hmle") ) CALL iom_put( "hmle", tmask(:,:,1)*hmle )               ! FK layer depth
+         IF ( iom_use("zmld") ) CALL iom_put( "zmld", tmask(:,:,1)*zmld )               ! FK target layer depth
+         IF ( iom_use("zwb_fk") ) CALL iom_put( "zwb_fk", tmask(:,:,1)*zwb_fk )         ! FK b flux
+         IF ( iom_use("zwb_fk_b") ) CALL iom_put( "zwb_fk_b", tmask(:,:,1)*zwb_fk_b )   ! FK b flux averaged over ML
+         IF ( iom_use("mld_prof") ) CALL iom_put( "mld_prof", tmask(:,:,1)*mld_prof )! FK layer max k
+         IF ( iom_use("zdtdx") ) CALL iom_put( "zdtdx", umask(:,:,1)*zdtdx )            ! FK dtdx at u-pt
+         IF ( iom_use("zdtdy") ) CALL iom_put( "zdtdy", vmask(:,:,1)*zdtdy )            ! FK dtdy at v-pt
+         IF ( iom_use("zdsdx") ) CALL iom_put( "zdsdx", umask(:,:,1)*zdsdx )            ! FK dtdx at u-pt
+         IF ( iom_use("zdsdy") ) CALL iom_put( "zdsdy", vmask(:,:,1)*zdsdy )            ! FK dsdy at v-pt
+         IF ( iom_use("dbdx_mle") ) CALL iom_put( "dbdx_mle", umask(:,:,1)*dbdx_mle )            ! FK dbdx at u-pt
+         IF ( iom_use("dbdy_mle") ) CALL iom_put( "dbdy_mle", vmask(:,:,1)*dbdy_mle )            ! FK dbdy at v-pt
+         IF ( iom_use("zdiff_mle") ) CALL iom_put( "zdiff_mle", tmask(:,:,1)*zdiff_mle )! FK diff in MLE at t-pt
+         IF ( iom_use("zvel_mle") ) CALL iom_put( "zvel_mle", tmask(:,:,1)*zdiff_mle )! FK diff in MLE at t-pt
+
       END IF
-      ! Lateral boundary conditions on p_avt  (sign unchanged)
-      CALL lbc_lnk( 'zdfosm', p_avt(:,:,:), 'W', 1. )
+
+CONTAINS
+
+
+   ! Alan: do we need zb?
+   SUBROUTINE zdf_osm_vertical_average( jnlev_av, zt, zs, zu, zv, zdt, zds, zdb, zdu, zdv )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_vertical_average  ***
+     !!
+     !! ** Purpose : Determines vertical averages from surface to jnlev.
+     !!
+     !! ** Method  : Averages are calculated from the surface to jnlev.
+     !!              The external level used to calculate differences is ibld+ibld_ext
+     !!
+     !!----------------------------------------------------------------------
+
+        INTEGER, DIMENSION(jpi,jpj) :: jnlev_av  ! Number of levels to average over.
+
+        ! Alan: do we need zb?
+        REAL(wp), DIMENSION(jpi,jpj) :: zt, zs        ! Average temperature and salinity
+        REAL(wp), DIMENSION(jpi,jpj) :: zu,zv         ! Average current components
+        REAL(wp), DIMENSION(jpi,jpj) :: zdt, zds, zdb ! Difference between average and value at base of OSBL
+        REAL(wp), DIMENSION(jpi,jpj) :: zdu, zdv      ! Difference for velocity components.
+
+        INTEGER :: jk, ji, jj
+        REAL(wp) :: zthick, zthermal, zbeta
+
+
+        zt   = 0._wp
+        zs   = 0._wp
+        zu   = 0._wp
+        zv   = 0._wp
+        DO jj = 2, jpjm1                                 !  Vertical slab
+         DO ji = 2, jpim1
+            zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
+            zbeta    = rab_n(ji,jj,1,jp_sal)
+               ! average over depth of boundary layer
+            zthick = epsln
+            DO jk = 2, jnlev_av(ji,jj)
+               zthick = zthick + e3t_n(ji,jj,jk)
+               zt(ji,jj)   = zt(ji,jj)  + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_tem)
+               zs(ji,jj)   = zs(ji,jj)  + e3t_n(ji,jj,jk) * tsn(ji,jj,jk,jp_sal)
+               zu(ji,jj)   = zu(ji,jj)  + e3t_n(ji,jj,jk) &
+                     &            * ( ub(ji,jj,jk) + ub(ji - 1,jj,jk) ) &
+                     &            / MAX( 1. , umask(ji,jj,jk) + umask(ji - 1,jj,jk) )
+               zv(ji,jj)   = zv(ji,jj)  + e3t_n(ji,jj,jk) &
+                     &            * ( vb(ji,jj,jk) + vb(ji,jj - 1,jk) ) &
+                     &            / MAX( 1. , vmask(ji,jj,jk) + vmask(ji,jj - 1,jk) )
+            END DO
+            zt(ji,jj) = zt(ji,jj) / zthick
+            zs(ji,jj) = zs(ji,jj) / zthick
+            zu(ji,jj) = zu(ji,jj) / zthick
+            zv(ji,jj) = zv(ji,jj) / zthick
+            ! Alan: do we need zb?
+            zdt(ji,jj) = zt(ji,jj) - tsn(ji,jj,ibld(ji,jj)+ibld_ext,jp_tem)
+            zds(ji,jj) = zs(ji,jj) - tsn(ji,jj,ibld(ji,jj)+ibld_ext,jp_sal)
+            zdu(ji,jj) = zu(ji,jj) - ( ub(ji,jj,ibld(ji,jj)+ibld_ext) + ub(ji-1,jj,ibld(ji,jj)+ibld_ext ) ) &
+                     &    / MAX(1. , umask(ji,jj,ibld(ji,jj)+ibld_ext ) + umask(ji-1,jj,ibld(ji,jj)+ibld_ext ) )
+            zdv(ji,jj) = zv(ji,jj) - ( vb(ji,jj,ibld(ji,jj)+ibld_ext) + vb(ji,jj-1,ibld(ji,jj)+ibld_ext ) ) &
+                     &   / MAX(1. , vmask(ji,jj,ibld(ji,jj)+ibld_ext ) + vmask(ji,jj-1,ibld(ji,jj)+ibld_ext ) )
+            zdb(ji,jj) = grav * zthermal * zdt(ji,jj) - grav * zbeta * zds(ji,jj)
+         END DO
+        END DO
+   END SUBROUTINE zdf_osm_vertical_average
+
+   SUBROUTINE zdf_osm_velocity_rotation( zcos_w, zsin_w, zu, zv, zdu, zdv )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_velocity_rotation  ***
+     !!
+     !! ** Purpose : Rotates frame of reference of averaged velocity components.
+     !!
+     !! ** Method  : The velocity components are rotated into frame specified by zcos_w and zsin_w
+     !!
+     !!----------------------------------------------------------------------
+
+        REAL(wp), DIMENSION(jpi,jpj) :: zcos_w, zsin_w       ! Cos and Sin of rotation angle
+        REAL(wp), DIMENSION(jpi,jpj) :: zu, zv               ! Components of current
+        REAL(wp), DIMENSION(jpi,jpj) :: zdu, zdv             ! Change in velocity components across pycnocline
+
+        INTEGER :: ji, jj
+        REAL(wp) :: ztemp
+
+        DO jj = 2, jpjm1
+           DO ji = 2, jpim1
+              ztemp = zu(ji,jj)
+              zu(ji,jj) = zu(ji,jj) * zcos_w(ji,jj) + zv(ji,jj) * zsin_w(ji,jj)
+              zv(ji,jj) = zv(ji,jj) * zcos_w(ji,jj) - ztemp * zsin_w(ji,jj)
+              ztemp = zdu(ji,jj)
+              zdu(ji,jj) = zdu(ji,jj) * zcos_w(ji,jj) + zdv(ji,jj) * zsin_w(ji,jj)
+              zdv(ji,jj) = zdv(ji,jj) * zsin_w(ji,jj) - ztemp * zsin_w(ji,jj)
+           END DO
+        END DO
+    END SUBROUTINE zdf_osm_velocity_rotation
+
+    SUBROUTINE zdf_osm_external_gradients( zdtdz, zdsdz, zdbdz )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_osm_external_gradients  ***
+     !!
+     !! ** Purpose : Calculates the gradients below the OSBL
+     !!
+     !! ** Method  : Uses ibld and ibld_ext to determine levels to calculate the gradient.
+     !!
+     !!----------------------------------------------------------------------
+
+     REAL(wp), DIMENSION(jpi,jpj) :: zdtdz, zdsdz, zdbdz   ! External gradients of temperature, salinity and buoyancy.
+
+     INTEGER :: jj, ji, jkb, jkb1
+     REAL(wp) :: zthermal, zbeta
+
+
+     DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+           IF ( ibld(ji,jj) + ibld_ext < mbkt(ji,jj) ) THEN
+              zthermal = rab_n(ji,jj,1,jp_tem) !ideally use ibld not 1??
+              zbeta    = rab_n(ji,jj,1,jp_sal)
+              jkb = ibld(ji,jj) + ibld_ext
+              jkb1 = MIN(jkb + 1, mbkt(ji,jj))
+              zdtdz(ji,jj) = - ( tsn(ji,jj,jkb1,jp_tem) - tsn(ji,jj,jkb,jp_tem ) ) &
+                   &   / e3t_n(ji,jj,ibld(ji,jj))
+              zdsdz(ji,jj) = - ( tsn(ji,jj,jkb1,jp_sal) - tsn(ji,jj,jkb,jp_sal ) ) &
+                   &   / e3t_n(ji,jj,ibld(ji,jj))
+              zdbdz(ji,jj) = grav * zthermal * zdtdz(ji,jj) - grav * zbeta * zdsdz(ji,jj)
+           END IF
+        END DO
+     END DO
+    END SUBROUTINE zdf_osm_external_gradients
+
+    SUBROUTINE zdf_osm_pycnocline_scalar_profiles( zdtdz, zdsdz, zdbdz )
+
+     REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdtdz, zdsdz, zdbdz      ! gradients in the pycnocline
+
+     INTEGER :: jk, jj, ji
+     REAL(wp) :: ztgrad, zsgrad, zbgrad
+     REAL(wp) :: zgamma_b_nd, zgamma_c, znd
+     REAL(wp) :: zzeta_s=0.3, ztmp
+
+     DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+           IF ( ibld(ji,jj) + ibld_ext < mbkt(ji,jj) ) THEN
+              IF ( lconv(ji,jj) ) THEN  ! convective conditions
+                    IF ( zdbdz_ext(ji,jj) > 0._wp .AND. &
+                         & (zdhdt(ji,jj) > 0._wp .AND. ln_osm_mle .AND. zdb_bl(ji,jj) > rn_osm_mle_thresh &
+                         &  .OR.  zdb_bl(ji,jj) > 0._wp)) THEN  ! zdhdt could be <0 due to FK, hence check zdhdt>0
+                       ztmp = 1._wp/MAX(zdh(ji,jj), epsln)
+                       ztgrad = 0.5 * zdt_ml(ji,jj) * ztmp + zdtdz_ext(ji,jj)
+                       zsgrad = 0.5 * zds_ml(ji,jj) * ztmp + zdsdz_ext(ji,jj)
+                       zbgrad = 0.5 * zdb_ml(ji,jj) * ztmp + zdbdz_ext(ji,jj)
+                       zgamma_b_nd = zdbdz_ext(ji,jj) * zdh(ji,jj) / MAX(zdb_ml(ji,jj), epsln)
+                       zgamma_c = ( 3.14159 / 4.0 ) * ( 0.5 + zgamma_b_nd ) /&
+                            & ( 1.0 - 0.25 * SQRT( 3.14159 / 6.0 ) - 2.0 * zgamma_b_nd * zzeta_s )**2 ! check
+                       DO jk = 2, ibld(ji,jj)+ibld_ext
+                          znd = -( gdepw_n(ji,jj,jk) - zhbl(ji,jj) ) * ztmp
+                          IF ( znd <= zzeta_s ) THEN
+                             zdtdz(ji,jj,jk) = zdtdz_ext(ji,jj) + 0.5 * zdt_ml(ji,jj) * ztmp * &
+                                  & EXP( -6.0 * ( znd -zzeta_s )**2 )
+                             zdsdz(ji,jj,jk) = zdsdz_ext(ji,jj) + 0.5 * zds_ml(ji,jj) * ztmp * &
+                                  & EXP( -6.0 * ( znd -zzeta_s )**2 )
+                             zdbdz(ji,jj,jk) = zdbdz_ext(ji,jj) + 0.5 * zdb_ml(ji,jj) * ztmp * &
+                                  & EXP( -6.0 * ( znd -zzeta_s )**2 )
+                          ELSE
+                             zdtdz(ji,jj,jk) =  ztgrad * EXP( -zgamma_c * ( znd - zzeta_s )**2 )
+                             zdsdz(ji,jj,jk) =  zsgrad * EXP( -zgamma_c * ( znd - zzeta_s )**2 )
+                             zdbdz(ji,jj,jk) =  zbgrad * EXP( -zgamma_c * ( znd - zzeta_s )**2 )
+                          ENDIF
+                       END DO
+                    ENDIF ! If condition not satisfied, no pycnocline present. Gradients have been initialised to zero, so do nothing
+              ELSE
+                 ! stable conditions
+                 ! if pycnocline profile only defined when depth steady of increasing.
+                 IF ( zdhdt(ji,jj) >= 0.0 ) THEN        ! Depth increasing, or steady.
+                    IF ( zdb_bl(ji,jj) > 0._wp ) THEN
+                       IF ( zhol(ji,jj) >= 0.5 ) THEN      ! Very stable - 'thick' pycnocline
+                          ztmp = 1._wp/MAX(zhbl(ji,jj), epsln)
+                          ztgrad = zdt_bl(ji,jj) * ztmp
+                          zsgrad = zds_bl(ji,jj) * ztmp
+                          zbgrad = zdb_bl(ji,jj) * ztmp
+                          DO jk = 2, ibld(ji,jj)
+                             znd = gdepw_n(ji,jj,jk) * ztmp
+                             zdtdz(ji,jj,jk) =  ztgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
+                             zdbdz(ji,jj,jk) =  zbgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
+                             zdsdz(ji,jj,jk) =  zsgrad * EXP( -15.0 * ( znd - 0.9 )**2 )
+                          END DO
+                       ELSE                                   ! Slightly stable - 'thin' pycnoline - needed when stable layer begins to form.
+                          ztmp = 1._wp/MAX(zdh(ji,jj), epsln)
+                          ztgrad = zdt_bl(ji,jj) * ztmp
+                          zsgrad = zds_bl(ji,jj) * ztmp
+                          zbgrad = zdb_bl(ji,jj) * ztmp
+                          DO jk = 2, ibld(ji,jj)
+                             znd = -( gdepw_n(ji,jj,jk) - zhml(ji,jj) ) * ztmp
+                             zdtdz(ji,jj,jk) =  ztgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                             zdbdz(ji,jj,jk) =  zbgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                             zdsdz(ji,jj,jk) =  zsgrad * EXP( -1.75 * ( znd + 0.75 )**2 )
+                          END DO
+                       ENDIF ! IF (zhol >=0.5)
+                    ENDIF    ! IF (zdb_bl> 0.)
+                 ENDIF       ! IF (zdhdt >= 0) zdhdt < 0 not considered since pycnocline profile is zero and profile arrays are intialized to zero
+              ENDIF          ! IF (lconv)
+           END IF      ! IF ( ibld(ji,jj) + ibld_ext < mbkt(ji,jj) )
+        END DO
+     END DO
+
+    END SUBROUTINE zdf_osm_pycnocline_scalar_profiles
+
+    SUBROUTINE zdf_osm_pycnocline_shear_profiles( zdudz, zdvdz )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_osm_pycnocline_shear_profiles  ***
+      !!
+      !! ** Purpose : Calculates velocity shear in the pycnocline
+      !!
+      !! ** Method  :
+      !!
+      !!----------------------------------------------------------------------
+
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdudz, zdvdz
+
+      INTEGER :: jk, jj, ji
+      REAL(wp) :: zugrad, zvgrad, znd
+      REAL(wp) :: zzeta_v = 0.45
       !
-   END SUBROUTINE zdf_osm
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            !
+            IF ( ibld(ji,jj) + ibld_ext < mbkt(ji,jj) ) THEN
+               IF ( lconv (ji,jj) ) THEN
+                  ! Unstable conditions
+                  zugrad = 0.7 * zdu_ml(ji,jj) / zdh(ji,jj) + 0.3 * zustar(ji,jj)*zustar(ji,jj) / &
+                       &      ( ( ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * zhml(ji,jj) ) * &
+                       &      MIN(zla(ji,jj)**(8.0/3.0) + epsln, 0.12 ))
+                  !Alan is this right?
+                  zvgrad = ( 0.7 * zdv_ml(ji,jj) + &
+                       &    2.0 * ff_t(ji,jj) * zustke(ji,jj) * dstokes(ji,jj) / &
+                       &          ( ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird  + epsln ) &
+                       &      )/ (zdh(ji,jj)  + epsln )
+                  DO jk = 2, ibld(ji,jj) - 1 + ibld_ext
+                     znd = -( gdepw_n(ji,jj,jk) - zhbl(ji,jj) ) / (zdh(ji,jj) + epsln ) - zzeta_v
+                     IF ( znd <= 0.0 ) THEN
+                        zdudz(ji,jj,jk) = 1.25 * zugrad * EXP( 3.0 * znd )
+                        zdvdz(ji,jj,jk) = 1.25 * zvgrad * EXP( 3.0 * znd )
+                     ELSE
+                        zdudz(ji,jj,jk) = 1.25 * zugrad * EXP( -2.0 * znd )
+                        zdvdz(ji,jj,jk) = 1.25 * zvgrad * EXP( -2.0 * znd )
+                     ENDIF
+                  END DO
+               ELSE
+                  ! stable conditions
+                  zugrad = 3.25 * zdu_bl(ji,jj) / zhbl(ji,jj)
+                  zvgrad = 2.75 * zdv_bl(ji,jj) / zhbl(ji,jj)
+                  DO jk = 2, ibld(ji,jj)
+                     znd = gdepw_n(ji,jj,jk) / zhbl(ji,jj)
+                     IF ( znd < 1.0 ) THEN
+                        zdudz(ji,jj,jk) = zugrad * EXP( -40.0 * ( znd - 1.0 )**2 )
+                     ELSE
+                        zdudz(ji,jj,jk) = zugrad * EXP( -20.0 * ( znd - 1.0 )**2 )
+                     ENDIF
+                     zdvdz(ji,jj,jk) = zvgrad * EXP( -20.0 * ( znd - 0.85 )**2 )
+                  END DO
+               ENDIF
+               !
+            END IF      ! IF ( ibld(ji,jj) + ibld_ext < mbkt(ji,jj) )
+         END DO
+      END DO
+    END SUBROUTINE zdf_osm_pycnocline_shear_profiles
+
+    SUBROUTINE zdf_osm_calculate_dhdt( zdhdt, zdhdt_2 )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_osm_calculate_dhdt  ***
+     !!
+     !! ** Purpose : Calculates the rate at which hbl changes.
+     !!
+     !! ** Method  :
+     !!
+     !!----------------------------------------------------------------------
+
+    REAL(wp), DIMENSION(jpi,jpj) :: zdhdt, zdhdt_2        ! Rate of change of hbl
+
+    INTEGER :: jj, ji
+    REAL(wp) :: zgamma_b_nd, zgamma_dh_nd, zpert
+    REAL(wp) :: zvel_max, zwb_min
+    REAL(wp) :: zwcor, zrf_conv, zrf_shear, zrf_langmuir, zr_stokes
+    REAL(wp) :: zzeta_m = 0.3
+    REAL(wp) :: zgamma_c = 2.0
+    REAL(wp) :: zdhoh = 0.1
+    REAL(wp) :: alpha_bc = 0.5
+
+    DO jj = 2, jpjm1
+       DO ji = 2, jpim1
+          IF ( lconv(ji,jj) ) THEN    ! Convective
+             ! Alan is this right?  Yes, it's a bit different from the previous relationship
+             ! zwb_ent(ji,jj) = - 2.0 * 0.2 * zwbav(ji,jj) &
+             !   &            - ( 0.15 * ( 1.0 - EXP( -1.5 * zla(ji,jj) ) ) * zustar(ji,jj)**3 + 0.03 * zwstrl(ji,jj)**3 ) / zhml(ji,jj)
+             zwcor = ABS(ff_t(ji,jj)) * zhbl(ji,jj) + epsln
+             zrf_conv = TANH( ( zwstrc(ji,jj) / zwcor )**0.69 )
+             zrf_shear = TANH( ( zustar(ji,jj) / zwcor )**0.69 )
+             zrf_langmuir = TANH( ( zwstrl(ji,jj) / zwcor )**0.69 )
+             zr_stokes = 1.0 - EXP( -25.0 * dstokes(ji,jj) / hbl(ji,jj) &
+                  &                  * ( 1.0 + 4.0 * dstokes(ji,jj) / hbl(ji,jj) ) )
+
+             zwb_ent(ji,jj) = - 2.0 * 0.2 * zrf_conv * zwbav(ji,jj) &
+                  &                  - 0.15 * zrf_shear * zustar(ji,jj)**3 /zhml(ji,jj) &
+                  &         + zr_stokes * ( 0.15 * EXP( -1.5 * zla(ji,jj) ) * zrf_shear * zustar(ji,jj)**3 &
+                  &                                         - zrf_langmuir * 0.03 * zwstrl(ji,jj)**3 ) / zhml(ji,jj)
+             !
+             zwb_min = dh(ji,jj) * zwb0(ji,jj) / zhml(ji,jj) + zwb_ent(ji,jj)
+
+             IF ( ln_osm_mle ) THEN
+                  !  zwb_fk_b(ji,jj) = zwb_fk(ji,jj) *  hmle(ji,jj) / ( 6.0 * hbl(ji,jj) ) * ( 6.0 * hbl(ji,jj) / hmle(ji,jj) - 1.0 + &
+                ! &            ( 1.0 - 2.0 * hbl(ji,jj) / hmle(ji,jj))**3 )          ! Fox-Kemper buoyancy flux average over OSBL
+                IF ( hmle(ji,jj) > hbl(ji,jj) ) THEN
+                   zwb_fk_b(ji,jj) = zwb_fk(ji,jj) *  &
+                        (1.0 + hmle(ji,jj) / ( 6.0 * hbl(ji,jj) ) * (-1.0 + ( 1.0 - 2.0 * hbl(ji,jj) / hmle(ji,jj))**3) )
+                ELSE
+                   zwb_fk_b(ji,jj) = 0.5 * zwb_fk(ji,jj) * hmle(ji,jj) / hbl(ji,jj)
+                ENDIF
+                zvel_max = ( zwstrl(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**p2third / hbl(ji,jj)
+                IF ( ( zwb_ent(ji,jj) + 2.0 * zwb_fk_b(ji,jj) ) < 0.0 ) THEN
+                   ! OSBL is deepening, entrainment > restratification
+                   IF ( zdb_bl(ji,jj) > 0.0 .and. zdbdz_ext(ji,jj) > 0.0 ) THEN
+                      zdhdt(ji,jj) = -( zwb_ent(ji,jj) + 2.0 * zwb_fk_b(ji,jj) ) / ( zvel_max + MAX(zdb_bl(ji,jj), 1.0e-15) )
+                   ELSE
+                      zdhdt(ji,jj) = -( zwb_ent(ji,jj) + 2.0 * zwb_fk_b(ji,jj) ) /  MAX( zvel_max, 1.0e-15)
+                   ENDIF
+                ELSE
+                   ! OSBL shoaling due to restratification flux. This is the velocity defined in Fox-Kemper et al (2008)
+                   zdhdt(ji,jj) = - zvel_mle(ji,jj)
+
+
+                ENDIF
+
+             ELSE
+                ! Fox-Kemper not used.
+
+                  zvel_max = - ( 1.0 + 1.0 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / hbl(ji,jj) ) * zwb_ent(ji,jj) / &
+                  &        ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+                  zdhdt(ji,jj) = -zwb_ent(ji,jj) / ( zvel_max + MAX(zdb_bl(ji,jj), 1.0e-15) )
+                ! added ajgn 23 July as temporay fix
+
+             ENDIF
+
+             zdhdt_2(ji,jj) = 0._wp
+
+                ! commented out ajgn 23 July as temporay fix
+!                 IF ( zdb_ml(ji,jj) > 0.0 .and. zdbdz_ext(ji,jj) > 0.0 ) THEN
+! !additional term to account for thickness of pycnocline on dhdt. Small correction, so could get rid of this if necessary.
+!                     zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
+!                     zgamma_b_nd = zdbdz_ext(ji,jj) * zhml(ji,jj) / zdb_ml(ji,jj)
+!                     zgamma_dh_nd = zdbdz_ext(ji,jj) * zdh(ji,jj) / zdb_ml(ji,jj)
+!                     zdhdt_2(ji,jj) = ( 1.0 - SQRT( 3.1415 / ( 4.0 * zgamma_c) ) * zdhoh ) * zdh(ji,jj) / zhml(ji,jj)
+!                     zdhdt_2(ji,jj) = zdhdt_2(ji,jj) * ( zwb0(ji,jj) - (1.0 + zgamma_b_nd / alpha_bc ) * zwb_min )
+!                     ! Alan no idea what this should be?
+!                     zdhdt_2(ji,jj) = alpha_bc / ( 4.0 * zgamma_c ) * zdhdt_2(ji,jj) &
+!                        &        + (alpha_bc + zgamma_dh_nd ) * ( 1.0 + SQRT( 3.1414 / ( 4.0 * zgamma_c ) ) * zdh(ji,jj) / zhbl(ji,jj) ) &
+!                        &        * (1.0 / ( 4.0 * zgamma_c * alpha_bc ) ) * zwb_min * zdh(ji,jj) / zhbl(ji,jj)
+!                     zdhdt_2(ji,jj) = zdhdt_2(ji,jj) / ( zvel_max + MAX( zdb_bl(ji,jj), 1.0e-15 ) )
+!                     IF ( zdhdt_2(ji,jj) <= 0.2 * zdhdt(ji,jj) ) THEN
+!                         zdhdt(ji,jj) = zdhdt(ji,jj) + zdhdt_2(ji,jj)
+!                 ENDIF
+            ELSE                        ! Stable
+                zdhdt(ji,jj) = ( 0.06 + 0.52 * zhol(ji,jj) / 2.0 ) * zvstr(ji,jj)**3 / hbl(ji,jj) + zwbav(ji,jj)
+                zdhdt_2(ji,jj) = 0._wp
+                IF ( zdhdt(ji,jj) < 0._wp ) THEN
+                   ! For long timsteps factor in brackets slows the rapid collapse of the OSBL
+                    zpert = 2.0 * ( 1.0 + 0.0 * 2.0 * zvstr(ji,jj) * rn_rdt / hbl(ji,jj) ) * zvstr(ji,jj)**2 / hbl(ji,jj)
+                ELSE
+                    zpert = MAX( 2.0 * ( 1.0 + 0.0 * 2.0 * zvstr(ji,jj) * rn_rdt / hbl(ji,jj) ) * zvstr(ji,jj)**2 / hbl(ji,jj), zdb_bl(ji,jj) )
+                ENDIF
+                zdhdt(ji,jj) = 2.0 * zdhdt(ji,jj) / zpert
+            ENDIF
+         END DO
+      END DO
+    END SUBROUTINE zdf_osm_calculate_dhdt
+
+    SUBROUTINE zdf_osm_timestep_hbl( zdhdt, zdhdt_2 )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_osm_timestep_hbl  ***
+     !!
+     !! ** Purpose : Increments hbl.
+     !!
+     !! ** Method  : If thechange in hbl exceeds one model level the change is
+     !!              is calculated by moving down the grid, changing the buoyancy
+     !!              jump. This is to ensure that the change in hbl does not
+     !!              overshoot a stable layer.
+     !!
+     !!----------------------------------------------------------------------
+
+
+    REAL(wp), DIMENSION(jpi,jpj) :: zdhdt, zdhdt_2   ! rates of change of hbl.
+
+    INTEGER :: jk, jj, ji, jm
+    REAL(wp) :: zhbl_s, zvel_max, zdb
+    REAL(wp) :: zthermal, zbeta
+
+     DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+           IF ( ibld(ji,jj) - imld(ji,jj) > 1 ) THEN
+!
+! If boundary layer changes by more than one level, need to check for stable layers between initial and final depths.
+!
+              zhbl_s = hbl(ji,jj)
+              jm = imld(ji,jj)
+              zthermal = rab_n(ji,jj,1,jp_tem)
+              zbeta = rab_n(ji,jj,1,jp_sal)
+
+
+              IF ( lconv(ji,jj) ) THEN
+!unstable
+
+                 IF( ln_osm_mle ) THEN
+                    zvel_max = ( zwstrl(ji,jj)**3 + zwstrc(ji,jj)**3 )**p2third / hbl(ji,jj)
+                 ELSE
+
+                    zvel_max = -( 1.0 + 1.0 * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird * rn_rdt / hbl(ji,jj) ) * zwb_ent(ji,jj) / &
+                      &      ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+
+                 ENDIF
+
+                 DO jk = imld(ji,jj), ibld(ji,jj)
+                    zdb = MAX( grav * ( zthermal * ( zt_bl(ji,jj) - tsn(ji,jj,jm,jp_tem) ) &
+                         & - zbeta * ( zs_bl(ji,jj) - tsn(ji,jj,jm,jp_sal) ) ), &
+                         &  0.0 ) + zvel_max
+
+
+                    IF ( ln_osm_mle ) THEN
+                       zhbl_s = zhbl_s + MIN( &
+                        & rn_rdt * ( ( -zwb_ent(ji,jj) - 2.0 * zwb_fk_b(ji,jj) )/ zdb + zdhdt_2(ji,jj) ) / FLOAT(ibld(ji,jj) - imld(ji,jj) ), &
+                        & e3w_n(ji,jj,jm) )
+                    ELSE
+                      zhbl_s = zhbl_s + MIN( &
+                        & rn_rdt * (  -zwb_ent(ji,jj) / zdb + zdhdt_2(ji,jj) ) / FLOAT(ibld(ji,jj) - imld(ji,jj) ), &
+                        & e3w_n(ji,jj,jm) )
+                    ENDIF
+
+                    zhbl_s = MIN(zhbl_s,  gdepw_n(ji,jj, mbkt(ji,jj) + 1) - depth_tol)
+
+                    IF ( zhbl_s >= gdepw_n(ji,jj,jm+1) ) jm = jm + 1
+                 END DO
+                 hbl(ji,jj) = zhbl_s
+                 ibld(ji,jj) = jm
+             ELSE
+! stable
+                 DO jk = imld(ji,jj), ibld(ji,jj)
+                    zdb = MAX( &
+                         & grav * ( zthermal * ( zt_bl(ji,jj) - tsn(ji,jj,jm,jp_tem) )&
+                         &           - zbeta * ( zs_bl(ji,jj) - tsn(ji,jj,jm,jp_sal) ) ),&
+                         & 0.0 ) + &
+             &       2.0 * zvstr(ji,jj)**2 / zhbl_s
+
+                    ! Alan is thuis right? I have simply changed hbli to hbl
+                    zhol(ji,jj) = -zhbl_s / ( ( zvstr(ji,jj)**3 + epsln )/ zwbav(ji,jj) )
+                    zdhdt(ji,jj) = -( zwbav(ji,jj) - 0.04 / 2.0 * zwstrl(ji,jj)**3 / zhbl_s - 0.15 / 2.0 * ( 1.0 - EXP( -1.5 * zla(ji,jj) ) ) * &
+               &                  zustar(ji,jj)**3 / zhbl_s ) * ( 0.725 + 0.225 * EXP( -7.5 * zhol(ji,jj) ) )
+                    zdhdt(ji,jj) = zdhdt(ji,jj) + zwbav(ji,jj)
+                    zhbl_s = zhbl_s + MIN( zdhdt(ji,jj) / zdb * rn_rdt / FLOAT( ibld(ji,jj) - imld(ji,jj) ), e3w_n(ji,jj,jm) )
+
+                    zhbl_s = MIN(zhbl_s, gdepw_n(ji,jj, mbkt(ji,jj) + 1) - depth_tol)
+                    IF ( zhbl_s >= gdepw_n(ji,jj,jm) ) jm = jm + 1
+                 END DO
+             ENDIF   ! IF ( lconv )
+             hbl(ji,jj) = MAX(zhbl_s, gdepw_n(ji,jj,4) )
+             ibld(ji,jj) = MAX(jm, 4 )
+           ELSE
+! change zero or one model level.
+             hbl(ji,jj) = MAX(zhbl_t(ji,jj), gdepw_n(ji,jj,4) )
+           ENDIF
+           zhbl(ji,jj) = gdepw_n(ji,jj,ibld(ji,jj))
+         END DO
+      END DO
+
+    END SUBROUTINE zdf_osm_timestep_hbl
+
+    SUBROUTINE zdf_osm_pycnocline_thickness( dh, zdh )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE zdf_osm_pycnocline_thickness  ***
+      !!
+      !! ** Purpose : Calculates thickness of the pycnocline
+      !!
+      !! ** Method  : The thickness is calculated from a prognostic equation
+      !!              that relaxes the pycnocine thickness to a diagnostic
+      !!              value. The time change is calculated assuming the
+      !!              thickness relaxes exponentially. This is done to deal
+      !!              with large timesteps.
+      !!
+      !!----------------------------------------------------------------------
+
+      REAL(wp), DIMENSION(jpi,jpj) :: dh, zdh     ! pycnocline thickness.
+      !
+      INTEGER :: jj, ji
+      INTEGER :: inhml
+      REAL(wp) :: zari, ztau, zddhdt
+
+
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            IF ( lconv(ji,jj) ) THEN
+
+               IF( ln_osm_mle ) THEN
+                  IF ( ( zwb_ent(ji,jj) + zwb_fk_b(ji,jj) ) < 0._wp ) THEN
+                     ! OSBL is deepening. Note wb_fk_b is zero if ln_osm_mle=F
+                     IF ( zdb_bl(ji,jj) > 0._wp .and. zdbdz_ext(ji,jj) > 0._wp)THEN
+                        IF ( ( zwstrc(ji,jj) / zvstr(ji,jj) )**3 <= 0.5 ) THEN  ! near neutral stability
+                           zari = MIN( 1.5 * ( zdb_bl(ji,jj) / ( zdbdz_ext(ji,jj) * zhbl(ji,jj) ) ) / &
+                                (1.0 + zdb_bl(ji,jj)**2 / ( 4.5 * zvstr(ji,jj)**2 * zdbdz_ext(ji,jj) ) ), 0.2 )
+                        ELSE                                                     ! unstable
+                           zari = MIN( 1.5 * ( zdb_bl(ji,jj) / ( zdbdz_ext(ji,jj) * zhbl(ji,jj) ) ) / &
+                                (1.0 + zdb_bl(ji,jj)**2 / ( 4.5 * zwstrc(ji,jj)**2 * zdbdz_ext(ji,jj) ) ), 0.2 )
+                        ENDIF
+                        ztau = 0.2 * hbl(ji,jj) / (zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3)**pthird
+                        zddhdt = zari * hbl(ji,jj)
+                     ELSE
+                        ztau = 0.2 * hbl(ji,jj) / ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+                        zddhdt = 0.2 * hbl(ji,jj)
+                     ENDIF
+                  ELSE
+                     ztau = 0.2 * hbl(ji,jj) / ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+                     zddhdt = 0.2 * hbl(ji,jj)
+                  ENDIF
+               ELSE ! ln_osm_mle
+                  IF ( zdb_bl(ji,jj) > 0._wp .and. zdbdz_ext(ji,jj) > 0._wp)THEN
+                     IF ( ( zwstrc(ji,jj) / zvstr(ji,jj) )**3 <= 0.5 ) THEN  ! near neutral stability
+                        zari = MIN( 1.5 * ( zdb_bl(ji,jj) / ( zdbdz_ext(ji,jj) * zhbl(ji,jj) ) ) / &
+                             (1.0 + zdb_bl(ji,jj)**2 / ( 4.5 * zvstr(ji,jj)**2 * zdbdz_ext(ji,jj) ) ), 0.2 )
+                     ELSE                                                     ! unstable
+                        zari = MIN( 1.5 * ( zdb_bl(ji,jj) / ( zdbdz_ext(ji,jj) * zhbl(ji,jj) ) ) / &
+                             (1.0 + zdb_bl(ji,jj)**2 / ( 4.5 * zwstrc(ji,jj)**2 * zdbdz_ext(ji,jj) ) ), 0.2 )
+                     ENDIF
+                     ztau = hbl(ji,jj) / (zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3)**pthird
+                     zddhdt = zari * hbl(ji,jj)
+                  ELSE
+                     ztau = hbl(ji,jj) / ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+                     zddhdt = 0.2 * hbl(ji,jj)
+                  ENDIF
+
+               END IF  ! ln_osm_mle
+
+               dh(ji,jj) = dh(ji,jj) * EXP( -rn_rdt / ztau ) + zddhdt * ( 1.0 - EXP( -rn_rdt / ztau ) )
+               ! Alan: this hml is never defined or used
+            ELSE   ! IF (lconv)
+               ztau = hbl(ji,jj) / zvstr(ji,jj)
+               IF ( zdhdt(ji,jj) >= 0.0 ) THEN    ! probably shouldn't include wm here
+                  ! boundary layer deepening
+                  IF ( zdb_bl(ji,jj) > 0._wp ) THEN
+                     ! pycnocline thickness set by stratification - use same relationship as for neutral conditions.
+                     zari = MIN( 4.5 * ( zvstr(ji,jj)**2 ) &
+                          & / ( zdb_bl(ji,jj) * zhbl(ji,jj) ) + 0.01  , 0.2 )
+                     zddhdt = MIN( zari, 0.2 ) * hbl(ji,jj)
+                  ELSE
+                     zddhdt = 0.2 * hbl(ji,jj)
+                  ENDIF
+               ELSE     ! IF(dhdt < 0)
+                  zddhdt = 0.2 * hbl(ji,jj)
+               ENDIF    ! IF (dhdt >= 0)
+               dh(ji,jj) = dh(ji,jj) * EXP( -rn_rdt / ztau )+ zddhdt * ( 1.0 - EXP( -rn_rdt / ztau ) )
+               IF ( zdhdt(ji,jj) < 0._wp .and. dh(ji,jj) >= hbl(ji,jj) ) dh(ji,jj) = zddhdt       ! can be a problem with dh>hbl for rapid collapse
+               ! Alan: this hml is never defined or used -- do we need it?
+            ENDIF       ! IF (lconv)
+
+            hml(ji,jj) = hbl(ji,jj) - dh(ji,jj)
+            inhml = MAX( INT( dh(ji,jj) / e3t_n(ji,jj,ibld(ji,jj)) ) , 1 )
+            imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 3)
+            zhml(ji,jj) = gdepw_n(ji,jj,imld(ji,jj))
+            zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
+         END DO
+      END DO
+
+    END SUBROUTINE zdf_osm_pycnocline_thickness
+
+
+   SUBROUTINE zdf_osm_zmld_horizontal_gradients( zmld, zdtdx, zdtdy, zdsdx, zdsdy, dbdx_mle, dbdy_mle )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_osm_horizontal_gradients  ***
+      !!
+      !! ** Purpose :   Calculates horizontal gradients of buoyancy for use with Fox-Kemper parametrization.
+      !!
+      !! ** Method  :
+      !!
+      !! References: Fox-Kemper et al., JPO, 38, 1145-1165, 2008
+      !!             Fox-Kemper and Ferrari, JPO, 38, 1166-1179, 2008
+
+
+      REAL(wp), DIMENSION(jpi,jpj)     :: dbdx_mle, dbdy_mle ! MLE horiz gradients at u & v points
+      REAL(wp), DIMENSION(jpi,jpj)     :: zmld ! ==  estimated FK BLD used for MLE horiz gradients  == !
+      REAL(wp), DIMENSION(jpi,jpj)     :: zdtdx, zdtdy, zdsdx, zdsdy
+
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      INTEGER  ::   ii, ij, ik, ikmax   ! local integers
+      REAL(wp)                         :: zc
+      REAL(wp)                         :: zN2_c           ! local buoyancy difference from 10m value
+      REAL(wp), DIMENSION(jpi,jpj)     :: ztm, zsm, zLf_NH, zLf_MH
+      REAL(wp), DIMENSION(jpi,jpj,jpts):: ztsm_midu, ztsm_midv, zabu, zabv
+      REAL(wp), DIMENSION(jpi,jpj)     :: zmld_midu, zmld_midv
+!!----------------------------------------------------------------------
+      !
+      !                                      !==  MLD used for MLE  ==!
+
+      mld_prof(:,:)  = nlb10               ! Initialization to the number of w ocean point
+      zmld(:,:)  = 0._wp               ! here hmlp used as a dummy variable, integrating vertically N^2
+      zN2_c = grav * rn_osm_mle_rho_c * r1_rau0   ! convert density criteria into N^2 criteria
+      DO jk = nlb10, jpkm1
+         DO jj = 1, jpj                ! Mixed layer level: w-level 
+            DO ji = 1, jpi
+               ikt = mbkt(ji,jj)
+               zmld(ji,jj) = zmld(ji,jj) + MAX( rn2b(ji,jj,jk) , 0._wp ) * e3w_n(ji,jj,jk)
+               IF( zmld(ji,jj) < zN2_c )   mld_prof(ji,jj) = MIN( jk , ikt ) + 1   ! Mixed layer level
+            END DO
+         END DO
+      END DO
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            mld_prof(ji,jj) = MAX(mld_prof(ji,jj),ibld(ji,jj))
+            zmld(ji,jj) = gdepw_n(ji,jj,mld_prof(ji,jj))
+         END DO
+      END DO
+      ! ensure mld_prof .ge. ibld
+      !
+      ikmax = MIN( MAXVAL( mld_prof(:,:) ), jpkm1 )                  ! max level of the computation
+      !
+      ztm(:,:) = 0._wp
+      zsm(:,:) = 0._wp
+      DO jk = 1, ikmax                                 ! MLD and mean buoyancy and N2 over the mixed layer
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zc = e3t_n(ji,jj,jk) * REAL( MIN( MAX( 0, mld_prof(ji,jj)-jk ) , 1  )  )    ! zc being 0 outside the ML t-points
+               ztm(ji,jj) = ztm(ji,jj) + zc * tsn(ji,jj,jk,jp_tem)
+               zsm(ji,jj) = zsm(ji,jj) + zc * tsn(ji,jj,jk,jp_sal)
+            END DO
+         END DO
+      END DO
+      ! average temperature and salinity.
+      ztm(:,:) = ztm(:,:) / MAX( e3t_n(:,:,1), zmld(:,:) )
+      zsm(:,:) = zsm(:,:) / MAX( e3t_n(:,:,1), zmld(:,:) )
+      ! calculate horizontal gradients at u & v points
+
+      DO jj = 2, jpjm1
+         DO ji = 1, jpim1
+            zdtdx(ji,jj) = ( ztm(ji+1,jj) - ztm( ji,jj) )  * umask(ji,jj,1) / e1u(ji,jj)
+            zdsdx(ji,jj) = ( zsm(ji+1,jj) - zsm( ji,jj) )  * umask(ji,jj,1) / e1u(ji,jj)
+            zmld_midu(ji,jj) = 0.25_wp * (zmld(ji+1,jj) + zmld( ji,jj))
+            ztsm_midu(ji,jj,jp_tem) = 0.5_wp * ( ztm(ji+1,jj) + ztm( ji,jj) )
+            ztsm_midu(ji,jj,jp_sal) = 0.5_wp * ( zsm(ji+1,jj) + zsm( ji,jj) )
+         END DO
+      END DO
+
+      DO jj = 1, jpjm1
+         DO ji = 2, jpim1
+            zdtdy(ji,jj) = ( ztm(ji,jj+1) - ztm( ji,jj) ) * vmask(ji,jj,1) / e1v(ji,jj)
+            zdsdy(ji,jj) = ( zsm(ji,jj+1) - zsm( ji,jj) ) * vmask(ji,jj,1) / e1v(ji,jj)
+            zmld_midv(ji,jj) = 0.25_wp * (zmld(ji,jj+1) + zmld( ji,jj))
+            ztsm_midv(ji,jj,jp_tem) = 0.5_wp * ( ztm(ji,jj+1) + ztm( ji,jj) )
+            ztsm_midv(ji,jj,jp_sal) = 0.5_wp * ( zsm(ji,jj+1) + zsm( ji,jj) )
+         END DO
+      END DO
+
+      CALL eos_rab(ztsm_midu, zmld_midu, zabu)
+      CALL eos_rab(ztsm_midv, zmld_midv, zabv)
+
+      DO jj = 2, jpjm1
+         DO ji = 1, jpim1
+            dbdx_mle(ji,jj) = grav*(zdtdx(ji,jj)*zabu(ji,jj,jp_tem) - zdsdx(ji,jj)*zabu(ji,jj,jp_sal))
+         END DO
+      END DO
+      DO jj = 1, jpjm1
+         DO ji = 2, jpim1
+            dbdy_mle(ji,jj) = grav*(zdtdy(ji,jj)*zabv(ji,jj,jp_tem) - zdsdy(ji,jj)*zabv(ji,jj,jp_sal))
+         END DO
+      END DO
+
+ END SUBROUTINE zdf_osm_zmld_horizontal_gradients
+  SUBROUTINE zdf_osm_mle_parameters( hmle, zwb_fk, zvel_mle, zdiff_mle )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_osm_mle_parameters  ***
+      !!
+      !! ** Purpose :   Timesteps the mixed layer eddy depth, hmle and calculates the mixed layer eddy fluxes for buoyancy, heat and salinity.
+      !!
+      !! ** Method  :
+      !!
+      !! References: Fox-Kemper et al., JPO, 38, 1145-1165, 2008
+      !!             Fox-Kemper and Ferrari, JPO, 38, 1166-1179, 2008
+
+      REAL(wp), DIMENSION(jpi,jpj)     :: hmle, zwb_fk, zvel_mle, zdiff_mle
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      INTEGER  ::   ii, ij, ik  ! local integers
+      INTEGER , DIMENSION(jpi,jpj)     :: inml_mle
+      REAL(wp) ::   zdb_mle, ztmp, zdbds_mle
+
+      mld_prof(:,:) = 4
+      DO jk = 5, jpkm1
+        DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+            IF ( hmle(ji,jj) >= gdepw_n(ji,jj,jk) ) mld_prof(ji,jj) = MIN(mbkt(ji,jj), jk)
+          END DO
+        END DO
+      END DO
+      ! DO jj = 2, jpjm1
+      !    DO ji = 1, jpim1
+      !       zhmle(ji,jj) = gdepw_n(ji,jj,mld_prof(ji,jj))
+      !    END DO
+      !  END DO
+   ! Timestep mixed layer eddy depth.
+      DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+          zdb_mle = grav * (rhop(ji,jj,mld_prof(ji,jj)) - rhop(ji,jj,ibld(ji,jj) )) * r1_rau0 ! check ALMG
+          IF ( lconv(ji,jj) .and. ( zdb_bl(ji,jj) < rn_osm_mle_thresh .and. mld_prof(ji,jj) > ibld(ji,jj) .and. zdb_mle > 0.0 ) ) THEN
+             hmle(ji,jj) = hmle(ji,jj) + zwb0(ji,jj) * rn_rdt / MAX( zdb_mle, rn_osm_mle_thresh )  ! MLE layer deepening through encroachment. Don't have a good maximum value for deepening, so use threshold buoyancy.
+          ELSE
+            ! MLE layer relaxes towards mixed layer depth on timescale tau_mle, or tau_mle/10
+             ! IF ( hmle(ji,jj) > zmld(ji,jj) ) THEN
+             !   hmle(ji,jj) = hmle(ji,jj) - ( hmle(ji,jj) - zmld(ji,jj) ) * rn_rdt / rn_osm_mle_tau
+             ! ELSE
+             !   hmle(ji,jj) = hmle(ji,jj) - 10.0 * ( hmle(ji,jj) - zmld(ji,jj) ) * rn_rdt / rn_osm_mle_tau ! fast relaxation if MLE layer shallower than MLD
+             ! ENDIF
+             IF ( hmle(ji,jj) > hbl(ji,jj) ) THEN
+               hmle(ji,jj) = hmle(ji,jj) - ( hmle(ji,jj) - hbl(ji,jj) ) * rn_rdt / rn_osm_mle_tau
+             ELSE
+               hmle(ji,jj) = hmle(ji,jj) - 10.0 * ( hmle(ji,jj) - hbl(ji,jj) ) * rn_rdt / rn_osm_mle_tau ! fast relaxation if MLE layer shallower than MLD
+             ENDIF
+          ENDIF
+          hmle(ji,jj) = MIN(hmle(ji,jj), ht_n(ji,jj))
+          hmle(ji,jj) = MIN(hmle(ji,jj), 1.2*zmld(ji,jj)) 
+        END DO
+      END DO
+
+      mld_prof = 4
+      DO jk = 5, jpkm1
+        DO jj = 2, jpjm1
+          DO ji = 2, jpim1
+            IF ( hmle(ji,jj) >= gdepw_n(ji,jj,jk) ) mld_prof(ji,jj) = MIN(mbkt(ji,jj), jk)
+          END DO
+        END DO
+      END DO
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zhmle(ji,jj) = gdepw_n(ji,jj, mld_prof(ji,jj))
+         END DO
+       END DO
+   ! Calculate vertical buoyancy, heat and salinity fluxes due to MLE.
+
+      DO jj = 2, jpjm1
+        DO ji = 2, jpim1
+          IF ( lconv(ji,jj) ) THEN
+             ztmp =  r1_ft(ji,jj) *  MIN( 111.e3_wp , e1u(ji,jj) ) / rn_osm_mle_lf
+             ! zwt_fk(ji,jj) = 0.5_wp * ztmp * ( dbdx_mle(ji,jj) * zdtdx(ji,jj) + dbdy_mle(ji,jj) * zdtdy(ji,jj) &
+             !      & + dbdx_mle(ji-1,jj) * zdtdx(ji-1,jj) + dbdy_mle(ji,jj-1) * zdtdy(ji,jj-1) )
+             ! zws_fk(ji,jj) = 0.5_wp * ztmp * ( dbdx_mle(ji,jj) * zdsdx(ji,jj) + dbdy_mle(ji,jj) * zdsdy(ji,jj) &
+             !      & + dbdx_mle(ji-1,jj) * zdsdx(ji-1,jj) + dbdy_mle(ji,jj-1) * zdsdy(ji,jj-1) )
+             zdbds_mle = SQRT( 0.5_wp * ( dbdx_mle(ji,jj) * dbdx_mle(ji,jj) + dbdy_mle(ji,jj) * dbdy_mle(ji,jj) &
+                  & + dbdx_mle(ji-1,jj) * dbdx_mle(ji-1,jj) + dbdy_mle(ji,jj-1) * dbdy_mle(ji,jj-1) ) )
+             zwb_fk(ji,jj) = rn_osm_mle_ce * hmle(ji,jj) * hmle(ji,jj) *ztmp * zdbds_mle * zdbds_mle
+      ! This vbelocity scale, defined in Fox-Kemper et al (2008), is needed for calculating dhdt.
+             zvel_mle(ji,jj) = zdbds_mle * ztmp * hmle(ji,jj) * tmask(ji,jj,1) 
+             zdiff_mle(ji,jj) = 1.e-4_wp * ztmp * zdbds_mle * zhmle(ji,jj)**3  / rn_osm_mle_lf
+          ENDIF
+        END DO
+      END DO
+END SUBROUTINE zdf_osm_mle_parameters
+
+END SUBROUTINE zdf_osm
 
 
@@ -1378,8 +1995,14 @@
      INTEGER  ::   ios            ! local integer
      INTEGER  ::   ji, jj, jk     ! dummy loop indices
+     REAL z1_t2
      !!
      NAMELIST/namzdf_osm/ ln_use_osm_la, rn_osm_la, rn_osm_dstokes, nn_ave &
           & ,nn_osm_wave, ln_dia_osm, rn_osm_hbl0 &
-          & ,ln_kpprimix, rn_riinfty, rn_difri, ln_convmix, rn_difconv
+          & ,ln_kpprimix, rn_riinfty, rn_difri, ln_convmix, rn_difconv, nn_osm_wave &
+          & ,ln_osm_mle
+! Namelist for Fox-Kemper parametrization.
+      NAMELIST/namosm_mle/ nn_osm_mle, rn_osm_mle_ce, rn_osm_mle_lf, rn_osm_mle_time, rn_osm_mle_lat,&
+           & rn_osm_mle_rho_c,rn_osm_mle_thresh,rn_osm_mle_tau
+
      !!----------------------------------------------------------------------
      !
@@ -1397,9 +2020,10 @@
         WRITE(numout,*) 'zdf_osm_init : OSMOSIS Parameterisation'
         WRITE(numout,*) '~~~~~~~~~~~~'
-        WRITE(numout,*) '   Namelist namzdf_osm : set tke mixing parameters'
-        WRITE(numout,*) '     Use namelist  rn_osm_la                     ln_use_osm_la = ', ln_use_osm_la
+        WRITE(numout,*) '   Namelist namzdf_osm : set osm mixing parameters'
+        WRITE(numout,*) '     Use  rn_osm_la                                ln_use_osm_la = ', ln_use_osm_la
+        WRITE(numout,*) '     Use  MLE in OBL, i.e. Fox-Kemper param        ln_osm_mle = ', ln_osm_mle
         WRITE(numout,*) '     Turbulent Langmuir number                     rn_osm_la   = ', rn_osm_la
         WRITE(numout,*) '     Initial hbl for 1D runs                       rn_osm_hbl0   = ', rn_osm_hbl0
-        WRITE(numout,*) '     Depth scale of Stokes drift                rn_osm_dstokes = ', rn_osm_dstokes
+        WRITE(numout,*) '     Depth scale of Stokes drift                   rn_osm_dstokes = ', rn_osm_dstokes
         WRITE(numout,*) '     horizontal average flag                       nn_ave      = ', nn_ave
         WRITE(numout,*) '     Stokes drift                                  nn_osm_wave = ', nn_osm_wave
@@ -1423,5 +2047,70 @@
      IF( zdf_osm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_osm_init : unable to allocate arrays' )
 
-     call osm_rst( nit000, 'READ' ) !* read or initialize hbl
+
+     IF( ln_osm_mle ) THEN
+! Initialise Fox-Kemper parametrization
+         REWIND( numnam_ref )              ! Namelist namosm_mle in reference namelist : Tracer advection scheme
+         READ  ( numnam_ref, namosm_mle, IOSTAT = ios, ERR = 903)
+903      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namosm_mle in reference namelist')
+
+         REWIND( numnam_cfg )              ! Namelist namosm_mle in configuration namelist : Tracer advection scheme
+         READ  ( numnam_cfg, namosm_mle, IOSTAT = ios, ERR = 904 )
+904      IF( ios >  0 )   CALL ctl_nam ( ios , 'namosm_mle in configuration namelist')
+         IF(lwm) WRITE ( numond, namosm_mle )
+
+         IF(lwp) THEN                     ! Namelist print
+            WRITE(numout,*)
+            WRITE(numout,*) 'zdf_osm_init : initialise mixed layer eddy (MLE)'
+            WRITE(numout,*) '~~~~~~~~~~~~~'
+            WRITE(numout,*) '   Namelist namosm_mle : '
+            WRITE(numout,*) '         MLE type: =0 standard Fox-Kemper ; =1 new formulation        nn_osm_mle    = ', nn_osm_mle
+            WRITE(numout,*) '         magnitude of the MLE (typical value: 0.06 to 0.08)           rn_osm_mle_ce    = ', rn_osm_mle_ce
+            WRITE(numout,*) '         scale of ML front (ML radius of deformation) (nn_osm_mle=0)      rn_osm_mle_lf     = ', rn_osm_mle_lf, 'm'
+            WRITE(numout,*) '         maximum time scale of MLE                    (nn_osm_mle=0)      rn_osm_mle_time   = ', rn_osm_mle_time, 's'
+            WRITE(numout,*) '         reference latitude (degrees) of MLE coef.    (nn_osm_mle=1)      rn_osm_mle_lat    = ', rn_osm_mle_lat, 'deg'
+            WRITE(numout,*) '         Density difference used to define ML for FK              rn_osm_mle_rho_c  = ', rn_osm_mle_rho_c
+            WRITE(numout,*) '         Threshold used to define ML for FK                      rn_osm_mle_thresh  = ', rn_osm_mle_thresh, 'm^2/s'
+            WRITE(numout,*) '         Timescale for OSM-FK                                         rn_osm_mle_tau  = ', rn_osm_mle_tau, 's'
+         ENDIF         !
+     ENDIF
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         IF( ln_osm_mle ) THEN
+            WRITE(numout,*) '   ==>>>   Mixed Layer Eddy induced transport added to OSMOSIS BL calculation'
+            IF( nn_osm_mle == 0 )   WRITE(numout,*) '              Fox-Kemper et al 2010 formulation'
+            IF( nn_osm_mle == 1 )   WRITE(numout,*) '              New formulation'
+         ELSE
+            WRITE(numout,*) '   ==>>>   Mixed Layer induced transport NOT added to OSMOSIS BL calculation'
+         ENDIF
+      ENDIF
+      !
+      IF( ln_osm_mle ) THEN                ! MLE initialisation
+         !
+         rb_c = grav * rn_osm_mle_rho_c /rau0        ! Mixed Layer buoyancy criteria
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '      ML buoyancy criteria = ', rb_c, ' m/s2 '
+         IF(lwp) WRITE(numout,*) '      associated ML density criteria defined in zdfmxl = ', rn_osm_mle_rho_c, 'kg/m3'
+         !
+         IF( nn_osm_mle == 0 ) THEN           ! MLE array allocation & initialisation            !
+!
+         ELSEIF( nn_osm_mle == 1 ) THEN           ! MLE array allocation & initialisation
+            rc_f = rn_osm_mle_ce/ (  5.e3_wp * 2._wp * omega * SIN( rad * rn_osm_mle_lat )  )
+            !
+         ENDIF
+         !                                ! 1/(f^2+tau^2)^1/2 at t-point (needed in both nn_osm_mle case)
+         z1_t2 = 2.e-5
+         do jj=1,jpj
+            do ji = 1,jpi
+               r1_ft(ji,jj) = MIN(1./( ABS(ff_t(ji,jj)) + epsln ), ABS(ff_t(ji,jj))/z1_t2**2)
+            end do
+         end do
+         ! z1_t2 = 1._wp / ( rn_osm_mle_time * rn_osm_mle_timeji,jj )
+         ! r1_ft(:,:) = 1._wp / SQRT(  ff_t(:,:) * ff_t(:,:) + z1_t2  )
+         !
+      ENDIF
+
+     call osm_rst( nit000, 'READ' ) !* read or initialize hbl, dh, hmle
+
 
      IF( ln_zdfddm) THEN
@@ -1512,5 +2201,8 @@
         CALL iom_set_rstw_var_active('wn')
         CALL iom_set_rstw_var_active('hbl')
-        CALL iom_set_rstw_var_active('hbli')
+        CALL iom_set_rstw_var_active('dh')
+        IF( ln_osm_mle ) THEN
+            CALL iom_set_rstw_var_active('hmle')
+        END IF
      ENDIF
    END SUBROUTINE zdf_osm_init
@@ -1530,5 +2222,5 @@
      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
 
-     INTEGER ::   id1, id2   ! iom enquiry index
+     INTEGER ::   id1, id2, id3   ! iom enquiry index
      INTEGER  ::   ji, jj, jk     ! dummy loop indices
      INTEGER  ::   iiki, ikt ! local integer
@@ -1536,5 +2228,5 @@
      REAL(wp) ::   zN2_c           ! local scalar
      REAL(wp) ::   rho_c = 0.01_wp    !: density criterion for mixed layer depth
-     INTEGER, DIMENSION(:,:), ALLOCATABLE :: imld_rst ! level of mixed-layer depth (pycnocline top)
+     INTEGER, DIMENSION(jpi,jpj) :: imld_rst ! level of mixed-layer depth (pycnocline top)
      !!----------------------------------------------------------------------
      !
@@ -1551,12 +2243,23 @@
            WRITE(numout,*) ' ===>>>> :  wn not in restart file, set to zero initially'
         END IF
+
         id1 = iom_varid( numror, 'hbl'   , ldstop = .FALSE. )
-        id2 = iom_varid( numror, 'hbli'   , ldstop = .FALSE. )
+        id2 = iom_varid( numror, 'dh'   , ldstop = .FALSE. )
         IF( id1 > 0 .AND. id2 > 0) THEN                       ! 'hbl' exists; read and return
            CALL iom_get( numror, jpdom_autoglo, 'hbl' , hbl , ldxios = lrxios )
-           CALL iom_get( numror, jpdom_autoglo, 'hbli', hbli, ldxios = lrxios  )
-           WRITE(numout,*) ' ===>>>> :  hbl & hbli read from restart file'
+           CALL iom_get( numror, jpdom_autoglo, 'dh', dh, ldxios = lrxios  )
+           WRITE(numout,*) ' ===>>>> :  hbl & dh read from restart file'
+           IF( ln_osm_mle ) THEN
+              id3 = iom_varid( numror, 'hmle'   , ldstop = .FALSE. )
+              IF( id3 > 0) THEN
+                 CALL iom_get( numror, jpdom_autoglo, 'hmle' , hmle , ldxios = lrxios )
+                 WRITE(numout,*) ' ===>>>> :  hmle read from restart file'
+              ELSE
+                 WRITE(numout,*) ' ===>>>> :  hmle not found, set to hbl'
+                 hmle(:,:) = hbl(:,:)            ! Initialise MLE depth.
+              END IF
+           END IF
            RETURN
-        ELSE                      ! 'hbl' & 'hbli' not in restart file, recalculate
+        ELSE                      ! 'hbl' & 'dh' not in restart file, recalculate
            WRITE(numout,*) ' ===>>>> : previous run without osmosis scheme, hbl computed from stratification'
         END IF
@@ -1568,7 +2271,10 @@
      IF( TRIM(cdrw) == 'WRITE') THEN     !* Write hbli into the restart file, then return
         IF(lwp) WRITE(numout,*) '---- osm-rst ----'
-         CALL iom_rstput( kt, nitrst, numrow, 'wn'     , wn  , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'hbl'    , hbl , ldxios = lwxios )
-         CALL iom_rstput( kt, nitrst, numrow, 'hbli'   , hbli, ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'wn'     , wn,   ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'hbl'    , hbl,  ldxios = lwxios )
+         CALL iom_rstput( kt, nitrst, numrow, 'dh'     , dh,   ldxios = lwxios )
+         IF( ln_osm_mle ) THEN
+            CALL iom_rstput( kt, nitrst, numrow, 'hmle', hmle, ldxios = lwxios )
+         END IF
         RETURN
      END IF
@@ -1578,5 +2284,4 @@
      !!-----------------------------------------------------------------------------
      IF( lwp ) WRITE(numout,*) ' ===>>>> : calculating hbl computed from stratification'
-     ALLOCATE( imld_rst(jpi,jpj) )
      ! w-level of the mixing and mixed layers
      CALL eos_rab( tsn, rab_n )
@@ -1599,12 +2304,19 @@
      DO jj = 1, jpj
         DO ji = 1, jpi
-           iiki = imld_rst(ji,jj)
-           hbl (ji,jj) = gdepw_n(ji,jj,iiki  ) * ssmask(ji,jj)    ! Turbocline depth
+           iiki = MAX(4,imld_rst(ji,jj))
+           hbl (ji,jj) = gdepw_n(ji,jj,iiki  )    ! Turbocline depth
+           dh (ji,jj) = e3t_n(ji,jj,iiki-1  )     ! Turbocline depth
         END DO
      END DO
-     hbl = MAX(hbl,epsln)
-     hbli(:,:) = hbl(:,:)
-     DEALLOCATE( imld_rst )
+
      WRITE(numout,*) ' ===>>>> : hbl computed from stratification'
+
+     IF( ln_osm_mle ) THEN
+        hmle(:,:) = hbl(:,:)            ! Initialise MLE depth.
+        WRITE(numout,*) ' ===>>>> : hmle set = to hbl'
+     END IF
+
+     wn(:,:,:) = 0._wp
+     WRITE(numout,*) ' ===>>>> :  wn not in restart file, set to zero initially'
    END SUBROUTINE osm_rst
 
@@ -1634,5 +2346,4 @@
       ENDIF
 
-      ! add non-local temperature and salinity flux
       DO jk = 1, jpkm1
          DO jj = 2, jpjm1
@@ -1648,12 +2359,11 @@
       END DO
 
-
-      ! save the non-local tracer flux trends for diagnostic
+      ! save the non-local tracer flux trends for diagnostics
       IF( l_trdtra )   THEN
          ztrdt(:,:,:) = tsa(:,:,:,jp_tem) - ztrdt(:,:,:)
          ztrds(:,:,:) = tsa(:,:,:,jp_sal) - ztrds(:,:,:)
-!!bug gm jpttdzdf ==> jpttosm
-         CALL trd_tra( kt, 'TRA', jp_tem, jptra_zdf, ztrdt )
-         CALL trd_tra( kt, 'TRA', jp_sal, jptra_zdf, ztrds )
+
+         CALL trd_tra( kt, 'TRA', jp_tem, jptra_osm, ztrdt )
+         CALL trd_tra( kt, 'TRA', jp_sal, jptra_osm, ztrds )
          DEALLOCATE( ztrdt )      ;     DEALLOCATE( ztrds )
       ENDIF
@@ -1723,3 +2433,4 @@
 
    !!======================================================================
+
 END MODULE zdfosm
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/ZDF/zdfphy.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/ZDF/zdfphy.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/ZDF/zdfphy.F90	(revision 13402)
@@ -56,5 +56,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id$
+   !! $Id: zdfphy.F90 12178 2019-12-11 11:02:38Z agn $
    !! Software governed by the CeCILL license (see ./LICENSE)
    !!----------------------------------------------------------------------
@@ -172,5 +172,5 @@
       IF( ln_zdfosm .AND. ln_zdfevd )   CALL ctl_stop( 'zdf_phy_init: chose between ln_zdfosm and ln_zdfevd' )
       IF( lk_top    .AND. ln_zdfnpc )   CALL ctl_stop( 'zdf_phy_init: npc scheme is not working with key_top' )
-      IF( lk_top    .AND. ln_zdfosm )   CALL ctl_stop( 'zdf_phy_init: osmosis scheme is not working with key_top' )
+      IF( lk_top    .AND. ln_zdfosm )   CALL ctl_warn( 'zdf_phy_init: osmosis gives no non-local fluxes for TOP tracers yet' )
       IF(lwp) THEN
          WRITE(numout,*)
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/nemogcm.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/nemogcm.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/nemogcm.F90	(revision 13402)
@@ -394,4 +394,5 @@
       !                             !-----------------------------------------!
       CALL mpp_init
+WRITE(numout,*)'NEMOGCM 1: nstop = ',nstop
 
       ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
@@ -405,4 +406,5 @@
       !
       !                                      ! General initialization
+WRITE(numout,*)'NEMOGCM 2: nstop = ',nstop
       IF( ln_timing    )   CALL timing_init     ! timing
       IF( ln_timing    )   CALL timing_start( 'nemo_init')
@@ -411,8 +413,10 @@
                            CALL     eos_init        ! Equation of state
       IF( lk_c1d       )   CALL     c1d_init        ! 1D column configuration
+WRITE(numout,*)'NEMOGCM 3: nstop = ',nstop
                            CALL     wad_init        ! Wetting and drying options
                            CALL     dom_init("OPA") ! Domain
       IF( ln_crs       )   CALL     crs_init        ! coarsened grid: domain initialization 
       IF( ln_ctl       )   CALL prt_ctl_init        ! Print control
+WRITE(numout,*)'NEMOGCM 4: nstop = ',nstop
       
       CALL diurnal_sst_bulk_init                ! diurnal sst
@@ -433,4 +437,5 @@
       
                            CALL  istate_init    ! ocean initial state (Dynamics and tracers)
+WRITE(numout,*)'NEMOGCM 5: nstop = ',nstop
 
       !                                      ! external forcing 
@@ -438,7 +443,9 @@
                            CALL     sbc_init    ! surface boundary conditions (including sea-ice)
                            CALL     bdy_init    ! Open boundaries initialisation
+WRITE(numout,*)'NEMOGCM 6: nstop = ',nstop
 
       !                                      ! Ocean physics
                            CALL zdf_phy_init    ! Vertical physics
+WRITE(numout,*)'NEMOGCM 7: nstop = ',nstop
                                      
       !                                         ! Lateral physics
@@ -446,4 +453,5 @@
                            CALL ldf_eiv_init      ! eddy induced velocity param.
                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
+WRITE(numout,*)'NEMOGCM 8: nstop = ',nstop
 
       !                                      ! Active tracers
@@ -451,7 +459,9 @@
                            CALL tra_bbc_init      ! bottom heat flux
                            CALL tra_bbl_init      ! advective (and/or diffusive) bottom boundary layer scheme
+WRITE(numout,*)'NEMOGCM 9: nstop = ',nstop
                            CALL tra_dmp_init      ! internal tracer damping
                            CALL tra_adv_init      ! horizontal & vertical advection
                            CALL tra_ldf_init      ! lateral mixing
+WRITE(numout,*)'NEMOGCM 10: nstop = ',nstop
 
       !                                      ! Dynamics
@@ -459,7 +469,9 @@
                            CALL dyn_adv_init      ! advection (vector or flux form)
                            CALL dyn_vor_init      ! vorticity term including Coriolis
+WRITE(numout,*)'NEMOGCM 11: nstop = ',nstop
                            CALL dyn_ldf_init      ! lateral mixing
                            CALL dyn_hpg_init      ! horizontal gradient of Hydrostatic pressure
                            CALL dyn_spg_init      ! surface pressure gradient
+WRITE(numout,*)'NEMOGCM 12: nstop = ',nstop
 
 #if defined key_top
@@ -467,12 +479,15 @@
                            CALL     trc_init
 #endif
+WRITE(numout,*)'NEMOGCM 13: nstop = ',nstop
       IF( l_ldfslp     )   CALL ldf_slp_init    ! slope of lateral mixing
 
       !                                      ! Icebergs
                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
+WRITE(numout,*)'NEMOGCM 14: nstop = ',nstop
 
       !                                      ! Misc. options
                            CALL sto_par_init    ! Stochastic parametrization
       IF( ln_sto_eos   )   CALL sto_pts_init    ! RRandom T/S fluctuations
+WRITE(numout,*)'NEMOGCM 15: nstop = ',nstop
      
       !                                      ! Diagnostics
@@ -480,12 +495,15 @@
       IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
                            CALL dia_ptr_init    ! Poleward TRansports initialization
+WRITE(numout,*)'NEMOGCM 16: nstop = ',nstop
                            CALL dia_dct_init    ! Sections tranports
                            CALL dia_hsb_init    ! heat content, salt content and volume budgets
                            CALL     trd_init    ! Mixed-layer/Vorticity/Integral constraints trends
                            CALL dia_obs_init    ! Initialize observational data
+WRITE(numout,*)'NEMOGCM 17: nstop = ',nstop
                            CALL dia_tmb_init    ! TMB outputs
                            CALL dia_25h_init    ! 25h mean  outputs
                            CALL dia_harm_init   ! tidal harmonics outputs
      IF( ln_diaobs    )    CALL dia_obs( nit000-1 )   ! Observation operator for restart
+WRITE(numout,*)'NEMOGCM 18: nstop = ',nstop
 
       !                                      ! Assimilation increments
Index: NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/step.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/step.F90	(revision 13401)
+++ NEMO/branches/UKMO/NEMO_4.0.1_FKOSM_m11715/src/OCE/step.F90	(revision 13402)
@@ -101,5 +101,6 @@
       IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
                              CALL iom_init(      cxios_context          )  ! for model grid (including passible AGRIF zoom)
-         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
+                             IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
+                             CALL dia_hth_init    ! extra ML depth diagnostics, thermocline depths
       ENDIF
       IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
@@ -205,5 +206,5 @@
       IF( ln_floats  )   CALL flo_stp ( kstp )        ! drifting Floats
       IF( ln_diacfl  )   CALL dia_cfl ( kstp )        ! Courant number diagnostics
-      IF( lk_diahth  )   CALL dia_hth ( kstp )        ! Thermocline depth (20 degres isotherm depth)
+      IF( ll_diahth  )   CALL dia_hth ( kstp )        ! Thermocline depth (20 degres isotherm depth)
       IF( ln_diadct  )   CALL dia_dct ( kstp )        ! Transports
                          CALL dia_ar5 ( kstp )        ! ar5 diag
