Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AGRIF_DEMO/EXPREF/1_namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AGRIF_DEMO/EXPREF/1_namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AGRIF_DEMO/EXPREF/1_namelist_cfg	(revision 14062)
@@ -299,5 +299,4 @@
 !-----------------------------------------------------------------------
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 0          ! =0   e3f = mean masked e3t divided by 4
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AGRIF_DEMO/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AGRIF_DEMO/EXPREF/namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AGRIF_DEMO/EXPREF/namelist_cfg	(revision 14062)
@@ -300,5 +300,4 @@
 !-----------------------------------------------------------------------
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 0          ! =0   e3f = mean masked e3t divided by 4
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AMM12/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AMM12/EXPREF/namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/AMM12/EXPREF/namelist_cfg	(revision 14062)
@@ -291,5 +291,5 @@
 !-----------------------------------------------------------------------
    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)
+   nn_e3f_typ = 1          !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/ORCA2_ICE_PISCES/EXPREF/namelist_cfg	(revision 14062)
@@ -334,5 +334,4 @@
 !-----------------------------------------------------------------------
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 0          ! =0   e3f = mean masked e3t divided by 4
 /
 !-----------------------------------------------------------------------
@@ -389,7 +388,7 @@
       !                       !                 = 3 as =2 with distinct dissipative an mixing length scale
       nn_etau     =   1       !  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)
+      !                       !        = 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)
       ln_mxhsw    = .false.   !  surface mixing length scale = F(wave height)
 /
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/axis_def_nemo.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/axis_def_nemo.xml	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/axis_def_nemo.xml	(revision 14062)
@@ -14,4 +14,5 @@
       <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="depthf"  long_name="Vertical F levels" unit="m" positive="down" />
       <axis id="nfloat"  long_name="Float number"      unit="-"                 />
       <axis id="icbcla"  long_name="Iceberg class"      unit="1"               />
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/domain_def_nemo.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/domain_def_nemo.xml	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/domain_def_nemo.xml	(revision 14062)
@@ -181,4 +181,7 @@
      <domain id="EqW" domain_ref="grid_W" > <zoom_domain id="EqW"/> </domain>
 
+     <!--   F grid   -->
+     <domain id="grid_F" long_name="grid F"/>
+     
 	           <!--   zonal mean grid   -->
      <domain_group id="gznl">
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/field_def_nemo-oce.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/field_def_nemo-oce.xml	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/field_def_nemo-oce.xml	(revision 14062)
@@ -171,5 +171,5 @@
         <field id="tosmint_pot"  long_name="vertical integral of potential temperature times density"   standard_name="integral_wrt_depth_of_product_of_density_and_potential_temperature"  unit="(kg m2) degree_C" />
 
-
+        <field id="ht"           long_name="water column height at T point"                     standard_name="water_column_height_T"                      unit="m" />
         <field id="ssh"          long_name="sea surface height"                                 standard_name="sea_surface_height_above_geoid"             unit="m" />
         <field id="ssh2"         long_name="square of sea surface height"                       standard_name="square_of_sea_surface_height_above_geoid"   unit="m2" > ssh * ssh </field >
@@ -190,4 +190,5 @@
 
         <!-- Energy - horizontal divergence -->
+        <field id="sKE"          long_name="surface kinetic energy"  standard_name="specific_kinetic_energy_of_sea_water"   unit="m2/s2"  grid_ref="grid_T_2D" />
         <field id="hdiv"         long_name="horizontal divergence"                                                          unit="s-1"    grid_ref="grid_T_3D" />
 
@@ -270,41 +271,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>
 
@@ -501,4 +557,5 @@
 
       <field_group id="grid_U"   grid_ref="grid_U_2D">
+        <field id="hu"            long_name="water column height at U point"                         standard_name="water_column_height_U"       unit="m" />
         <field id="e2u"           long_name="U-cell width in meridional direction"                   standard_name="cell_width"                  unit="m"                               />
         <field id="e3u"           long_name="U-cell thickness"                                       standard_name="cell_thickness"              unit="m"          grid_ref="grid_U_3D" />
@@ -571,4 +628,5 @@
         <field id="e3v"          long_name="V-cell thickness"                                       standard_name="cell_thickness"              unit="m"          grid_ref="grid_V_3D" />
         <field id="e3v_0"        long_name="Initial V-cell thickness"                               standard_name="ref_cell_thickness"          unit="m"          grid_ref="grid_V_3D" />
+        <field id="hv"            long_name="water column height at V point"                        standard_name="water_column_height_V"       unit="m" />
         <field id="vtau"         long_name="Wind Stress along j-axis"                               standard_name="surface_downward_y_stress"   unit="N/m2"                            />
         <field id="voce"         long_name="ocean current along j-axis"                             standard_name="sea_water_y_velocity"        unit="m/s"        grid_ref="grid_V_3D" />
@@ -679,4 +737,16 @@
 
       <!-- F grid -->
+      <field_group id="grid_F" grid_ref="grid_F_2D">
+	<field id="e3f"          long_name="F-cell thickness"                    standard_name="cell_thickness"        unit="m"   grid_ref="grid_F_3D" />
+	<field id="e3f_0"        long_name="F-cell thickness"                    standard_name="cell_thickness"        unit="m"   grid_ref="grid_F_3D" />
+        <field id="hf"           long_name="water column height at F point"    standard_name="water_column_height_F"  unit="m"                     />
+        <field id="sKEf"         long_name="surface kinetic energy at F point" standard_name="specific_kinetic_energy_of_sea_water"   unit="m2/s2" />
+        <field id="relvor"       long_name="relative vorticity"                standard_name="relative_vorticity"     unit="1/s"                   />
+        <field id="plavor"       long_name="planetary vorticity"               standard_name="planetary_vorticity"    unit="1/s"                   />
+        <field id="relpotvor"    long_name="relative potential vorticity"      standard_name="relpot_vorticity"       unit="1/m.s"                 />
+        <field id="abspotvor"    long_name="absolute potential vorticity"      standard_name="abspot_vorticity"       unit="1/m.s"                 />
+        <field id="Ens"          long_name="enstrophy"                         standard_name="enstrophy"              unit="1/m2.s2"               />
+      </field_group> 
+ 
       <!-- AGRIF sponge -->
       <field id="agrif_spf"    long_name=" AGRIF f-sponge coefficient"   unit=" " />
@@ -841,5 +911,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" />
@@ -877,4 +952,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>
@@ -892,4 +971,6 @@
      <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>
@@ -1099,4 +1180,15 @@
     </field_group>
 
+    <!-- TMB diagnostic output -->
+    <field_group  id="1h_grid_T_tmb" grid_ref="grid_T_2D" operation="instant">
+      <field id="top_temp"           name="votemper_top"  unit="degC"  />
+      <field id="mid_temp"           name="votemper_mid"  unit="degC"  />
+      <field id="bot_temp"           name="votemper_bot"  unit="degC"  />
+      <field id="top_sal"            name="vosaline_top"  unit="psu"   />
+      <field id="mid_sal"            name="vosaline_mid"  unit="psu"   />
+      <field id="bot_sal"            name="vosaline_bot"  unit="psu"   />
+      <field id="sshnmasked"         name="sossheig"      unit="m"     /> 
+    </field_group>
+
     <field_group  id="1h_grid_U_tmb" grid_ref="grid_U_2D" operation="instant">
       <field id="top_u"           name="vozocrtx_top"  unit="m/s"  />
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/grid_def_nemo.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/grid_def_nemo.xml	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/grid_def_nemo.xml	(revision 14062)
@@ -53,4 +53,13 @@
          <domain domain_ref="grid_W" />
          <axis axis_ref="depthw" />
+       </grid>
+       <!--  -->
+       <grid id="grid_F_2D" >
+         <domain domain_ref="grid_F" />
+       </grid>
+        <!--  -->
+       <grid id="grid_F_3D" >
+         <domain domain_ref="grid_F" />
+         <axis axis_ref="depthf" />
        </grid>
         <!--  -->
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/namelist_ref
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/namelist_ref	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/cfgs/SHARED/namelist_ref	(revision 14062)
@@ -998,8 +998,10 @@
    ln_dynvor_eeT = .false. !  energy conserving scheme (een using e3t)
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0          ! =0  e3f = mi(mj(e3t))/4
-      !                       ! =1  e3f = mi(mj(e3t))/mi(mj( tmask))
+   !
    ln_dynvor_msk = .false. !  vorticity multiplied by fmask (=T)        ==>>> PLEASE DO NOT ACTIVATE
-      !                    !  (f-point vorticity schemes only)
+   !                       !  (f-point vorticity schemes only)
+   !
+   nn_e3f_typ = 0          !  type of e3f (EEN, ENE, ENS, MIX only)  =0  e3f = mi(mj(e3t))/4
+   !                       !                                         =1  e3f = mi(mj(e3t))/mi(mj( tmask))
 /
 !-----------------------------------------------------------------------
@@ -1011,4 +1013,6 @@
    ln_hpg_isf  = .false.   !  s-coordinate (sco ) adapted to isf
    ln_hpg_djc  = .false.   !  s-coordinate (Density Jacobian with Cubic polynomial)
+      ln_hpg_djc_vnh = .true.  !  hor.  bc type for djc scheme (T=von Neumann, F=linear extrapolation)
+      ln_hpg_djc_vnv = .true.  !  vert. bc type for djc scheme (T=von Neumann, F=linear extrapolation)
    ln_hpg_prj  = .false.   !  s-coordinate (Pressure Jacobian scheme)
 /
@@ -1033,4 +1037,5 @@
    !                       !  Type of the operator :
    ln_dynldf_OFF = .false.     !  No operator (i.e. no explicit diffusion)
+   nn_dynldf_typ = 0           !  =0 div-rot (default)   ;   =1 symmetric
    ln_dynldf_lap = .false.     !    laplacian operator
    ln_dynldf_blp = .false.     !  bilaplacian operator
@@ -1163,8 +1168,8 @@
    ln_mxl0     = .true.    !  surface mixing length scale = F(wind stress) (T) or not (F)
       nn_mxlice    = 2        ! type of scaling under sea-ice
-                              !    = 0 no scaling under sea-ice
-                              !    = 1 scaling with constant sea-ice thickness
-                              !    = 2 scaling with mean sea-ice thickness ( only with SI3 sea-ice model )
-                              !    = 3 scaling with maximum sea-ice thickness
+      !                       !    = 0 no scaling under sea-ice
+      !                       !    = 1 scaling with constant sea-ice thickness
+      !                       !    = 2 scaling with mean sea-ice thickness ( only with SI3 sea-ice model )
+      !                       !    = 3 scaling with maximum sea-ice thickness
       rn_mxlice   = 10.       ! max constant ice thickness value when scaling under sea-ice ( nn_mxlice=1)
    rn_mxl0     =   0.04    !  surface  buoyancy lenght scale minimum value
@@ -1173,11 +1178,11 @@
       rn_lc       =   0.15    !  coef. associated to Langmuir cells
    nn_etau     =   1       !  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)
+   !                          !        = 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)
       rn_efr      =   0.05    !  fraction of surface tke value which penetrates below the ML (nn_etau=1 or 2)
       nn_htau     =   1       !  type of exponential decrease of tke penetration below the ML
-                              !        = 0  constant 10 m length scale
-                              !        = 1  0.5m at the equator to 30m poleward of 40 degrees
+      !                       !        = 0  constant 10 m length scale
+      !                       !        = 1  0.5m at the equator to 30m poleward of 40 degrees
    nn_eice     =   1       !  attenutaion of langmuir & surface wave breaking under ice
    !                       !           = 0 no impact of ice cover on langmuir & surface wave breaking
@@ -1216,7 +1221,9 @@
 &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)
+   rn_zdfosm_adjust_sd = 1.0   ! Stokes drift reduction factor
+   rn_osm_hblfrac = 0.1        ! specify top part of hbl for nn_osm_wave = 3 or 4
+   rn_osm_bl_thresh   = 5.e-5      !Threshold buoyancy for deepening of OSBL base
    nn_ave = 0                  ! choice of horizontal averaging on avt, avmu, avmv
    ln_dia_osm = .true.         ! output OSMOSIS-OBL variables
@@ -1226,10 +1233,31 @@
    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.             ! diffusivity when unstable below BL  (m2/s)
+   rn_difconv = 1. !0.01 !1.             ! diffusivity when unstable below BL  (m2/s)
+   rn_osm_dstokes     = 5.     !  Depth scale of Stokes drift (m)
    nn_osm_wave = 0             ! Method used to calculate Stokes drift
       !                        !  = 2: Use ECMWF wave fields
       !                        !  = 1: Pierson Moskowitz wave spectrum
       !                        !  = 0: Constant La# = 0.3
-/
+   nn_osm_SD_reduce = 0        ! Method used to get active Stokes drift from surface value
+      !                        !  = 0: No reduction
+                               !  = 1: use SD avged over top 10% hbl
+                               !  = 2:use surface value of SD fit to slope at rn_osm_hblfrac*hbl below surface
+   ln_zdfosm_ice_shelter = .true.  ! reduce surface SD and depth scale under ice
+   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 MLE criterion
+   rn_osm_mle_tau     = 172800.    ! time scale for FK-OSM (seconds)  (case rn_osm_mle=0)
+   ln_osm_hmle_limit   = .false.   ! limit hmle to rn_osm_hmle_limit*hbl
+   rn_osm_hmle_limit   = 1.2
+   /
 !-----------------------------------------------------------------------
 &namzdf_mfc     !   Mass Flux Convection
@@ -1374,4 +1402,5 @@
    ln_sstnight = .false.             ! Logical switch for calculating night-time average for SST obs
    ln_bound_reject  = .false.        ! Logical to remove obs near boundaries in LAMs.
+   ln_default_fp_indegs = .true.     ! Logical: T=> averaging footprint is in degrees, F=> in metres
    ln_sla_fp_indegs = .true.         ! Logical for SLA: T=> averaging footprint is in degrees, F=> in metres
    ln_sst_fp_indegs = .true.         ! Logical for SST: T=> averaging footprint is in degrees, F=> in metres
@@ -1389,4 +1418,6 @@
    cn_gridsearchfile ='gridsearch.nc' ! Grid search file name
    rn_gridsearchres = 0.5            ! Grid search resolution
+   rn_default_avglamscl = 0.         ! Default E/W diameter of observation footprint (metres/degrees)
+   rn_default_avgphiscl = 0.         ! Default N/S diameter of observation footprint (metres/degrees)
    rn_mdtcorr  = 1.61                ! MDT  correction
    rn_mdtcutoff = 65.0               ! MDT cutoff for computed correction
@@ -1402,5 +1433,5 @@
    rn_sic_avgphiscl = 0.             ! N/S diameter of SIC observation footprint (metres/degrees)
    nn_1dint = 0                      ! Type of vertical interpolation method
-   nn_2dint = 0                      ! Default horizontal interpolation method
+   nn_2dint_default = 0              ! Default horizontal interpolation method
    nn_2dint_sla = 0                  ! Horizontal interpolation method for SLA
    nn_2dint_sst = 0                  ! Horizontal interpolation method for SST
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/doc/namelists/namobs
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/doc/namelists/namobs	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/doc/namelists/namobs	(revision 14062)
@@ -20,4 +20,5 @@
    ln_sstnight = .false.             ! Logical switch for calculating night-time average for SST obs
    ln_bound_reject  = .false.        ! Logical to remove obs near boundaries in LAMs.
+   ln_default_fp_indegs = .true.     ! Logical: T=> averaging footprint is in degrees, F=> in metres
    ln_sla_fp_indegs = .true.         ! Logical for SLA: T=> averaging footprint is in degrees, F=> in metres
    ln_sst_fp_indegs = .true.         ! Logical for SST: T=> averaging footprint is in degrees, F=> in metres
@@ -39,4 +40,6 @@
    rn_dobsini  = 00010101.000000     ! Initial date in window YYYYMMDD.HHMMSS
    rn_dobsend  = 00010102.000000     ! Final date in window YYYYMMDD.HHMMSS
+   rn_default_avglamscl = 0.         ! Default E/W diameter of observation footprint (metres/degrees)
+   rn_default_avgphiscl = 0.         ! Default N/S diameter of observation footprint (metres/degrees)
    rn_sla_avglamscl = 0.             ! E/W diameter of SLA observation footprint (metres/degrees)
    rn_sla_avgphiscl = 0.             ! N/S diameter of SLA observation footprint (metres/degrees)
@@ -48,5 +51,5 @@
    rn_sic_avgphiscl = 0.             ! N/S diameter of SIC observation footprint (metres/degrees)
    nn_1dint = 0                      ! Type of vertical interpolation method
-   nn_2dint = 0                      ! Default horizontal interpolation method
+   nn_2dint_default = 0              ! Default horizontal interpolation method
    nn_2dint_sla = 0                  ! Horizontal interpolation method for SLA
    nn_2dint_sst = 0                  ! Horizontal interpolation method for SST
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/ICE/iceistate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/ICE/iceistate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/ICE/iceistate.F90	(revision 14062)
@@ -21,5 +21,9 @@
    USE sbc_ice , ONLY : tn_ice, snwice_mass, snwice_mass_b
    USE eosbn2         ! equation of state
+# if defined key_qco
+   USE domqco         ! Variable volume
+# else
    USE domvvl         ! Variable volume
+# endif
    USE ice            ! sea-ice: variables
    USE ice1D          ! sea-ice: thermodynamics variables
@@ -434,45 +438,10 @@
          ssh(:,:,Kbb) = ssh(:,:,Kbb) - snwice_mass(:,:) * r1_rho0
          !
+#if defined key_qco
+         IF( .NOT.ln_linssh )   CALL dom_qco_zgr( Kbb, Kmm )        ! interpolation scale factor, depth and water column
+#else
          IF( .NOT.ln_linssh )   CALL dom_vvl_zgr( Kbb, Kmm, Kaa )   ! interpolation scale factor, depth and water column
-! !!st
-!          IF( .NOT.ln_linssh ) THEN
-!             !
-!             WHERE( ht_0(:,:) > 0 )   ;   z2d(:,:) = 1._wp + ssh(:,:,Kmm)*tmask(:,:,1) / ht_0(:,:)
-!             ELSEWHERE                ;   z2d(:,:) = 1._wp   ;   END WHERE
-!             !
-!             DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
-!                e3t(:,:,jk,Kmm) = e3t_0(:,:,jk) * z2d(:,:)
-!                e3t(:,:,jk,Kbb) = e3t(:,:,jk,Kmm)
-!                e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kmm)
-!             END DO
-!             !
-!             ! Reconstruction of all vertical scale factors at now and before time-steps
-!             ! =========================================================================
-!             ! Horizontal scale factor interpolations
-!             ! --------------------------------------
-!             CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3u(:,:,:,Kbb), 'U' )
-!             CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3v(:,:,:,Kbb), 'V' )
-!             CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-!             CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-!             CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3f(:,:,:), 'F' )
-!             ! Vertical scale factor interpolations
-!             ! ------------------------------------
-!             CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )
-!             CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-!             CALL dom_vvl_interpol( e3v(:,:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-!             CALL dom_vvl_interpol( e3u(:,:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-!             CALL dom_vvl_interpol( e3v(:,:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-!             ! t- and w- points depth
-!             ! ----------------------
-!             !!gm not sure of that....
-!             gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
-!             gdepw(:,:,1,Kmm) = 0.0_wp
-!             gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)
-!             DO jk = 2, jpk
-!                gdept(:,:,jk,Kmm) = gdept(:,:,jk-1,Kmm) + e3w(:,:,jk  ,Kmm)
-!                gdepw(:,:,jk,Kmm) = gdepw(:,:,jk-1,Kmm) + e3t(:,:,jk-1,Kmm)
-!                gde3w(:,:,jk) = gdept(:,:,jk  ,Kmm) - ssh (:,:,Kmm)
-!             END DO
-!          ENDIF
+#endif
+
       ENDIF
 
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_interp.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_interp.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_interp.F90	(revision 14062)
@@ -28,5 +28,5 @@
    USE agrif_oce
    USE phycst
-   USE dynspg_ts, ONLY: un_adv, vn_adv
+!!!   USE dynspg_ts, ONLY: un_adv, vn_adv
    !
    USE in_out_manager
@@ -50,5 +50,6 @@
    INTEGER ::   bdy_tinterp = 0
 
-   !!----------------------------------------------------------------------
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
    !! NEMO/NST 4.0 , NEMO Consortium (2018)
    !! $Id$
@@ -1192,9 +1193,9 @@
       !!----------------------------------------------------------------------  
       IF( before ) THEN
-         IF ( ln_bt_fw ) THEN
+!         IF ( ln_bt_fw ) THEN
             ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * ub2_b(i1:i2,j1:j2)
-         ELSE
-            ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * un_adv(i1:i2,j1:j2)
-         ENDIF
+!         ELSE
+!            ptab(i1:i2,j1:j2) = e2u(i1:i2,j1:j2) * un_adv(i1:i2,j1:j2)
+!         ENDIF
       ELSE
          zrhot = Agrif_rhot()
@@ -1228,9 +1229,9 @@
       !
       IF( before ) THEN
-         IF ( ln_bt_fw ) THEN
+!         IF ( ln_bt_fw ) THEN
             ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vb2_b(i1:i2,j1:j2)
-         ELSE
-            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vn_adv(i1:i2,j1:j2)
-         ENDIF
+!         ELSE
+!            ptab(i1:i2,j1:j2) = e1v(i1:i2,j1:j2) * vn_adv(i1:i2,j1:j2)
+!         ENDIF
       ELSE      
          zrhot = Agrif_rhot()
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_sponge.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_sponge.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_sponge.F90	(revision 14062)
@@ -32,4 +32,5 @@
 
    !! * Substitutions
+#  include "domzgr_substitute.h90"
 #  include "do_loop_substitute.h90"
    !!----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_update.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_update.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_oce_update.F90	(revision 14062)
@@ -27,5 +27,7 @@
    USE vremap         ! Vertical remapping
    USE lbclnk 
-
+#if defined key_qco
+   USE domqco
+#endif
    IMPLICIT NONE
    PRIVATE
@@ -34,4 +36,6 @@
    PUBLIC   Update_Scales
 
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/NST 4.0 , NEMO Consortium (2018)
@@ -191,5 +195,4 @@
    END SUBROUTINE Agrif_Update_Tke
 
-
    SUBROUTINE Agrif_Update_vvl( )
       !!---------------------------------------------
@@ -201,4 +204,5 @@
       IF (lwp.AND.lk_agrif_debug) Write(*,*) 'Update e3 from grid Number',Agrif_Fixed(), 'Step', Agrif_Nb_Step()
       !
+#if ! defined key_qco
       Agrif_UseSpecialValueInUpdate = .TRUE.
       Agrif_SpecialValueFineGrid = 0.
@@ -213,7 +217,32 @@
       CALL dom_vvl_update_UVF
       CALL Agrif_ParentGrid_To_ChildGrid()
+#else
+      CALL Agrif_ChildGrid_To_ParentGrid()
+      CALL Agrif_Update_qco
+      CALL Agrif_ParentGrid_To_ChildGrid()
+#endif
       !
    END SUBROUTINE Agrif_Update_vvl
 
+
+#if defined key_qco
+   SUBROUTINE Agrif_Update_qco
+      !!---------------------------------------------
+      !!       *** ROUTINE dom_Update_qco ***
+      !!---------------------------------------------
+      !
+      ! Save arrays prior update (needed for asselin correction)
+      r3t(:,:,Krhs_a) = r3t(:,:,Kmm_a)
+      r3u(:,:,Krhs_a) = r3u(:,:,Kmm_a)
+      r3v(:,:,Krhs_a) = r3v(:,:,Kmm_a)
+
+      ! Update r3x arrays from updated ssh
+      CALL dom_qco_zgr( Kbb_a, Kmm_a )
+      !
+   END SUBROUTINE Agrif_Update_qco
+#endif
+
+
+#if ! defined key_qco
    SUBROUTINE dom_vvl_update_UVF
       !!---------------------------------------------
@@ -224,5 +253,4 @@
       REAL(wp):: zcoef
       !!---------------------------------------------
-
       IF (lwp.AND.lk_agrif_debug) Write(*,*) 'Finalize e3 on grid Number', &
                   & Agrif_Fixed(), 'Step', Agrif_Nb_Step()
@@ -290,4 +318,5 @@
       !
    END SUBROUTINE dom_vvl_update_UVF
+#endif
 
 #if defined key_vertical
@@ -1336,4 +1365,5 @@
    END SUBROUTINE updateAVM
 
+#if ! defined key_qco
    SUBROUTINE updatee3t(ptab_dum, i1, i2, j1, j2, k1, k2, before )
       !!---------------------------------------------
@@ -1447,4 +1477,5 @@
       !
    END SUBROUTINE updatee3t
+#endif
 
 #else
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_user.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_user.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/NST/agrif_user.F90	(revision 14062)
@@ -288,4 +288,5 @@
          CALL Agrif_Init_Variable(sshini_id, procname=agrif_initssh)
          CALL lbc_lnk( 'Agrif_Init_Domain', ssh(:,:,Kbb), 'T', 1. )
+#if ! defined key_qco
          DO jk = 1, jpk
                e3t(:,:,jk,Kbb) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kbb)  ) &
@@ -293,4 +294,5 @@
                         &              + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )
          END DO
+#endif
       ENDIF
 
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DIA/diawri.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DIA/diawri.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DIA/diawri.F90	(revision 14062)
@@ -19,4 +19,5 @@
    !!            3.7  ! 2014-01  (G. Madec) remove eddy induced velocity from no-IOM output
    !!                 !                     change name of output variables in dia_wri_state
+   !!            4.0  ! 2020-10  (A. Nasser, S. Techene) add diagnostic for SWE
    !!----------------------------------------------------------------------
 
@@ -46,4 +47,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)
@@ -118,7 +120,7 @@
       INTEGER ::   ji, jj, jk       ! dummy loop indices
       INTEGER ::   ikbot            ! local integer
-      REAL(wp)::   ze3
       REAL(wp)::   zztmp , zztmpx   ! local scalar
       REAL(wp)::   zztmp2, zztmpy   !   -      -
+      REAL(wp)::   ze3
       REAL(wp), DIMENSION(jpi,jpj)     ::   z2d   ! 2D workspace
       REAL(wp), DIMENSION(jpi,jpj,jpk) ::   z3d   ! 3D workspace
@@ -137,4 +139,5 @@
       CALL iom_put("e3u_0", e3u_0(:,:,:) )
       CALL iom_put("e3v_0", e3v_0(:,:,:) )
+      CALL iom_put("e3f_0", e3f_0(:,:,:) )
       !
       IF ( iom_use("e3t") .OR. iom_use("e3tdef") ) THEN  ! time-varying e3t
@@ -163,13 +166,25 @@
          CALL iom_put( "e3w" , z3d(:,:,:) )
       ENDIF
+      IF ( iom_use("e3f") ) THEN                         ! time-varying e3f caution here at Kaa
+          DO jk = 1, jpk
+            z3d(:,:,jk) =  e3f(:,:,jk)
+         END DO
+         CALL iom_put( "e3f" , z3d(:,:,:) )
+      ENDIF
 
       IF( ll_wd ) THEN                                   ! sea surface height (brought back to the reference used for wetting and drying)
-         CALL iom_put( "ssh" , (ssh(:,:,Kmm)+ssh_ref)*tmask(:,:,1) )
+         CALL iom_put( "ssh" , (ssh(:,:,Kmm)+ssh_ref)*ssmask(:,:) )
       ELSE
          CALL iom_put( "ssh" , ssh(:,:,Kmm) )              ! sea surface height
       ENDIF
 
-      IF( iom_use("wetdep") )   &                  ! wet depth
-         CALL iom_put( "wetdep" , ht_0(:,:) + ssh(:,:,Kmm) )
+      IF( iom_use("wetdep") )    CALL iom_put( "wetdep" , ht_0(:,:) + ssh(:,:,Kmm) )   ! wet depth
+         
+#if defined key_qco
+      IF( iom_use("ht") )   CALL iom_put( "ht" , ht(:,:)     )   ! water column at t-point
+      IF( iom_use("hu") )   CALL iom_put( "hu" , hu(:,:,Kmm) )   ! water column at u-point
+      IF( iom_use("hv") )   CALL iom_put( "hv" , hv(:,:,Kmm) )   ! water column at v-point
+      IF( iom_use("hf") )   CALL iom_put( "hf" , hf_0(:,:)*( 1._wp + r3f(:,:) ) )   ! water column at f-point (caution here at Naa)
+#endif
       
       CALL iom_put( "toce", ts(:,:,:,jp_tem,Kmm) )    ! 3D temperature
@@ -325,4 +340,30 @@
       ENDIF
       !
+      IF ( iom_use("sKE") ) THEN                        ! surface kinetic energy at T point
+         z2d(:,:) = 0._wp
+         DO_2D( 0, 0, 0, 0 )
+            z2d(ji,jj) = 0.25_wp * ( uu(ji  ,jj,1,Kmm) * uu(ji  ,jj,1,Kmm) * e1e2u(ji  ,jj) * e3u(ji  ,jj,1,Kmm)  &
+               &                   + uu(ji-1,jj,1,Kmm) * uu(ji-1,jj,1,Kmm) * e1e2u(ji-1,jj) * e3u(ji-1,jj,1,Kmm)  &
+               &                   + vv(ji,jj  ,1,Kmm) * vv(ji,jj  ,1,Kmm) * e1e2v(ji,jj  ) * e3v(ji,jj  ,1,Kmm)  & 
+               &                   + vv(ji,jj-1,1,Kmm) * vv(ji,jj-1,1,Kmm) * e1e2v(ji,jj-1) * e3v(ji,jj-1,1,Kmm)  )  &
+               &                 * r1_e1e2t(ji,jj) / e3t(ji,jj,1,Kmm) * ssmask(ji,jj)
+         END_2D
+         CALL lbc_lnk( 'diawri', z2d, 'T', 1. )
+         IF ( iom_use("sKE" ) )  CALL iom_put( "sKE" , z2d )   
+      ENDIF
+      !    
+      IF ( iom_use("sKEf") ) THEN                        ! surface kinetic energy at F point
+         z2d(:,:) = 0._wp                                ! CAUTION : only valid in SWE, not with bathymetry
+         DO_2D( 0, 0, 0, 0 )
+            z2d(ji,jj) = 0.25_wp * ( uu(ji,jj  ,1,Kmm) * uu(ji,jj  ,1,Kmm) * e1e2u(ji,jj  ) * e3u(ji,jj  ,1,Kmm)  &
+               &                   + uu(ji,jj+1,1,Kmm) * uu(ji,jj+1,1,Kmm) * e1e2u(ji,jj+1) * e3u(ji,jj+1,1,Kmm)  &
+               &                   + vv(ji  ,jj,1,Kmm) * vv(ji,jj  ,1,Kmm) * e1e2v(ji  ,jj) * e3v(ji  ,jj,1,Kmm)  & 
+               &                   + vv(ji+1,jj,1,Kmm) * vv(ji+1,jj,1,Kmm) * e1e2v(ji+1,jj) * e3v(ji+1,jj,1,Kmm)  )  &
+               &                 * r1_e1e2f(ji,jj) / e3f(ji,jj,1) * ssfmask(ji,jj)
+         END_2D
+         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
+         CALL iom_put( "sKEf", z2d )                     
+      ENDIF
+      !
       CALL iom_put( "hdiv", hdiv )                  ! Horizontal divergence
 
@@ -424,4 +465,50 @@
       
       IF (ln_dia25h)   CALL dia_25h( kt, Kmm )        ! 25h averaging
+      
+      ! Output of vorticity terms
+      IF ( iom_use("relvor")    .OR. iom_use("plavor")    .OR.   &
+         & iom_use("relpotvor") .OR. iom_use("abspotvor") .OR.   &
+         & iom_use("Ens")                                        ) THEN
+         !
+         z2d(:,:) = 0._wp 
+         ze3 = 0._wp 
+         DO_2D( 1, 0, 1, 0 )
+            z2d(ji,jj) = (   e2v(ji+1,jj  ) * vv(ji+1,jj  ,1,Kmm) - e2v(ji,jj) * vv(ji,jj,1,Kmm)    &
+            &              - e1u(ji  ,jj+1) * uu(ji  ,jj+1,1,Kmm) + e1u(ji,jj) * uu(ji,jj,1,Kmm)  ) * r1_e1e2f(ji,jj)
+         END_2D
+         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
+         CALL iom_put( "relvor", z2d )                  ! relative vorticity ( zeta ) 
+         !
+         CALL iom_put( "plavor", ff_f )                 ! planetary vorticity ( f )
+         !
+         DO_2D( 1, 0, 1, 0 )  
+            ze3 = (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
+              &    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
+            IF( ze3 /= 0._wp ) THEN   ;   ze3 = 4._wp / ze3
+            ELSE                      ;   ze3 = 0._wp
+            ENDIF
+            z2d(ji,jj) = ze3 * z2d(ji,jj) 
+         END_2D
+         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
+         CALL iom_put( "relpotvor", z2d )                  ! relative potential vorticity (zeta/h)
+         !
+         DO_2D( 1, 0, 1, 0 )
+            ze3 = (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
+              &    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
+            IF( ze3 /= 0._wp ) THEN   ;   ze3 = 4._wp / ze3
+            ELSE                      ;   ze3 = 0._wp
+            ENDIF
+            z2d(ji,jj) = ze3 * ff_f(ji,jj) + z2d(ji,jj) 
+         END_2D
+         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
+         CALL iom_put( "abspotvor", z2d )                  ! absolute potential vorticity ( q )
+         !
+         DO_2D( 1, 0, 1, 0 )  
+            z2d(ji,jj) = 0.5_wp * z2d(ji,jj)  * z2d(ji,jj) 
+         END_2D
+         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
+         CALL iom_put( "Ens", z2d )                        ! potential enstrophy ( 1/2*q2 )
+         !
+      ENDIF
 
       IF( ln_timing )   CALL timing_stop('dia_wri')
@@ -997,5 +1084,5 @@
       !!
       INTEGER :: inum, jk
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t, zgdept      ! 3D workspace !!st patch to use substitution
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t, zgdept       ! 3D workspace for qco substitution
       !!----------------------------------------------------------------------
       ! 
@@ -1076,4 +1163,17 @@
          CALL iom_rstput ( 0, 0, inum, "qz1_abl",  tq_abl(:,:,2,nt_a,2) )   ! now first level humidity
       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*umask     )      ! non-local u forcing
+         CALL iom_rstput( 0, 0, inum, 'ghamv', ghamv*vmask     )      ! 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
       !
       CALL iom_close( inum )
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/dom_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/dom_oce.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/dom_oce.F90	(revision 14062)
@@ -131,6 +131,6 @@
    !
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2t , r1_e1e2t                !: associated metrics at t-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2u , e2_e1u, r1_e1e2u        !: associated metrics at u-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2v , e1_e2v, r1_e1e2v        !: associated metrics at v-point
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2u , r1_e1e2u , e2_e1u       !: associated metrics at u-point
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2v , r1_e1e2v , e1_e2v       !: associated metrics at v-point
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2f , r1_e1e2f                !: associated metrics at f-point
    !
@@ -162,7 +162,7 @@
 
    !                                                        !  reference depths of cells
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdept_0  !: t- depth              [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gdepw_0  !: w- depth              [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   gde3w_0  !: w- depth (sum of e3w) [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gdept_0  !: t- depth              [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gdepw_0  !: w- depth              [m]
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gde3w_0  !: w- depth (sum of e3w) [m]
    !                                                        !  time-dependent depths of cells
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  gdept, gdepw  
@@ -205,7 +205,9 @@
 
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)           ::   ssmask, ssumask, ssvmask, ssfmask   !: surface mask at T-,U-, V- and F-pts
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: tmask, umask, vmask, wmask, fmask   !: land/ocean mask at T-, U-, V-, W- and F-pts
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: wumask, wvmask        !: land/ocean mask at WT-, WU- and WV-pts
-
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET ::   tmask, umask, vmask, wmask, fmask   !: land/ocean mask at T-, U-, V-, W- and F-pts
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET ::   wumask, wvmask                      !: land/ocean mask at WU- and WV-pts
+#if defined key_qco   
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET ::   fe3mask                             !: land/ocean mask at F-pts for qco
+#endif
    !!----------------------------------------------------------------------
    !! calendar variables
@@ -306,5 +308,9 @@
          &       e3w_0(jpi,jpj,jpk) , e3uw_0(jpi,jpj,jpk) , e3vw_0(jpi,jpj,jpk)                      ,  STAT=ierr(ii) )
          !
-#if ! defined key_qco
+#if defined key_qco
+      ii = ii+1
+      ALLOCATE( r3t  (jpi,jpj,jpt)   , r3u  (jpi,jpj,jpt)    , r3v  (jpi,jpj,jpt)    , r3f  (jpi,jpj) ,      &
+         &      r3t_f(jpi,jpj)       , r3u_f(jpi,jpj)        , r3v_f(jpi,jpj)                         ,  STAT=ierr(ii) )             
+#else
       ii = ii+1
       ALLOCATE( e3t(jpi,jpj,jpk,jpt) , e3u (jpi,jpj,jpk,jpt) , e3v (jpi,jpj,jpk,jpt) , e3f(jpi,jpj,jpk) ,      &
@@ -313,8 +319,4 @@
          !
       ii = ii+1
-      ALLOCATE( r3t  (jpi,jpj,jpt)   , r3u  (jpi,jpj,jpt)    , r3v  (jpi,jpj,jpt)    , r3f  (jpi,jpj) ,  &
-         &      r3t_f(jpi,jpj)       , r3u_f(jpi,jpj)        , r3v_f(jpi,jpj)                         ,  STAT=ierr(ii) )
-         !
-      ii = ii+1
       ALLOCATE( ht_0(jpi,jpj) ,    hu_0(jpi,jpj)    ,    hv_0(jpi,jpj)     , hf_0(jpi,jpj) ,       &
          &   r1_ht_0(jpi,jpj) , r1_hu_0(jpi,jpj) ,    r1_hv_0(jpi,jpj),   r1_hf_0(jpi,jpj) ,   STAT=ierr(ii)  )
@@ -323,8 +325,4 @@
       ii = ii+1
       ALLOCATE( ht  (jpi,jpj) ,    hu  (jpi,jpj,jpt),    hv  (jpi,jpj,jpt)                 ,       &
-         &                      r1_hu  (jpi,jpj,jpt), r1_hv  (jpi,jpj,jpt)                 ,   STAT=ierr(ii)  )
-#else
-      ii = ii+1
-      ALLOCATE(                    hu  (jpi,jpj,jpt),    hv  (jpi,jpj,jpt)                 ,       &
          &                      r1_hu  (jpi,jpj,jpt), r1_hv  (jpi,jpj,jpt)                 ,   STAT=ierr(ii)  )
 #endif
@@ -350,4 +348,9 @@
       ii = ii+1
       ALLOCATE( wmask(jpi,jpj,jpk) , wumask(jpi,jpj,jpk), wvmask(jpi,jpj,jpk) , STAT=ierr(ii) )
+#if defined key_qco
+         !
+      ii = ii+1
+      ALLOCATE( fe3mask(jpi,jpj,jpk) , STAT=ierr(ii) )
+#endif
       !
       dom_oce_alloc = MAXVAL(ierr)
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domain.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domain.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domain.F90	(revision 14062)
@@ -15,5 +15,5 @@
    !!            3.7  !  2015-11  (G. Madec, A. Coward)  time varying zgr by default
    !!            4.0  !  2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface
-   !!            4.x  ! 2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
+   !!            4.1  !  2020-02  (G. Madec, S. Techene)  introduce ssh to h0 ratio
    !!----------------------------------------------------------------------
    
@@ -28,4 +28,10 @@
    USE oce            ! ocean variables
    USE dom_oce        ! domain: ocean
+#if defined key_qco
+   USE domqco         ! quasi-eulerian
+#else
+   USE domvvl         ! variable volume
+#endif
+   USE sshwzv  , ONLY : ssh_init_rst   ! set initial ssh 
    USE sbc_oce        ! surface boundary condition: ocean
    USE trc_oce        ! shared ocean & passive tracers variab
@@ -35,13 +41,8 @@
    USE dommsk         ! domain: set the mask system
    USE domwri         ! domain: write the meshmask file
-#if ! defined key_qco
-   USE domvvl         ! variable volume
-#else
-   USE domqco          ! variable volume
-#endif
    USE c1d            ! 1D configuration
    USE dyncor_c1d     ! 1D configuration: Coriolis term    (cor_c1d routine)
-   USE wet_dry, ONLY : ll_wd
-   USE closea , ONLY : dom_clo ! closed seas
+   USE wet_dry , ONLY : ll_wd     ! wet & drying flag
+   USE closea  , ONLY : dom_clo   ! closed seas routine
    !
    USE prtctl         ! Print control (prt_ctl_info routine)
@@ -50,4 +51,5 @@
    USE lbclnk         ! ocean lateral boundary condition (or mpp link)
    USE lib_mpp        ! distributed memory computing library
+   USE restart        ! only for lrst_oce
 
    IMPLICIT NONE
@@ -58,4 +60,6 @@
    PUBLIC   dom_tile     ! called by step.F90
 
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
    !!-------------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -84,4 +88,5 @@
       INTEGER ::   ji, jj, jk, jt   ! dummy loop indices
       INTEGER ::   iconf = 0    ! local integers
+      REAL(wp)::   zrdt
       CHARACTER (len=64) ::   cform = "(A12, 3(A13, I7))" 
       INTEGER , DIMENSION(jpi,jpj) ::   ik_top , ik_bot       ! top and bottom ocean level
@@ -121,6 +126,5 @@
          WRITE(numout,*)     '         cn_cfg = ', TRIM( cn_cfg ), '   nn_cfg = ', nn_cfg
       ENDIF
-      nn_wxios = 0
-      ln_xios_read = .FALSE.
+      
       !
       !           !==  Reference coordinate system  ==!
@@ -143,10 +147,18 @@
       hv_0(:,:) = 0._wp
       hf_0(:,:) = 0._wp
-      DO jk = 1, jpk
+      DO jk = 1, jpkm1
          ht_0(:,:) = ht_0(:,:) + e3t_0(:,:,jk) * tmask(:,:,jk)
          hu_0(:,:) = hu_0(:,:) + e3u_0(:,:,jk) * umask(:,:,jk)
          hv_0(:,:) = hv_0(:,:) + e3v_0(:,:,jk) * vmask(:,:,jk)
-         hf_0(:,:) = hf_0(:,:) + e3f_0(:,:,jk) * fmask(:,:,jk)
       END DO
+      !
+      DO jk = 1, jpkm1
+         hf_0(1:jpim1,:) = hf_0(1:jpim1,:) + e3f_0(1:jpim1,:,jk)*vmask(1:jpim1,:,jk)*vmask(2:jpi,:,jk)
+      END DO
+      CALL lbc_lnk('domain', hf_0, 'F', 1._wp)
+      !
+      IF( lk_SWE ) THEN      ! SWE case redefine hf_0
+         hf_0(:,:) = hf_0(:,:) + e3f_0(:,:,1) * ssfmask(:,:)
+      ENDIF
       !
       r1_ht_0(:,:) = ssmask (:,:) / ( ht_0(:,:) + 1._wp -  ssmask (:,:) )
@@ -154,17 +166,29 @@
       r1_hv_0(:,:) = ssvmask(:,:) / ( hv_0(:,:) + 1._wp -  ssvmask(:,:) )
       r1_hf_0(:,:) = ssfmask(:,:) / ( hf_0(:,:) + 1._wp -  ssfmask(:,:) )
-
+      !
+      IF( ll_wd ) THEN       ! wet and drying (check ht_0 >= 0)
+         DO_2D( 1, 1, 1, 1 )
+            IF( ht_0(ji,jj) < 0._wp .AND. ssmask(ji,jj) == 1._wp ) THEN
+               CALL ctl_stop( 'ssh_init_rst : ht_0 must be positive at potentially wet points' )
+            ENDIF
+         END_2D
+      ENDIF
+      !
+      !           !==  initialisation of time varying coordinate  ==!
+      !
+      !                                 != ssh initialization
+      IF( .NOT.l_offline .AND. .NOT.l_SAS ) THEN
+         CALL ssh_init_rst( Kbb, Kmm, Kaa )
+      ELSE
+         ssh(:,:,:) = 0._wp
+      ENDIF
       !
 #if defined key_qco
-      !           !==  initialisation of time varying coordinate  ==!   Quasi-Euerian coordinate case
+      !                                 != Quasi-Euerian coordinate case
       !
       IF( .NOT.l_offline )   CALL dom_qco_init( Kbb, Kmm, Kaa )
-      !
-      IF( ln_linssh )        CALL ctl_stop('STOP','domain: key_qco and ln_linssh = T are incompatible')
-      !
 #else
-      !           !==  time varying part of coordinate system  ==!
-      !
-      IF( ln_linssh ) THEN       != Fix in time : set to the reference one for all
+      !
+      IF( ln_linssh ) THEN              != Fix in time : set to the reference one for all
          !
          DO jt = 1, jpt                         ! depth of t- and w-grid-points
@@ -175,22 +199,22 @@
          !
          DO jt = 1, jpt                         ! vertical scale factors
-            e3t(:,:,:,jt) =  e3t_0(:,:,:)
-            e3u(:,:,:,jt) =  e3u_0(:,:,:)
-            e3v(:,:,:,jt) =  e3v_0(:,:,:)
-            e3w(:,:,:,jt) =  e3w_0(:,:,:)
+            e3t (:,:,:,jt) =  e3t_0(:,:,:)
+            e3u (:,:,:,jt) =  e3u_0(:,:,:)
+            e3v (:,:,:,jt) =  e3v_0(:,:,:)
+            e3w (:,:,:,jt) =  e3w_0(:,:,:)
             e3uw(:,:,:,jt) = e3uw_0(:,:,:)
             e3vw(:,:,:,jt) = e3vw_0(:,:,:)
          END DO
-            e3f(:,:,:)    =  e3f_0(:,:,:)
+            e3f (:,:,:)    =  e3f_0(:,:,:)
          !
          DO jt = 1, jpt                         ! water column thickness and its inverse
-            hu(:,:,jt)    =    hu_0(:,:)
-            hv(:,:,jt)    =    hv_0(:,:)
+               hu(:,:,jt) =    hu_0(:,:)
+               hv(:,:,jt) =    hv_0(:,:)
             r1_hu(:,:,jt) = r1_hu_0(:,:)
             r1_hv(:,:,jt) = r1_hv_0(:,:)
          END DO
-            ht(:,:) =    ht_0(:,:)
-         !
-      ELSE                       != time varying : initialize before/now/after variables
+               ht   (:,:) =    ht_0(:,:)
+         !
+      ELSE                              != Time varying : initialize before/now/after variables
          !
          IF( .NOT.l_offline )   CALL dom_vvl_init( Kbb, Kmm, Kaa )
@@ -373,5 +397,7 @@
       USE ioipsl
       !!
-      INTEGER  ::   ios   ! Local integer
+      INTEGER ::   ios   ! Local integer
+      REAL(wp)::   zrdt
+      !!----------------------------------------------------------------------
       !
       NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,                 &
@@ -393,4 +419,46 @@
       ENDIF
       !
+      !                       !=======================!
+      !                       !==  namelist namdom  ==!
+      !                       !=======================!
+      !
+      READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in reference namelist' )
+      READ  ( numnam_cfg, namdom, IOSTAT = ios, ERR = 904 )
+904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist' )
+      IF(lwm) WRITE( numond, namdom )
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN    ! AGRIF child, subdivide the Parent timestep
+         rn_Dt = Agrif_Parent (rn_Dt ) / Agrif_Rhot()
+      ENDIF
+#endif
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '   Namelist : namdom   ---   space & time domain'
+         WRITE(numout,*) '      linear free surface (=T)                ln_linssh   = ', ln_linssh
+         WRITE(numout,*) '      create mesh/mask file                   ln_meshmask = ', ln_meshmask
+         WRITE(numout,*) '      ocean time step                         rn_Dt       = ', rn_Dt
+         WRITE(numout,*) '      asselin time filter parameter           rn_atfp     = ', rn_atfp
+         WRITE(numout,*) '      online coarsening of dynamical fields   ln_crs      = ', ln_crs
+      ENDIF
+      !
+      ! set current model timestep rDt = 2*rn_Dt if MLF or rDt = rn_Dt if RK3
+      rDt   = 2._wp * rn_Dt
+      r1_Dt = 1._wp / rDt
+      !
+      IF( l_SAS .AND. .NOT.ln_linssh ) THEN
+         CALL ctl_warn( 'SAS requires linear ssh : force ln_linssh = T' )
+         ln_linssh = .TRUE.
+      ENDIF
+      !
+#if defined key_qco
+      IF( ln_linssh )   CALL ctl_stop( 'STOP','domain: key_qco and ln_linssh = T are incompatible' )
+#endif
+      !
+      !                       !=======================!
+      !                       !==  namelist namrun  ==!
+      !                       !=======================!
       !
       READ  ( numnam_ref, namrun, IOSTAT = ios, ERR = 901)
@@ -452,13 +520,51 @@
       nleapy = nn_leapy
       ninist = nn_istate
+      !
+      !                                        !==  Set parameters for restart reading using xIOS  ==!
+      !
+      IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+         lrxios = ln_xios_read .AND. ln_rstart
+         IF( nn_wxios > 0 )   lwxios = .TRUE.           !* set output file type for XIOS based on NEMO namelist
+         nxioso = nn_wxios
+      ENDIF
+      !                                        !==  Check consistency between ln_rstart and ln_1st_euler  ==!   (i.e. set l_1st_euler)
       l_1st_euler = ln_1st_euler
-      IF( .NOT. l_1st_euler .AND. .NOT. ln_rstart ) THEN
+      !
+      IF( ln_rstart ) THEN                              !*  Restart case
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) '   open the restart file'
+         CALL rst_read_open                                              !- Open the restart file
+         !
+         IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 ) THEN     !- Check time-step consistency and force Euler restart if changed
+            CALL iom_get( numror, 'rdt', zrdt )
+            IF( zrdt /= rn_Dt ) THEN
+               IF(lwp) WRITE( numout,*)
+               IF(lwp) WRITE( numout,*) '   rn_Dt = ', rn_Dt,' not equal to the READ one rdt = ', zrdt
+               IF(lwp) WRITE( numout,*)
+               IF(lwp) WRITE( numout,*) '      ==>>>   forced euler first time-step'
+               l_1st_euler =  .TRUE.
+            ENDIF
+         ENDIF
+         !
+         IF( .NOT.l_SAS .AND. iom_varid( numror, 'sshb', ldstop = .FALSE. ) <= 0 ) THEN   !- Check absence of one of the Kbb field (here sshb)
+            !                                                                             !  (any Kbb field is missing ==> all Kbb fields are missing) 
+            IF( .NOT.l_1st_euler ) THEN
+               CALL ctl_warn('dom_nam : ssh at Kbb not found in restart files ',   &
+                  &                        'l_1st_euler forced to .true. and ' ,   &
+                  &                        'ssh(Kbb) = ssh(Kmm) '                  )
+               l_1st_euler = .TRUE.
+            ENDIF
+         ENDIF
+      ELSEIF( .NOT.l_1st_euler ) THEN                   !*  Initialization case
          IF(lwp) WRITE(numout,*)  
          IF(lwp) WRITE(numout,*)'   ==>>>   Start from rest (ln_rstart=F)'
          IF(lwp) WRITE(numout,*)'           an Euler initial time step is used : l_1st_euler is forced to .true. '   
-         l_1st_euler = .true.
-      ENDIF
-      !                             ! control of output frequency
-      IF( .NOT. ln_rst_list ) THEN     ! we use nn_stock
+         l_1st_euler = .TRUE.
+      ENDIF
+      !
+      !                                        !==  control of output frequency  ==!
+      !
+      IF( .NOT. ln_rst_list ) THEN   ! we use nn_stock
          IF( nn_stock == -1 )   CALL ctl_warn( 'nn_stock = -1 --> no restart will be done' )
          IF( nn_stock == 0 .OR. nn_stock > nitend ) THEN
@@ -479,5 +585,5 @@
       IF( Agrif_Root() ) THEN
          IF(lwp) WRITE(numout,*)
-         SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
+         SELECT CASE ( nleapy )                !==  Choose calendar for IOIPSL  ==!
          CASE (  1 ) 
             CALL ioconf_calendar('gregorian')
@@ -491,31 +597,9 @@
          END SELECT
       ENDIF
-
-      READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in reference namelist' )
-      READ  ( numnam_cfg, namdom, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist' )
-      IF(lwm) WRITE( numond, namdom )
-      !
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-            rn_Dt = Agrif_Parent(rn_Dt) / Agrif_Rhot()
-      ENDIF
-#endif
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '   Namelist : namdom   ---   space & time domain'
-         WRITE(numout,*) '      linear free surface (=T)                ln_linssh   = ', ln_linssh
-         WRITE(numout,*) '      create mesh/mask file                   ln_meshmask = ', ln_meshmask
-         WRITE(numout,*) '      ocean time step                         rn_Dt       = ', rn_Dt
-         WRITE(numout,*) '      asselin time filter parameter           rn_atfp     = ', rn_atfp
-         WRITE(numout,*) '      online coarsening of dynamical fields   ln_crs      = ', ln_crs
-      ENDIF
-      !
-      !! Initialise current model timestep rDt = 2*rn_Dt if MLF or rDt = rn_Dt if RK3
-      rDt  = 2._wp * rn_Dt
-      r1_Dt = 1._wp / rDt
-
+      !
+      !                       !========================!
+      !                       !==  namelist namtile  ==!
+      !                       !========================!
+      !
       READ  ( numnam_ref, namtile, IOSTAT = ios, ERR = 905 )
 905   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtile in reference namelist' )
@@ -537,14 +621,10 @@
          ENDIF
       ENDIF
-
-      IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-         lrxios = ln_xios_read.AND.ln_rstart
-!set output file type for XIOS based on NEMO namelist 
-         IF (nn_wxios > 0) lwxios = .TRUE. 
-         nxioso = nn_wxios
-      ENDIF
-
+      !
 #if defined key_netcdf4
-      !                             ! NetCDF 4 case   ("key_netcdf4" defined)
+      !                       !=======================!
+      !                       !==  namelist namnc4  ==!   NetCDF 4 case   ("key_netcdf4" defined)
+      !                       !=======================!
+      !
       READ  ( numnam_ref, namnc4, IOSTAT = ios, ERR = 907)
 907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namnc4 in reference namelist' )
@@ -555,5 +635,5 @@
       IF(lwp) THEN                        ! control print
          WRITE(numout,*)
-         WRITE(numout,*) '   Namelist namnc4 - Netcdf4 chunking parameters'
+         WRITE(numout,*) '   Namelist namnc4 - Netcdf4 chunking parameters ("key_netcdf4" defined)'
          WRITE(numout,*) '      number of chunks in i-dimension             nn_nchunks_i = ', nn_nchunks_i
          WRITE(numout,*) '      number of chunks in j-dimension             nn_nchunks_j = ', nn_nchunks_j
@@ -618,5 +698,5 @@
    SUBROUTINE domain_cfg( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
       !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_nam  ***
+      !!                     ***  ROUTINE domain_cfg  ***
       !!                    
       !! ** Purpose :   read the domain size in domain configuration file
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/dommsk.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/dommsk.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/dommsk.F90	(revision 14062)
@@ -181,4 +181,14 @@
       ssvmask(:,:) = MAXVAL( vmask(:,:,:), DIM=3 )
       ssfmask(:,:) = MAXVAL( fmask(:,:,:), DIM=3 )
+      IF( lk_SWE ) THEN      ! Shallow Water Eq. case : redefine ssfmask
+         DO_2D( 0,0 , 0,0 )
+            ssfmask(ji,jj) = MAX(  ssmask(ji,jj+1), ssmask(ji+1,jj+1),  & 
+               &                   ssmask(ji,jj  ), ssmask(ji+1,jj  )   )
+         END_2D
+         CALL lbc_lnk( 'dommsk', ssfmask, 'F', 1.0_wp )
+      ENDIF
+#if defined key_qco
+      fe3mask(:,:,:) = fmask(:,:,:)
+#endif
 
       ! Interior domain mask  (used for global sum)
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domqco.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domqco.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domqco.F90	(revision 14062)
@@ -8,13 +8,13 @@
    !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl: vvl option includes z_star and z_tilde coordinates
    !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
-   !!            4.x  !  2020-02  (G. Madec, S. Techene) pure z* (quasi-eulerian) coordinate
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dom_qe_init   : define initial vertical scale factors, depths and column thickness
-   !!   dom_qe_r3c    : Compute ssh/h_0 ratioat t-, u-, v-, and optionally f-points
-   !!       qe_rst_read : read/write restart file
-   !!   dom_qe_ctl    : Check the vvl options
+   !!            4.1  !  2019-08  (A. Coward, D. Storkey) add time level indices for prognostic variables
+   !!             -   !  2020-02  (S. Techene, G. Madec) quasi-eulerian coordinate (z* or s*)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_qco_init  : define initial vertical scale factors, depths and column thickness
+   !!   dom_qco_zgr   : Set ssh/h_0 ratio at t
+   !!   dom_qco_r3c   : Compute ssh/h_0 ratio at t-, u-, v-, and optionally f-points
+   !!       qco_ctl   : Check the vvl options
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers
@@ -55,6 +55,4 @@
    LOGICAL , PUBLIC :: ln_vvl_dbg = .FALSE.                ! debug control prints
 
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: un_td, vn_td                ! thickness diffusion transport
-
    !! * Substitutions
 #  include "do_loop_substitute.h90"
@@ -79,5 +77,6 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa   ! time level indices
+      !!----------------------------------------------------------------------
       !
       IF(lwp) WRITE(numout,*)
@@ -85,33 +84,37 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
       !
-      CALL dom_qco_ctl     ! choose vertical coordinate (z_star, z_tilde or layer)
-      !
-      !                    ! Read or initialize e3t_(b/n), tilde_e3t_(b/n) and hdiv_lf
-      CALL qe_rst_read( nit000, Kbb, Kmm )
-      !
-      CALL dom_qco_zgr(Kbb, Kmm, Kaa) ! interpolation scale factor, depth and water column
+      CALL qco_ctl                            ! choose vertical coordinate (z_star, z_tilde or layer)
+      !
+      CALL dom_qco_zgr( Kbb, Kmm )            ! interpolation scale factor, depth and water column
+      !
+#if defined key_agrif
+      ! We need to define r3[tuv](Kaa) for AGRIF initialisation (should not be a
+      ! problem for the restartability...)
+      r3t(:,:,Kaa) = r3t(:,:,Kmm)
+      r3u(:,:,Kaa) = r3u(:,:,Kmm)
+      r3v(:,:,Kaa) = r3v(:,:,Kmm)
+#endif
       !
    END SUBROUTINE dom_qco_init
 
 
-   SUBROUTINE dom_qco_zgr(Kbb, Kmm, Kaa)
+   SUBROUTINE dom_qco_zgr( Kbb, Kmm )
       !!----------------------------------------------------------------------
       !!                ***  ROUTINE dom_qco_init  ***
       !!
-      !! ** Purpose :  Initialization of all ssh. to h._0 ratio
-      !!
-      !! ** Method  :  - interpolate scale factors
-      !!
-      !! ** Action  : - r3(t/u/v)_b
-      !!              - r3(t/u/v/f)_n
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
+      !! ** Purpose :  Initialization of all r3. = ssh./h._0 ratios
+      !!
+      !! ** Method  :  Call domqco using Kbb and Kmm
+      !!               NB: dom_qco_zgr is called by dom_qco_init it uses ssh from ssh_init 
+      !!
+      !! ** Action  : - r3(t/u/v)(Kbb)
+      !!              - r3(t/u/v/f)(Kmm)
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm   ! time level indices
       !!----------------------------------------------------------------------
       !
       !                    !== Set of all other vertical scale factors  ==!  (now and before)
       !                                ! Horizontal interpolation of e3t
-      CALL dom_qco_r3c( ssh(:,:,Kbb), r3t(:,:,Kbb), r3u(:,:,Kbb), r3v(:,:,Kbb) )
+      CALL dom_qco_r3c( ssh(:,:,Kbb), r3t(:,:,Kbb), r3u(:,:,Kbb), r3v(:,:,Kbb)           )
       CALL dom_qco_r3c( ssh(:,:,Kmm), r3t(:,:,Kmm), r3u(:,:,Kmm), r3v(:,:,Kmm), r3f(:,:) )
       !
@@ -143,5 +146,7 @@
       !                                      !==  ratio at u-,v-point  ==!
       !
-      IF( ln_dynadv_vec ) THEN                     !- Vector Form   (thickness weighted averaging)
+!!st      IF( ln_dynadv_vec ) THEN                     !- Vector Form   (thickness weighted averaging)
+#if ! defined key_qcoTest_FluxForm
+      !                                ! no 'key_qcoTest_FluxForm' : surface weighted ssh average
          DO_2D( 0, 0, 0, 0 )
             pr3u(ji,jj) = 0.5_wp * (  e1e2t(ji  ,jj) * pssh(ji  ,jj)  &
@@ -150,10 +155,12 @@
                &                    + e1e2t(ji,jj+1) * pssh(ji,jj+1)  ) * r1_hv_0(ji,jj) * r1_e1e2v(ji,jj)
          END_2D
-      ELSE                                         !- Flux Form   (simple averaging)
+!!st      ELSE                                         !- Flux Form   (simple averaging)
+#else
          DO_2D( 0, 0, 0, 0 )
-            pr3u(ji,jj) = 0.5_wp * (  pssh(ji  ,jj) + pssh(ji+1,jj)  ) * r1_hu_0(ji,jj)
-            pr3v(ji,jj) = 0.5_wp * (  pssh(ji,jj  ) + pssh(ji,jj+1)  ) * r1_hv_0(ji,jj)
+            pr3u(ji,jj) = 0.5_wp * (  pssh(ji,jj) + pssh(ji+1,jj  )  ) * r1_hu_0(ji,jj)
+            pr3v(ji,jj) = 0.5_wp * (  pssh(ji,jj) + pssh(ji  ,jj+1)  ) * r1_hv_0(ji,jj)
          END_2D
-      ENDIF
+!!st      ENDIF
+#endif         
       !
       IF( .NOT.PRESENT( pr3f ) ) THEN              !- lbc on ratio at u-, v-points only
@@ -163,6 +170,9 @@
       ELSE                                   !==  ratio at f-point  ==!
          !
-         IF( ln_dynadv_vec )   THEN                !- Vector Form   (thickness weighted averaging)
-            DO_2D( 1, 0, 1, 0 )                               ! start from 1 since lbc_lnk('F') doesn't update the 1st row/line
+!!st         IF( ln_dynadv_vec )   THEN                !- Vector Form   (thickness weighted averaging)
+#if ! defined key_qcoTest_FluxForm
+         !                                ! no 'key_qcoTest_FluxForm' : surface weighted ssh average
+
+            DO_2D( 0, 0, 0, 0 )                               ! start from 1 since lbc_lnk('F') doesn't update the 1st row/line
                pr3f(ji,jj) = 0.25_wp * (  e1e2t(ji  ,jj  ) * pssh(ji  ,jj  )  &
                   &                     + e1e2t(ji+1,jj  ) * pssh(ji+1,jj  )  &
@@ -170,10 +180,12 @@
                   &                     + e1e2t(ji+1,jj+1) * pssh(ji+1,jj+1)  ) * r1_hf_0(ji,jj) * r1_e1e2f(ji,jj)
             END_2D
-         ELSE                                      !- Flux Form   (simple averaging)
-            DO_2D( 1, 0, 1, 0 )                               ! start from 1 since lbc_lnk('F') doesn't update the 1st row/line
-               pr3f(ji,jj) = 0.25_wp * (  pssh(ji  ,jj  ) + pssh(ji+1,jj  )  &
-                  &                     + pssh(ji  ,jj+1) + pssh(ji+1,jj+1)  ) * r1_hf_0(ji,jj)
+!!st         ELSE                                      !- Flux Form   (simple averaging)
+#else
+            DO_2D( 0, 0, 0, 0 )                               ! start from 1 since lbc_lnk('F') doesn't update the 1st row/line
+               pr3f(ji,jj) = 0.25_wp * (  pssh(ji,jj  ) + pssh(ji+1,jj  )  &
+                  &                     + pssh(ji,jj+1) + pssh(ji+1,jj+1)  ) * r1_hf_0(ji,jj)
             END_2D
-         ENDIF
+!!st         ENDIF
+#endif
          !                                                 ! lbc on ratio at u-,v-,f-points
          CALL lbc_lnk_multi( 'dom_qco_r3c', pr3u, 'U', 1._wp, pr3v, 'V', 1._wp, pr3f, 'F', 1._wp )
@@ -184,113 +196,7 @@
 
 
-   SUBROUTINE qe_rst_read( kt, Kbb, Kmm )
+   SUBROUTINE qco_ctl
       !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE qe_rst_read  ***
-      !!
-      !! ** Purpose :   Read ssh in restart file
-      !!
-      !! ** Method  :   use of IOM library
-      !!                if the restart does not contain ssh,
-      !!                it is set to the _0 values.
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt        ! ocean time-step
-      INTEGER         , INTENT(in) ::   Kbb, Kmm  ! ocean time level indices
-      !
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   id1, id2     ! local integers
-      !!----------------------------------------------------------------------
-      !
-         IF( ln_rstart ) THEN                   !* Read the restart file
-            CALL rst_read_open                  !  open the restart file if necessary
-            !
-            id1 = iom_varid( numror, 'sshb', ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'sshn', ldstop = .FALSE. )
-            !
-            !                             ! --------- !
-            !                             ! all cases !
-            !                             ! --------- !
-            !
-            IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
-               CALL iom_get( numror, jpdom_auto, 'sshb'   , ssh(:,:,Kbb)    )
-               CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm)    )
-               ! needed to restart if land processor not computed
-               IF(lwp) write(numout,*) 'qe_rst_read : ssh(:,:,Kbb) and ssh(:,:,Kmm) found in restart files'
-               WHERE ( ssmask(:,:) == 0.0_wp )   !!gm/st ==> sm should not be necessary on ssh when it was required on e3
-                  ssh(:,:,Kmm) = 0._wp
-                  ssh(:,:,Kbb) = 0._wp
-               END WHERE
-               IF( l_1st_euler ) THEN
-                  ssh(:,:,Kbb) = ssh(:,:,Kmm)
-               ENDIF
-            ELSE IF( id1 > 0 ) THEN
-               IF(lwp) write(numout,*) 'qe_rst_read WARNING : ssh(:,:,Kmm) not found in restart files'
-               IF(lwp) write(numout,*) 'sshn set equal to sshb.'
-               IF(lwp) write(numout,*) 'neuler is forced to 0'
-               CALL iom_get( numror, jpdom_auto, 'sshb', ssh(:,:,Kbb) )
-               ssh(:,:,Kmm) = ssh(:,:,Kbb)
-               l_1st_euler = .TRUE.
-            ELSE IF( id2 > 0 ) THEN
-               IF(lwp) write(numout,*) 'qe_rst_read WARNING : ssh(:,:,Kbb) not found in restart files'
-               IF(lwp) write(numout,*) 'sshb set equal to sshn.'
-               IF(lwp) write(numout,*) 'neuler is forced to 0'
-               CALL iom_get( numror, jpdom_auto, 'sshn', ssh(:,:,Kmm) )
-               ssh(:,:,Kbb) = ssh(:,:,Kmm)
-               l_1st_euler = .TRUE.
-            ELSE
-               IF(lwp) write(numout,*) 'qe_rst_read WARNING : ssh(:,:,Kmm) not found in restart file'
-               IF(lwp) write(numout,*) 'ssh_b and ssh_n set to zero'
-               IF(lwp) write(numout,*) 'neuler is forced to 0'
-               ssh(:,:,:) = 0._wp
-               l_1st_euler = .TRUE.
-            ENDIF
-            !
-         ELSE                                   !* Initialize at "rest"
-            !
-            IF( ll_wd ) THEN   ! MJB ll_wd edits start here - these are essential
-               !
-               IF( cn_cfg == 'wad' ) THEN            ! Wetting and drying test case
-                  CALL usr_def_istate( gdept(:,:,:,Kbb), tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-                  ts (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-                  ssh(:,:    ,Kmm) = ssh(:,:    ,Kbb)
-                  uu (:,:,:  ,Kmm) = uu (:,:,:  ,Kbb)
-                  vv (:,:,:  ,Kmm) = vv (:,:,:  ,Kbb)
-               ELSE                                  ! if not test case
-                  ssh(:,:,Kmm) = -ssh_ref
-                  ssh(:,:,Kbb) = -ssh_ref
-                  !
-                  DO_2D( 1, 1, 1, 1 )
-                     IF( ht_0(ji,jj)-ssh_ref <  rn_wdmin1 ) THEN ! if total depth is less than min depth
-                        ssh(ji,jj,Kbb) = rn_wdmin1 - (ht_0(ji,jj) )
-                        ssh(ji,jj,Kmm) = rn_wdmin1 - (ht_0(ji,jj) )
-                     ENDIF
-                  END_2D
-               ENDIF
-
-               DO ji = 1, jpi
-                  DO jj = 1, jpj
-                     IF ( ht_0(ji,jj) .LE. 0.0 .AND. NINT( ssmask(ji,jj) ) .EQ. 1) THEN
-                       CALL ctl_stop( 'qe_rst_read: ht_0 must be positive at potentially wet points' )
-                     ENDIF
-                  END DO
-               END DO
-               !
-            ELSE
-               !
-               ! Just to read set ssh in fact, called latter once vertical grid
-               ! is set up:
-!               CALL usr_def_istate( gdept_0, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-!               !
-                ssh(:,:,:) = 0._wp
-               !
-            ENDIF           ! end of ll_wd edits
-            !
-         ENDIF
-      !
-   END SUBROUTINE qe_rst_read
-
-
-   SUBROUTINE dom_qco_ctl
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_qco_ctl  ***
+      !!                  ***  ROUTINE qco_ctl  ***
       !!
       !! ** Purpose :   Control the consistency between namelist options
@@ -312,6 +218,6 @@
       IF(lwp) THEN                    ! Namelist print
          WRITE(numout,*)
-         WRITE(numout,*) 'dom_qco_ctl : choice/control of the variable vertical coordinate'
-         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) 'qco_ctl : choice/control of the variable vertical coordinate'
+         WRITE(numout,*) '~~~~~~~~'
          WRITE(numout,*) '   Namelist nam_vvl : chose a vertical coordinate'
          WRITE(numout,*) '      zstar                      ln_vvl_zstar   = ', ln_vvl_zstar
@@ -357,5 +263,5 @@
 #endif
       !
-   END SUBROUTINE dom_qco_ctl
+   END SUBROUTINE qco_ctl
 
    !!======================================================================
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domvvl.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domvvl.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domvvl.F90	(revision 14062)
@@ -9,5 +9,5 @@
    !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
    !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
-   !!            4.x  ! 2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
+   !!             -   !  2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
    !!----------------------------------------------------------------------
 
@@ -766,9 +766,18 @@
       !! ** Purpose :   Read or write VVL file in restart file
       !!
-      !! ** Method  :   use of IOM library
-      !!                if the restart does not contain vertical scale factors,
-      !!                they are set to the _0 values
-      !!                if the restart does not contain vertical scale factors increments (z_tilde),
-      !!                they are set to 0.
+      !! ** Method  : * restart comes from a linear ssh simulation :
+      !!                   an attempt to read e3t_n stops simulation
+      !!              * restart comes from a z-star, z-tilde, or layer :
+      !!                   read e3t_n and e3t_b
+      !!              * restart comes from a z-star :
+      !!                   set tilde_e3t_n, tilde_e3t_n, and hdiv_lf to 0
+      !!              * restart comes from layer :
+      !!                   read tilde_e3t_n and tilde_e3t_b
+      !!                   set hdiv_lf to 0
+      !!              * restart comes from a z-tilde:
+      !!                   read tilde_e3t_n, tilde_e3t_b, and hdiv_lf
+      !!
+      !!              NB: if l_1st_euler = T (ln_1st_euler or ssh_b not found)
+      !!                   Kbb fields set to Kmm ones
       !!----------------------------------------------------------------------
       INTEGER         , INTENT(in) ::   kt        ! ocean time-step
@@ -776,154 +785,91 @@
       CHARACTER(len=*), INTENT(in) ::   cdrw      ! "READ"/"WRITE" flag
       !
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   id1, id2, id3, id4, id5     ! local integers
-      !!----------------------------------------------------------------------
-      !
-      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-         !                                   ! ===============
-         IF( ln_rstart ) THEN                   !* Read the restart file
-            CALL rst_read_open                  !  open the restart file if necessary
-            CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm)    )
+      INTEGER ::   ji, jj, jk      ! dummy loop indices
+      INTEGER ::   id3, id4, id5   ! local integers
+      !!----------------------------------------------------------------------
+      !
+      !                                      !=====================!
+      IF( TRIM(cdrw) == 'READ' ) THEN        !  Read / initialise  !
+         !                                   !=====================!
+         !
+         IF( ln_rstart ) THEN                   !==  Read the restart file  ==!
             !
-            id1 = iom_varid( numror, 'e3t_b', ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'e3t_n', ldstop = .FALSE. )
-            id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
+            CALL rst_read_open                                          !*  open the restart file if necessary
+            !                                         ! --------- !
+            !                                         ! all cases !
+            !                                         ! --------- !
+            !
+            id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )  !*  check presence
             id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
-            id5 = iom_varid( numror, 'hdiv_lf', ldstop = .FALSE. )
+            id5 = iom_varid( numror, 'hdiv_lf'    , ldstop = .FALSE. )
             !
-            !                             ! --------- !
-            !                             ! all cases !
-            !                             ! --------- !
-            !
-            IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
+            !                                                           !*  scale factors
+            IF(lwp) WRITE(numout,*)    '          Kmm scale factor read in the restart file'
+            CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
+            WHERE ( tmask(:,:,:) == 0.0_wp ) 
+               e3t(:,:,:,Kmm) = e3t_0(:,:,:)
+            END WHERE
+            IF( l_1st_euler ) THEN                       ! euler
+               IF(lwp) WRITE(numout,*) '          Euler first time step : e3t(Kbb) = e3t(Kmm)'
+               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
+            ELSE                                         ! leap frog
+               IF(lwp) WRITE(numout,*) '          Kbb scale factor read in the restart file'
                CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               ! needed to restart if land processor not computed 
-               IF(lwp) write(numout,*) 'dom_vvl_rst : e3t(:,:,:,Kbb) and e3t(:,:,:,Kmm) found in restart files'
                WHERE ( tmask(:,:,:) == 0.0_wp ) 
-                  e3t(:,:,:,Kmm) = e3t_0(:,:,:)
                   e3t(:,:,:,Kbb) = e3t_0(:,:,:)
                END WHERE
-               IF( l_1st_euler ) THEN
-                  e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               ENDIF
-            ELSE IF( id1 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_n set equal to e3t_b.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               l_1st_euler = .true.
-            ELSE IF( id2 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kbb) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_b set equal to e3t_n.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ELSE
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart file'
-               IF(lwp) write(numout,*) 'Compute scale factor from sshn'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm) ) &
-                      &                          / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                      &          + e3t_0(:,:,jk)                               * (1._wp -tmask(:,:,jk))
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
             ENDIF
-            !                             ! ----------- !
-            IF( ln_vvl_zstar ) THEN       ! z_star case !
-               !                          ! ----------- !
+            !                                         ! ------------ !
+            IF( ln_vvl_zstar ) THEN                   !  z_star case !
+               !                                      ! ------------ !
                IF( MIN( id3, id4 ) > 0 ) THEN
                   CALL ctl_stop( 'dom_vvl_rst: z_star cannot restart from a z_tilde or layer run' )
                ENDIF
-               !                          ! ----------------------- !
-            ELSE                          ! z_tilde and layer cases !
-               !                          ! ----------------------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN  ! all required arrays exist
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
+               !                                      ! ------------------------ !
+            ELSE                                      !  z_tilde and layer cases !
+               !                                      ! ------------------------ !
+               !
+               IF( id4 > 0 ) THEN                                       !*  scale factor increments
+                  IF(lwp) WRITE(numout,*)    '          Kmm scale factor increments read in the restart file'
                   CALL iom_get( numror, jpdom_auto, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
-               ELSE                            ! one at least array is missing
+                  IF( l_1st_euler ) THEN                 ! euler
+                     IF(lwp) WRITE(numout,*) '          Euler first time step : tilde_e3t(Kbb) = tilde_e3t(Kmm)'
+                     tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:)
+                  ELSE                                   ! leap frog
+                     IF(lwp) WRITE(numout,*) '          Kbb scale factor increments read in the restart file'
+                     CALL iom_get( numror, jpdom_auto, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
+                  ENDIF
+               ELSE 
                   tilde_e3t_b(:,:,:) = 0.0_wp
                   tilde_e3t_n(:,:,:) = 0.0_wp
                ENDIF
-               !                          ! ------------ !
-               IF( ln_vvl_ztilde ) THEN   ! z_tilde case !
-                  !                       ! ------------ !
+               !                                      ! ------------ !
+               IF( ln_vvl_ztilde ) THEN               ! z_tilde case !
+                  !                                   ! ------------ !
                   IF( id5 > 0 ) THEN  ! required array exists
                      CALL iom_get( numror, jpdom_auto, 'hdiv_lf', hdiv_lf(:,:,:) )
                   ELSE                ! array is missing
-                     hdiv_lf(:,:,:) = 0.0_wp
+                     hdiv_lf(:,:,:) = 0.0_wp 
                   ENDIF
                ENDIF
             ENDIF
             !
-         ELSE                                   !* Initialize at "rest"
+         ELSE                                   !==  Initialize at "rest" with ssh  ==!
             !
-
-            IF( ll_wd ) THEN   ! MJB ll_wd edits start here - these are essential 
-               !
-               IF( cn_cfg == 'wad' ) THEN
-                  ! Wetting and drying test case
-                  CALL usr_def_istate( gdept(:,:,:,Kbb), tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-                  ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-                  ssh (:,:,Kmm)     = ssh(:,:,Kbb)
-                  uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
-                  vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
-               ELSE
-                  ! if not test case
-                  ssh(:,:,Kmm) = -ssh_ref
-                  ssh(:,:,Kbb) = -ssh_ref
-
-                  DO_2D( 1, 1, 1, 1 )
-                     IF( ht_0(ji,jj)-ssh_ref <  rn_wdmin1 ) THEN ! if total depth is less than min depth
-                        ssh(ji,jj,Kbb) = rn_wdmin1 - (ht_0(ji,jj) )
-                        ssh(ji,jj,Kmm) = rn_wdmin1 - (ht_0(ji,jj) )
-                     ENDIF
-                  END_2D
-               ENDIF !If test case else
-
-               ! Adjust vertical metrics for all wad
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm)  ) &
-                    &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-
-               DO_2D( 1, 1, 1, 1 )
-                  IF ( ht_0(ji,jj) .LE. 0.0 .AND. NINT( ssmask(ji,jj) ) .EQ. 1) THEN
-                     CALL ctl_stop( 'dom_vvl_rst: ht_0 must be positive at potentially wet points' )
-                  ENDIF
-               END_2D
-               !
-            ELSE
-               !
-               ! Just to read set ssh in fact, called latter once vertical grid
-               ! is set up:
-!               CALL usr_def_istate( gdept_0, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-!               !
-!               DO jk=1,jpk
-!                  e3t(:,:,jk,Kbb) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kbb) ) &
-!                     &            / ( ht_0(:,:) + 1._wp -ssmask(:,:) ) * tmask(:,:,jk)
-!               END DO
-!               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-                ssh(:,:,Kmm)=0._wp
-                e3t(:,:,:,Kmm)=e3t_0(:,:,:)
-                e3t(:,:,:,Kbb)=e3t_0(:,:,:)
-               !
-            END IF           ! end of ll_wd edits
-
+            DO jk = 1, jpk
+               e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( 1._wp + ssh(:,:,Kmm) * r1_ht_0(:,:) * tmask(:,:,jk) )
+            END DO
+            e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
+            !
             IF( ln_vvl_ztilde .OR. ln_vvl_layer) THEN
                tilde_e3t_b(:,:,:) = 0._wp
                tilde_e3t_n(:,:,:) = 0._wp
                IF( ln_vvl_ztilde ) hdiv_lf(:,:,:) = 0._wp
-            END IF
+            ENDIF
          ENDIF
-         !
-      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-         !                                   ! ===================
+         !                                       !=======================!
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN       !  Create restart file  !
+         !                                       !=======================!
+         !
          IF(lwp) WRITE(numout,*) '---- dom_vvl_rst ----'
          !                                           ! --------- !
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domzgr_substitute.h90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domzgr_substitute.h90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/domzgr_substitute.h90	(revision 14062)
@@ -15,9 +15,10 @@
 #   define  e3u(i,j,k,t)   (e3u_0(i,j,k)*(1._wp+r3u(i,j,t)*umask(i,j,k)))
 #   define  e3v(i,j,k,t)   (e3v_0(i,j,k)*(1._wp+r3v(i,j,t)*vmask(i,j,k)))
-#   define  e3f(i,j,k)     (e3f_0(i,j,k)*(1._wp+r3f(i,j)*fmask(i,j,k)))
+#   define  e3f(i,j,k)     (e3f_0(i,j,k)*(1._wp+r3f(i,j)*fe3mask(i,j,k)))
+#   define  e3f_vor(i,j,k) (e3f_0vor(i,j,k)*(1._wp+r3f(i,j)*fe3mask(i,j,k)))
 #   define  e3w(i,j,k,t)   (e3w_0(i,j,k)*(1._wp+r3t(i,j,t)))
 #   define  e3uw(i,j,k,t)  (e3uw_0(i,j,k)*(1._wp+r3u(i,j,t)))
 #   define  e3vw(i,j,k,t)  (e3vw_0(i,j,k)*(1._wp+r3v(i,j,t)))
-#   define  ht(i,j)        (ht_0(i,j)+ssh(i,j,Kmm))
+#   define  ht(i,j)        (ht_0(i,j)*(1._wp+r3t(i,j,Kmm)))
 #   define  hu(i,j,t)      (hu_0(i,j)*(1._wp+r3u(i,j,t)))
 #   define  hv(i,j,t)      (hv_0(i,j)*(1._wp+r3v(i,j,t)))
@@ -29,2 +30,5 @@
 #endif
 !!----------------------------------------------------------------------
+!!#   define  e3t_f(i,j,k)   (e3t_0(i,j,k)*(1._wp+r3t_f(i,j)*tmask(i,j,k)))
+!!#   define  e3u_f(i,j,k)   (e3u_0(i,j,k)*(1._wp+r3u_f(i,j)*umask(i,j,k)))
+!!#   define  e3v_f(i,j,k)   (e3v_0(i,j,k)*(1._wp+r3v_f(i,j)*vmask(i,j,k)))
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/istate.F90	(revision 14062)
@@ -42,5 +42,5 @@
    PRIVATE
 
-   PUBLIC   istate_init   ! routine called by step.F90
+   PUBLIC   istate_init   ! routine called by nemogcm.F90
 
    !! * Substitutions
@@ -59,9 +59,11 @@
       !! 
       !! ** Purpose :   Initialization of the dynamics and tracer fields.
+      !!
+      !! ** Method  :   
       !!----------------------------------------------------------------------
       INTEGER, INTENT( in )  ::  Kbb, Kmm, Kaa   ! ocean time level indices
       !
       INTEGER ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zgdept     ! 3D table  !!st patch to use gdept subtitute
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zgdept     ! 3D table for qco substitute
 !!gm see comment further down
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) ::   zuvd    ! U & V data workspace
@@ -73,15 +75,12 @@
       IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
 
-!!gm  Why not include in the first call of dta_tsd ?  
-!!gm  probably associated with the use of internal damping...
        CALL dta_tsd_init        ! Initialisation of T & S input data
-!!gm to be moved in usrdef of C1D case
+
 !      IF( lk_c1d )   CALL dta_uvd_init        ! Initialization of U & V input data
-!!gm
 
-      rhd  (:,:,:  ) = 0._wp   ;   rhop (:,:,:  ) = 0._wp      ! set one for all to 0 at level jpk
-      rn2b (:,:,:  ) = 0._wp   ;   rn2  (:,:,:  ) = 0._wp      ! set one for all to 0 at levels 1 and jpk
-      ts  (:,:,:,:,Kaa) = 0._wp                                   ! set one for all to 0 at level jpk
-      rab_b(:,:,:,:) = 0._wp   ;   rab_n(:,:,:,:) = 0._wp      ! set one for all to 0 at level jpk
+      rhd  (:,:,:      ) = 0._wp   ;   rhop (:,:,:  ) = 0._wp      ! set one for all to 0 at level jpk
+      rn2b (:,:,:      ) = 0._wp   ;   rn2  (:,:,:  ) = 0._wp      ! set one for all to 0 at levels 1 and jpk
+      ts   (:,:,:,:,Kaa) = 0._wp                                   ! set one for all to 0 at level jpk
+      rab_b(:,:,:,:    ) = 0._wp   ;   rab_n(:,:,:,:) = 0._wp      ! set one for all to 0 at level jpk
 #if defined key_agrif
       uu   (:,:,:  ,Kaa) = 0._wp   ! used in agrif_oce_sponge at initialization
@@ -96,8 +95,11 @@
          CALL agrif_istate( Kbb, Kmm, Kaa )   ! Interp from parent
          !
-         ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb) 
-         ssh (:,:,Kmm)     = ssh(:,:,Kbb)
-         uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
-         vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
+         ts (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)
+!!st
+!!st need for a recent agrif version to be displaced toward ssh_init_rst with agrif_istate_ssh
+         ssh(:,:,    Kmm) = ssh(:,:    ,Kbb)
+!!st end
+         uu (:,:,:  ,Kmm) = uu (:,:,:  ,Kbb)
+         vv (:,:,:  ,Kmm) = vv (:,:,:  ,Kbb)
       ELSE
 #endif
@@ -117,55 +119,27 @@
             CALL dta_tsd( nit000, ts(:,:,:,:,Kbb) )       ! read 3D T and S data at nit000
             !
-            ssh(:,:,Kbb)   = 0._wp               ! set the ocean at rest
-            uu  (:,:,:,Kbb) = 0._wp
-            vv  (:,:,:,Kbb) = 0._wp  
+            uu (:,:,:,Kbb) = 0._wp
+            vv (:,:,:,Kbb) = 0._wp  
             !
-            IF( ll_wd ) THEN
-               ssh(:,:,Kbb) =  -ssh_ref  ! Added in 30 here for bathy that adds 30 as Iterative test CEOD 
-               !
-               ! Apply minimum wetdepth criterion
-               !
-               DO_2D( 1, 1, 1, 1 )
-                  IF( ht_0(ji,jj) + ssh(ji,jj,Kbb)  < rn_wdmin1 ) THEN
-                     ssh(ji,jj,Kbb) = tmask(ji,jj,1)*( rn_wdmin1 - (ht_0(ji,jj)) )
-                  ENDIF
-               END_2D
-            ENDIF 
-             !
          ELSE                                 ! user defined initial T and S
             DO jk = 1, jpk
                zgdept(:,:,jk) = gdept(:,:,jk,Kbb)
             END DO
-            CALL usr_def_istate( zgdept, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )         
+            CALL usr_def_istate( zgdept, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb) )
          ENDIF
-         ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-         ssh (:,:,Kmm)     = ssh(:,:,Kbb)   
-         uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
-         vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
-
-!!gm POTENTIAL BUG :
-!!gm  ISSUE :  if ssh(:,:,Kbb) /= 0  then, in non linear free surface, the e3._n, e3._b should be recomputed
-!!             as well as gdept_ and gdepw_....   !!!!! 
-!!      ===>>>>   probably a call to domvvl initialisation here....
-
+         ts (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
+         uu (:,:,:  ,Kmm) = uu (:,:,:  ,Kbb)
+         vv (:,:,:  ,Kmm) = vv (:,:,:  ,Kbb)
 
          !
-!!gm to be moved in usrdef of C1D case
-!         IF ( ln_uvd_init .AND. lk_c1d ) THEN ! read 3D U and V data at nit000
-!            ALLOCATE( zuvd(jpi,jpj,jpk,2) )
-!            CALL dta_uvd( nit000, zuvd )
-!            uu(:,:,:,Kbb) = zuvd(:,:,:,1) ;  uu(:,:,:,Kmm) = uu(:,:,:,Kbb)
-!            vv(:,:,:,Kbb) = zuvd(:,:,:,2) ;  vv(:,:,:,Kmm) = vv(:,:,:,Kbb)
-!            DEALLOCATE( zuvd )
-!         ENDIF
+!!gm ==>>>  to be moved in usrdef_istate of C1D case 
+         IF ( ln_uvd_init .AND. lk_c1d ) THEN ! read 3D U and V data at nit000
+            ALLOCATE( zuvd(jpi,jpj,jpk,2) )
+            CALL dta_uvd( nit000, Kbb, zuvd )
+            uu(:,:,:,Kbb) = zuvd(:,:,:,1)  ;  uu(:,:,:,Kmm) = uu(:,:,:,Kbb)
+            vv(:,:,:,Kbb) = zuvd(:,:,:,2)  ;  vv(:,:,:,Kmm) = vv(:,:,:,Kbb)
+            DEALLOCATE( zuvd )
+         ENDIF
          !
-!!gm This is to be changed !!!!
-!         ! - ML - ssh(:,:,Kmm) could be modified by istate_eel, so that initialization of e3t(:,:,:,Kbb) is done here
-!         IF( .NOT.ln_linssh ) THEN
-!            DO jk = 1, jpk
-!               e3t(:,:,jk,Kbb) = e3t(:,:,jk,Kmm)
-!            END DO
-!         ENDIF
-!!gm 
          ! 
       ENDIF 
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/phycst.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/phycst.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DOM/phycst.F90	(revision 14062)
@@ -66,4 +66,5 @@
    REAL(wp), PUBLIC ::   r1_rhos                     !: 1 / rhos
    REAL(wp), PUBLIC ::   r1_rcpi                     !: 1 / rcpi
+   
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynadv.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynadv.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynadv.F90	(revision 14062)
@@ -127,5 +127,7 @@
       IF( ioptio /= 1 )   CALL ctl_stop( 'choose ONE and only ONE advection scheme' )
       IF( nn_dynkeg /= nkeg_C2 .AND. nn_dynkeg /= nkeg_HW )   CALL ctl_stop( 'KEG scheme wrong value of nn_dynkeg' )
-
+#if defined key_qcoTest_FluxForm
+      IF( ln_dynadv_vec  ) THEN CALL ctl_stop( 'STOP', 'key_qcoTest_FluxForm requires flux form advection' )
+#endif
 
       IF(lwp) THEN                    ! Print the choice
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynatf_qco.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynatf_qco.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynatf_qco.F90	(revision 14062)
@@ -1,5 +1,5 @@
-MODULE dynatfqco
+MODULE dynatf_qco
    !!=========================================================================
-   !!                       ***  MODULE  dynatfqco  ***
+   !!                       ***  MODULE  dynatf_qco  ***
    !! Ocean dynamics: time filtering
    !!=========================================================================
@@ -50,7 +50,4 @@
    USE prtctl         ! Print control
    USE timing         ! Timing
-#if defined key_agrif
-   USE agrif_oce_interp
-#endif
 
    IMPLICIT NONE
@@ -199,19 +196,19 @@
       ! JC: Would be more clever to swap variables than to make a full vertical
       ! integration
-      !
+      ! CAUTION : calculation need to be done in the same way than see GM  
       uu_b(:,:,Kaa) = e3u(:,:,1,Kaa) * puu(:,:,1,Kaa) * umask(:,:,1)
-      uu_b(:,:,Kmm) = e3u(:,:,1,Kmm) * puu(:,:,1,Kmm) * umask(:,:,1)
+      uu_b(:,:,Kmm) = (e3u_0(:,:,1) * ( 1._wp + r3u_f(:,:) * umask(:,:,1) )) * puu(:,:,1,Kmm) * umask(:,:,1)
       vv_b(:,:,Kaa) = e3v(:,:,1,Kaa) * pvv(:,:,1,Kaa) * vmask(:,:,1)
-      vv_b(:,:,Kmm) = e3v(:,:,1,Kmm) * pvv(:,:,1,Kmm) * vmask(:,:,1)
+      vv_b(:,:,Kmm) = (e3v_0(:,:,1) * ( 1._wp + r3v_f(:,:) * vmask(:,:,1))) * pvv(:,:,1,Kmm) * vmask(:,:,1)
       DO jk = 2, jpkm1
          uu_b(:,:,Kaa) = uu_b(:,:,Kaa) + e3u(:,:,jk,Kaa) * puu(:,:,jk,Kaa) * umask(:,:,jk)
-         uu_b(:,:,Kmm) = uu_b(:,:,Kmm) + e3u(:,:,jk,Kmm) * puu(:,:,jk,Kmm) * umask(:,:,jk)
+         uu_b(:,:,Kmm) = uu_b(:,:,Kmm) + (e3u_0(:,:,jk) * ( 1._wp + r3u_f(:,:) * umask(:,:,jk) )) * puu(:,:,jk,Kmm) * umask(:,:,jk)
          vv_b(:,:,Kaa) = vv_b(:,:,Kaa) + e3v(:,:,jk,Kaa) * pvv(:,:,jk,Kaa) * vmask(:,:,jk)
-         vv_b(:,:,Kmm) = vv_b(:,:,Kmm) + e3v(:,:,jk,Kmm) * pvv(:,:,jk,Kmm) * vmask(:,:,jk)
+         vv_b(:,:,Kmm) = vv_b(:,:,Kmm) + (e3v_0(:,:,jk) * ( 1._wp + r3v_f(:,:) * vmask(:,:,jk) )) * pvv(:,:,jk,Kmm) * vmask(:,:,jk)
       END DO
       uu_b(:,:,Kaa) = uu_b(:,:,Kaa) * r1_hu(:,:,Kaa)
       vv_b(:,:,Kaa) = vv_b(:,:,Kaa) * r1_hv(:,:,Kaa)
-      uu_b(:,:,Kmm) = uu_b(:,:,Kmm) * r1_hu(:,:,Kmm)
-      vv_b(:,:,Kmm) = vv_b(:,:,Kmm) * r1_hv(:,:,Kmm)
+      uu_b(:,:,Kmm) = uu_b(:,:,Kmm) * (r1_hu_0(:,:)/( 1._wp + r3u_f(:,:) ))
+      vv_b(:,:,Kmm) = vv_b(:,:,Kmm) * (r1_hv_0(:,:)/( 1._wp + r3v_f(:,:) ))
       !
       IF( .NOT.ln_dynspg_ts ) THEN        ! output the barotropic currents
@@ -235,3 +232,3 @@
 
    !!=========================================================================
-END MODULE dynatfqco
+END MODULE dynatf_qco
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynhpg.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynhpg.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynhpg.F90	(revision 14062)
@@ -17,4 +17,5 @@
    !!                 !           (A. Coward) suppression of hel, wdj and rot options
    !!            3.6  !  2014-11  (P. Mathiot) hpg_isf: original code for ice shelf cavity
+   !!            4.2  !  2020-12  (M. Bell, A. Young) hpg_djc: revised djc scheme
    !!----------------------------------------------------------------------
 
@@ -72,5 +73,8 @@
    INTEGER, PARAMETER ::   np_isf    =  5   ! s-coordinate similar to sco modify for isf
    !
-   INTEGER, PUBLIC ::   nhpg         !: type of pressure gradient scheme used ! (deduced from ln_hpg_... flags) (PUBLIC for TAM)
+   INTEGER, PUBLIC  ::   nhpg         !: type of pressure gradient scheme used ! (deduced from ln_hpg_... flags) (PUBLIC for TAM)
+   !
+   LOGICAL          ::   ln_hpg_djc_vnh, ln_hpg_djc_vnv                 ! flag to specify hpg_djc boundary condition type
+   REAL(wp), PUBLIC ::   aco_bc_hor, bco_bc_hor, aco_bc_vrt, bco_bc_vrt !: coefficients for hpg_djc hor and vert boundary conditions
 
    !! * Substitutions
@@ -155,5 +159,6 @@
       !!
       NAMELIST/namdyn_hpg/ ln_hpg_zco, ln_hpg_zps, ln_hpg_sco,     &
-         &                 ln_hpg_djc, ln_hpg_prj, ln_hpg_isf
+         &                 ln_hpg_djc, ln_hpg_prj, ln_hpg_isf,     &
+         &                 ln_hpg_djc_vnh, ln_hpg_djc_vnv
       !!----------------------------------------------------------------------
       !
@@ -178,10 +183,5 @@
       ENDIF
       !
-      IF( ln_hpg_djc )   &
-         &   CALL ctl_stop('dyn_hpg_init : Density Jacobian: Cubic polynominal method',   &
-         &                 '   currently disabled (bugs under investigation).'        ,   &
-         &                 '   Please select either  ln_hpg_sco or  ln_hpg_prj instead' )
-         !
-      IF( .NOT.ln_linssh .AND. .NOT.(ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf) )          &
+      IF( .NOT.ln_linssh .AND. .NOT.(ln_hpg_sco.OR.ln_hpg_prj.OR.ln_hpg_isf.OR.ln_hpg_djc) )          &
          &   CALL ctl_stop('dyn_hpg_init : non-linear free surface requires either ',   &
          &                 '   the standard jacobian formulation hpg_sco    or '    ,   &
@@ -219,4 +219,24 @@
       ENDIF
       !                          
+      IF ( ln_hpg_djc ) THEN
+         IF (ln_hpg_djc_vnh) THEN ! Von Neumann boundary condition
+           IF(lwp) WRITE(numout,*) '           horizontal bc: von Neumann '
+           aco_bc_hor = 6.0_wp/5.0_wp
+           bco_bc_hor = 7.0_wp/15.0_wp
+         ELSE ! Linear extrapolation
+           IF(lwp) WRITE(numout,*) '           horizontal bc: linear extrapolation'
+           aco_bc_hor = 3.0_wp/2.0_wp
+           bco_bc_hor = 1.0_wp/2.0_wp
+         END IF
+         IF (ln_hpg_djc_vnv) THEN ! Von Neumann boundary condition
+           IF(lwp) WRITE(numout,*) '           vertical bc: von Neumann '
+           aco_bc_vrt = 6.0_wp/5.0_wp
+           bco_bc_vrt = 7.0_wp/15.0_wp
+         ELSE ! Linear extrapolation
+           IF(lwp) WRITE(numout,*) '           vertical bc: linear extrapolation'
+           aco_bc_vrt = 3.0_wp/2.0_wp
+           bco_bc_vrt = 1.0_wp/2.0_wp
+         END IF
+      END IF
    END SUBROUTINE dyn_hpg_init
 
@@ -612,13 +632,18 @@
       !!
       INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      INTEGER  ::   iktb, iktt          ! jk indices at tracer points for top and bottom points 
       REAL(wp) ::   zcoef0, zep, cffw   ! temporary scalars
-      REAL(wp) ::   z1_10, cffu, cffx   !    "         "
-      REAL(wp) ::   z1_12, cffv, cffy   !    "         "
+      REAL(wp) ::   z_grav_10, z1_12
+      REAL(wp) ::   cffu, cffx          !    "         "
+      REAL(wp) ::   cffv, cffy          !    "         "
       LOGICAL  ::   ll_tmp1, ll_tmp2    ! local logical variables
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zpgu, zpgv   ! 2D workspace
       REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zhpi, zhpj
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   dzx, dzy, dzz, dzu, dzv, dzw
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   drhox, drhoy, drhoz, drhou, drhov, drhow
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   rho_i, rho_j, rho_k
+ 
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdzx, zdzy, zdzz                          ! Primitive grid differences ('delta_xyz')
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdz_i, zdz_j, zdz_k                       ! Harmonic average of primitive grid differences ('d_xyz')
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdrhox, zdrhoy, zdrhoz                    ! Primitive rho differences ('delta_rho')
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zdrho_i, zdrho_j, zdrho_k                 ! Harmonic average of primitive rho differences ('d_rho')
+      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   z_rho_i, z_rho_j, z_rho_k                 ! Face intergrals
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zz_dz_i, zz_dz_j, zz_drho_i, zz_drho_j    ! temporary arrays 
       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   zcpx, zcpy   !W/D pressure filter
       !!----------------------------------------------------------------------
@@ -673,148 +698,212 @@
       ! Local constant initialization
       zcoef0 = - grav * 0.5_wp
-      z1_10  = 1._wp / 10._wp
-      z1_12  = 1._wp / 12._wp
+      z_grav_10  = grav / 10._wp
+      z1_12  = 1.0_wp / 12._wp
 
       !----------------------------------------------------------------------------------------
-      !  compute and store in provisional arrays elementary vertical and horizontal differences
+      !  1. compute and store elementary vertical differences in provisional arrays 
       !----------------------------------------------------------------------------------------
 
-!!bug gm   Not a true bug, but... dzz=e3w  for dzx, dzy verify what it is really
-
-      DO_3D( 0, 0, 0, 0, 2, jpkm1 )
-         drhoz(ji,jj,jk) = rhd    (ji  ,jj  ,jk) - rhd    (ji,jj,jk-1)
-         dzz  (ji,jj,jk) = gde3w(ji  ,jj  ,jk) - gde3w(ji,jj,jk-1)
-         drhox(ji,jj,jk) = rhd    (ji+1,jj  ,jk) - rhd    (ji,jj,jk  )
-         dzx  (ji,jj,jk) = gde3w(ji+1,jj  ,jk) - gde3w(ji,jj,jk  )
-         drhoy(ji,jj,jk) = rhd    (ji  ,jj+1,jk) - rhd    (ji,jj,jk  )
-         dzy  (ji,jj,jk) = gde3w(ji  ,jj+1,jk) - gde3w(ji,jj,jk  )
+!!bug gm   Not a true bug, but... zdzz=e3w  for zdzx, zdzy verify what it is really
+
+      DO_3D( 1, 1, 1, 1, 2, jpkm1 )  
+         zdrhoz(ji,jj,jk) =   rhd    (ji  ,jj  ,jk) - rhd    (ji,jj,jk-1)
+         zdzz  (ji,jj,jk) = - gde3w(ji  ,jj  ,jk) + gde3w(ji,jj,jk-1)
       END_3D
 
       !-------------------------------------------------------------------------
-      ! compute harmonic averages using eq. 5.18
+      ! 2. compute harmonic averages for vertical differences using eq. 5.18
       !-------------------------------------------------------------------------
       zep = 1.e-15
 
-!!bug  gm  drhoz not defined at level 1 and used (jk-1 with jk=2)
-!!bug  gm  idem for drhox, drhoy et ji=jpi and jj=jpj
-
-      DO_3D( 0, 0, 0, 0, 2, jpkm1 )
-         cffw = 2._wp * drhoz(ji  ,jj  ,jk) * drhoz(ji,jj,jk-1)
-
-         cffu = 2._wp * drhox(ji+1,jj  ,jk) * drhox(ji,jj,jk  )
-         cffx = 2._wp * dzx  (ji+1,jj  ,jk) * dzx  (ji,jj,jk  )
-
-         cffv = 2._wp * drhoy(ji  ,jj+1,jk) * drhoy(ji,jj,jk  )
-         cffy = 2._wp * dzy  (ji  ,jj+1,jk) * dzy  (ji,jj,jk  )
-
+!! mb zdrho_k, zdz_k, zdrho_i, zdz_i, zdrho_j, zdz_j re-centred about the point (ji,jj,jk) 
+      zdrho_k(:,:,:) = 0._wp
+      zdz_k  (:,:,:) = 0._wp
+
+      DO_3D( 1, 1, 1, 1, 2, jpk-2 ) 
+         cffw = 2._wp * zdrhoz(ji  ,jj  ,jk) * zdrhoz(ji,jj,jk+1)
          IF( cffw > zep) THEN
-            drhow(ji,jj,jk) = 2._wp *   drhoz(ji,jj,jk) * drhoz(ji,jj,jk-1)   &
-               &                    / ( drhoz(ji,jj,jk) + drhoz(ji,jj,jk-1) )
+            zdrho_k(ji,jj,jk) = cffw / ( zdrhoz(ji,jj,jk) + zdrhoz(ji,jj,jk+1) )
+         ENDIF
+         zdz_k(ji,jj,jk) = 2._wp *   zdzz(ji,jj,jk) * zdzz(ji,jj,jk+1)   &
+            &                  / ( zdzz(ji,jj,jk) + zdzz(ji,jj,jk+1) )
+      END_3D
+
+      !----------------------------------------------------------------------------------
+      ! 3. apply boundary conditions at top and bottom using 5.36-5.37
+      !----------------------------------------------------------------------------------
+
+! mb for sea-ice shelves we will need to re-write this upper boundary condition in the same form as the lower boundary condition
+      zdrho_k(:,:,1) = aco_bc_vrt * ( rhd    (:,:,2) - rhd    (:,:,1) ) - bco_bc_vrt * zdrho_k(:,:,2)
+      zdz_k  (:,:,1) = aco_bc_vrt * (-gde3w(:,:,2) + gde3w(:,:,1) ) - bco_bc_vrt * zdz_k  (:,:,2)
+
+      DO_2D( 1, 1, 1, 1 )
+         IF ( mbkt(ji,jj)>1 ) THEN
+            iktb = mbkt(ji,jj)
+            zdrho_k(ji,jj,iktb) = aco_bc_vrt * (     rhd(ji,jj,iktb) -     rhd(ji,jj,iktb-1) ) - bco_bc_vrt * zdrho_k(ji,jj,iktb-1)
+            zdz_k  (ji,jj,iktb) = aco_bc_vrt * (-gde3w(ji,jj,iktb) + gde3w(ji,jj,iktb-1) ) - bco_bc_vrt * zdz_k  (ji,jj,iktb-1) 
+         END IF
+      END_2D
+
+      !--------------------------------------------------------------
+      ! 4. Compute side face integrals
+      !-------------------------------------------------------------
+
+!! ssh replaces e3w_n ; gde3w is a depth; the formulae involve heights  
+!! rho_k stores grav * FX / rho_0  
+
+      !--------------------------------------------------------------
+      ! 4. a) Upper half of top-most grid box, compute and store
+      !-------------------------------------------------------------
+! *** AY note: ssh(ji,jj,Kmm) + gde3w(ji,jj,1) = e3w(ji,jj,1)
+      DO_2D( 0, 1, 0, 1)
+         z_rho_k(ji,jj,1) =  grav * ( ssh(ji,jj,Kmm) + gde3w(ji,jj,1) )                        & 
+            &                     * (  rhd(ji,jj,1)                                        &
+            &                     + 0.5_wp * (   rhd    (ji,jj,2) - rhd    (ji,jj,1) ) &
+            &                              * (   ssh   (ji,jj,Kmm) + gde3w(ji,jj,1) )          &
+            &                              / ( - gde3w(ji,jj,2) + gde3w(ji,jj,1) )  )
+      END_2D
+
+      !--------------------------------------------------------------
+      ! 4. b) Interior faces, compute and store
+      !-------------------------------------------------------------
+
+      DO_3D( 0, 1, 0, 1, 2, jpkm1 )
+         z_rho_k(ji,jj,jk) = zcoef0 * (   rhd    (ji,jj,jk) + rhd    (ji,jj,jk-1) )                                   &
+            &                       * ( - gde3w(ji,jj,jk) + gde3w(ji,jj,jk-1) )                                               &
+            &                       + z_grav_10 * (                                                                           &
+            &     (   zdrho_k  (ji,jj,jk) - zdrho_k  (ji,jj,jk-1) )                                                           &
+            &   * ( - gde3w(ji,jj,jk) + gde3w(ji,jj,jk-1) - z1_12 * ( zdz_k  (ji,jj,jk) + zdz_k  (ji,jj,jk-1) ) )             &
+            &   - ( zdz_k    (ji,jj,jk) - zdz_k    (ji,jj,jk-1) )                                                             &
+            &   * ( rhd    (ji,jj,jk) - rhd    (ji,jj,jk-1) - z1_12 * ( zdrho_k(ji,jj,jk) + zdrho_k(ji,jj,jk-1) ) )   &
+            &                             )
+      END_3D
+
+      !----------------------------------------------------------------------------------------
+      !  5. compute and store elementary horizontal differences in provisional arrays 
+      !----------------------------------------------------------------------------------------
+
+      DO_3D( 1, 0, 1, 0, 1, jpkm1 )
+         zdrhox(ji,jj,jk) =   rhd    (ji+1,jj  ,jk) - rhd    (ji,jj,jk  )
+         zdzx  (ji,jj,jk) = - gde3w(ji+1,jj  ,jk) + gde3w(ji,jj,jk  )
+         zdrhoy(ji,jj,jk) =   rhd    (ji  ,jj+1,jk) - rhd    (ji,jj,jk  )
+         zdzy  (ji,jj,jk) = - gde3w(ji  ,jj+1,jk) + gde3w(ji,jj,jk  )
+      END_3D
+
+      CALL lbc_lnk_multi( 'dynhpg', zdrhox, 'U', 1., zdzx, 'U', 1., zdrhoy, 'V', 1., zdzy, 'V', 1. ) 
+
+      !-------------------------------------------------------------------------
+      ! 6. compute harmonic averages using eq. 5.18
+      !-------------------------------------------------------------------------
+
+      DO_3D( 0, 1, 0, 1, 1, jpkm1 )
+         cffu = 2._wp * zdrhox(ji-1,jj  ,jk) * zdrhox(ji,jj,jk  )
+         IF( cffu > zep ) THEN
+            zdrho_i(ji,jj,jk) = cffu / ( zdrhox(ji-1,jj,jk) + zdrhox(ji,jj,jk) )
          ELSE
-            drhow(ji,jj,jk) = 0._wp
-         ENDIF
-
-         dzw(ji,jj,jk) = 2._wp *   dzz(ji,jj,jk) * dzz(ji,jj,jk-1)   &
-            &                  / ( dzz(ji,jj,jk) + dzz(ji,jj,jk-1) )
-
-         IF( cffu > zep ) THEN
-            drhou(ji,jj,jk) = 2._wp *   drhox(ji+1,jj,jk) * drhox(ji,jj,jk)   &
-               &                    / ( drhox(ji+1,jj,jk) + drhox(ji,jj,jk) )
+            zdrho_i(ji,jj,jk ) = 0._wp
+         ENDIF
+
+         cffx = 2._wp * zdzx  (ji-1,jj  ,jk) * zdzx  (ji,jj,jk  )
+         IF( cffx > zep ) THEN
+            zdz_i(ji,jj,jk) = cffx / ( zdzx(ji-1,jj,jk) + zdzx(ji,jj,jk) )
          ELSE
-            drhou(ji,jj,jk ) = 0._wp
-         ENDIF
-
-         IF( cffx > zep ) THEN
-            dzu(ji,jj,jk) = 2._wp *   dzx(ji+1,jj,jk) * dzx(ji,jj,jk)   &
-               &                  / ( dzx(ji+1,jj,jk) + dzx(ji,jj,jk) )
+            zdz_i(ji,jj,jk) = 0._wp
+         ENDIF
+
+         cffv = 2._wp * zdrhoy(ji  ,jj-1,jk) * zdrhoy(ji,jj,jk  )
+         IF( cffv > zep ) THEN
+            zdrho_j(ji,jj,jk) = cffv / ( zdrhoy(ji,jj-1,jk) + zdrhoy(ji,jj,jk) )
          ELSE
-            dzu(ji,jj,jk) = 0._wp
-         ENDIF
-
-         IF( cffv > zep ) THEN
-            drhov(ji,jj,jk) = 2._wp *   drhoy(ji,jj+1,jk) * drhoy(ji,jj,jk)   &
-               &                    / ( drhoy(ji,jj+1,jk) + drhoy(ji,jj,jk) )
+            zdrho_j(ji,jj,jk) = 0._wp
+         ENDIF
+
+         cffy = 2._wp * zdzy  (ji  ,jj-1,jk) * zdzy  (ji,jj,jk  )
+         IF( cffy > zep ) THEN
+            zdz_j(ji,jj,jk) = cffy / ( zdzy(ji,jj-1,jk) + zdzy(ji,jj,jk) )
          ELSE
-            drhov(ji,jj,jk) = 0._wp
-         ENDIF
-
-         IF( cffy > zep ) THEN
-            dzv(ji,jj,jk) = 2._wp *   dzy(ji,jj+1,jk) * dzy(ji,jj,jk)   &
-               &                  / ( dzy(ji,jj+1,jk) + dzy(ji,jj,jk) )
-         ELSE
-            dzv(ji,jj,jk) = 0._wp
-         ENDIF
-
-      END_3D
+            zdz_j(ji,jj,jk) = 0._wp
+         ENDIF
+      END_3D
+      
+!!! Note that zdzx, zdzy, zdzz, zdrhox, zdrhoy and zdrhoz should NOT be used beyond this point      
 
       !----------------------------------------------------------------------------------
-      ! apply boundary conditions at top and bottom using 5.36-5.37
+      ! 6B. apply boundary conditions at side boundaries using 5.36-5.37
       !----------------------------------------------------------------------------------
-      drhow(:,:, 1 ) = 1.5_wp * ( drhoz(:,:, 2 ) - drhoz(:,:,  1  ) ) - 0.5_wp * drhow(:,:,  2  )
-      drhou(:,:, 1 ) = 1.5_wp * ( drhox(:,:, 2 ) - drhox(:,:,  1  ) ) - 0.5_wp * drhou(:,:,  2  )
-      drhov(:,:, 1 ) = 1.5_wp * ( drhoy(:,:, 2 ) - drhoy(:,:,  1  ) ) - 0.5_wp * drhov(:,:,  2  )
-
-      drhow(:,:,jpk) = 1.5_wp * ( drhoz(:,:,jpk) - drhoz(:,:,jpkm1) ) - 0.5_wp * drhow(:,:,jpkm1)
-      drhou(:,:,jpk) = 1.5_wp * ( drhox(:,:,jpk) - drhox(:,:,jpkm1) ) - 0.5_wp * drhou(:,:,jpkm1)
-      drhov(:,:,jpk) = 1.5_wp * ( drhoy(:,:,jpk) - drhoy(:,:,jpkm1) ) - 0.5_wp * drhov(:,:,jpkm1)
-
+
+      DO jk = 1, jpkm1
+         zz_drho_i(:,:) = zdrho_i(:,:,jk)
+         zz_dz_i  (:,:) = zdz_i  (:,:,jk)
+         zz_drho_j(:,:) = zdrho_j(:,:,jk)
+         zz_dz_j  (:,:) = zdz_j  (:,:,jk)
+         DO_2D( 0, 1, 0, 1)
+            ! Walls coming from left: should check from 2 to jpi-1 (and jpj=2-jpj)
+            IF (ji < jpi) THEN
+               IF ( umask(ji,jj,jk) > 0.5_wp .AND. umask(ji-1,jj,jk) < 0.5_wp .AND. umask(ji+1,jj,jk) > 0.5_wp)  THEN  
+                  zz_drho_i(ji,jj) = aco_bc_hor * ( rhd    (ji+1,jj,jk) - rhd    (ji,jj,jk) ) - bco_bc_hor * zdrho_i(ji+1,jj,jk) 
+                  zz_dz_i  (ji,jj) = aco_bc_hor * (-gde3w(ji+1,jj,jk) + gde3w(ji,jj,jk) ) - bco_bc_hor * zdz_i  (ji+1,jj,jk)
+               END IF
+            END IF
+            ! Walls coming from right: should check from 3 to jpi (and jpj=2-jpj)
+            IF (ji > 2) THEN
+               IF ( umask(ji,jj,jk) < 0.5_wp .AND. umask(ji-1,jj,jk) > 0.5_wp .AND. umask(ji-2,jj,jk) > 0.5_wp) THEN
+                  zz_drho_i(ji,jj) = aco_bc_hor * ( rhd    (ji,jj,jk) - rhd    (ji-1,jj,jk) ) - bco_bc_hor * zdrho_i(ji-1,jj,jk)  
+                  zz_dz_i  (ji,jj) = aco_bc_hor * (-gde3w(ji,jj,jk) + gde3w(ji-1,jj,jk) ) - bco_bc_hor * zdz_i  (ji-1,jj,jk)
+               END IF
+            END IF
+            ! Walls coming from left: should check from 2 to jpj-1 (and jpi=2-jpi)
+            IF (jj < jpj) THEN
+               IF ( vmask(ji,jj,jk) > 0.5_wp .AND. vmask(ji,jj-1,jk) < 0.5_wp .AND. vmask(ji,jj+1,jk) > 0.5_wp)  THEN
+                  zz_drho_j(ji,jj) = aco_bc_hor * ( rhd    (ji,jj+1,jk) - rhd    (ji,jj,jk) ) - bco_bc_hor * zdrho_j(ji,jj+1,jk)
+                  zz_dz_j  (ji,jj) = aco_bc_hor * (-gde3w(ji,jj+1,jk) + gde3w(ji,jj,jk) ) - bco_bc_hor * zdz_j  (ji,jj+1,jk)
+               END IF
+            END IF 
+            ! Walls coming from right: should check from 3 to jpj (and jpi=2-jpi)
+            IF (jj > 2) THEN
+               IF ( vmask(ji,jj,jk) < 0.5_wp .AND. vmask(ji,jj-1,jk) > 0.5_wp .AND. vmask(ji,jj-2,jk) > 0.5_wp) THEN 
+                  zz_drho_j(ji,jj) = aco_bc_hor * ( rhd    (ji,jj,jk) - rhd    (ji,jj-1,jk) ) - bco_bc_hor * zdrho_j(ji,jj-1,jk) 
+                  zz_dz_j  (ji,jj) = aco_bc_hor * (-gde3w(ji,jj,jk) + gde3w(ji,jj-1,jk) ) - bco_bc_hor * zdz_j  (ji,jj-1,jk)
+               END IF
+            END IF
+         END_2D
+         zdrho_i(:,:,jk) = zz_drho_i(:,:)
+         zdz_i  (:,:,jk) = zz_dz_i  (:,:)
+         zdrho_j(:,:,jk) = zz_drho_j(:,:)
+         zdz_j  (:,:,jk) = zz_dz_j  (:,:)
+      END DO
 
       !--------------------------------------------------------------
-      ! Upper half of top-most grid box, compute and store
+      ! 7. Calculate integrals on side faces  
       !-------------------------------------------------------------
 
-!!bug gm   :  e3w-gde3w(:,:,:) = 0.5*e3w  ....  and gde3w(:,:,2)-gde3w(:,:,1)=e3w(:,:,2,Kmm) ....   to be verified
-!          true if gde3w(:,:,:) is really defined as the sum of the e3w scale factors as, it seems to me, it should be
-
-      DO_2D( 0, 0, 0, 0 )
-         rho_k(ji,jj,1) = -grav * ( e3w(ji,jj,1,Kmm) - gde3w(ji,jj,1) )               &
-            &                   * (  rhd(ji,jj,1)                                     &
-            &                     + 0.5_wp * ( rhd    (ji,jj,2) - rhd    (ji,jj,1) )  &
-            &                              * ( e3w  (ji,jj,1,Kmm) - gde3w(ji,jj,1) )  &
-            &                              / ( gde3w(ji,jj,2) - gde3w(ji,jj,1) )  )
-      END_2D
-
-!!bug gm    : here also, simplification is possible
-!!bug gm    : optimisation: 1/10 and 1/12 the division should be done before the loop
-
-      DO_3D( 0, 0, 0, 0, 2, jpkm1 )
-
-         rho_k(ji,jj,jk) = zcoef0 * ( rhd    (ji,jj,jk) + rhd    (ji,jj,jk-1) )                                   &
-            &                     * ( gde3w(ji,jj,jk) - gde3w(ji,jj,jk-1) )                                   &
-            &            - grav * z1_10 * (                                                                   &
-            &     ( drhow  (ji,jj,jk) - drhow  (ji,jj,jk-1) )                                                     &
-            &   * ( gde3w(ji,jj,jk) - gde3w(ji,jj,jk-1) - z1_12 * ( dzw  (ji,jj,jk) + dzw  (ji,jj,jk-1) ) )   &
-            &   - ( dzw    (ji,jj,jk) - dzw    (ji,jj,jk-1) )                                                     &
-            &   * ( rhd    (ji,jj,jk) - rhd    (ji,jj,jk-1) - z1_12 * ( drhow(ji,jj,jk) + drhow(ji,jj,jk-1) ) )   &
-            &                             )
-
-         rho_i(ji,jj,jk) = zcoef0 * ( rhd    (ji+1,jj,jk) + rhd    (ji,jj,jk) )                                   &
-            &                     * ( gde3w(ji+1,jj,jk) - gde3w(ji,jj,jk) )                                   &
-            &            - grav* z1_10 * (                                                                    &
-            &     ( drhou  (ji+1,jj,jk) - drhou  (ji,jj,jk) )                                                     &
-            &   * ( gde3w(ji+1,jj,jk) - gde3w(ji,jj,jk) - z1_12 * ( dzu  (ji+1,jj,jk) + dzu  (ji,jj,jk) ) )   &
-            &   - ( dzu    (ji+1,jj,jk) - dzu    (ji,jj,jk) )                                                     &
-            &   * ( rhd    (ji+1,jj,jk) - rhd    (ji,jj,jk) - z1_12 * ( drhou(ji+1,jj,jk) + drhou(ji,jj,jk) ) )   &
-            &                            )
-
-         rho_j(ji,jj,jk) = zcoef0 * ( rhd    (ji,jj+1,jk) + rhd    (ji,jj,jk) )                                 &
-            &                     * ( gde3w(ji,jj+1,jk) - gde3w(ji,jj,jk) )                                   &
-            &            - grav* z1_10 * (                                                                    &
-            &     ( drhov  (ji,jj+1,jk) - drhov  (ji,jj,jk) )                                                     &
-            &   * ( gde3w(ji,jj+1,jk) - gde3w(ji,jj,jk) - z1_12 * ( dzv  (ji,jj+1,jk) + dzv  (ji,jj,jk) ) )   &
-            &   - ( dzv    (ji,jj+1,jk) - dzv    (ji,jj,jk) )                                                     &
-            &   * ( rhd    (ji,jj+1,jk) - rhd    (ji,jj,jk) - z1_12 * ( drhov(ji,jj+1,jk) + drhov(ji,jj,jk) ) )   &
-            &                            )
-
-      END_3D
-      CALL lbc_lnk_multi( 'dynhpg', rho_k, 'W', 1.0_wp, rho_i, 'U', 1.0_wp, rho_j, 'V', 1.0_wp )
-      !
-      ! ---------------
-      !  Surface pressure gradient to be removed
-      ! ---------------
-      DO_2D( 0, 0, 0, 0 )
-         zpgu(ji,jj) = - grav * ( ssh(ji+1,jj,Kmm) - ssh(ji,jj,Kmm) ) * r1_e1u(ji,jj)
-         zpgv(ji,jj) = - grav * ( ssh(ji,jj+1,Kmm) - ssh(ji,jj,Kmm) ) * r1_e2v(ji,jj)
-      END_2D
+      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+! two -ve signs cancel in next two lines (within zcoef0 and because gde3w is a depth not a height)
+         z_rho_i(ji,jj,jk) = zcoef0 * ( rhd    (ji+1,jj,jk) + rhd    (ji,jj,jk) )                                       &
+             &                    * ( gde3w(ji+1,jj,jk) - gde3w(ji,jj,jk) )                                    
+         IF ( umask(ji-1, jj, jk) > 0.5 .OR. umask(ji+1, jj, jk) > 0.5 ) THEN
+            z_rho_i(ji,jj,jk) = z_rho_i(ji,jj,jk) - z_grav_10 * (                                                               &
+             &     (   zdrho_i  (ji+1,jj,jk) - zdrho_i  (ji,jj,jk) )                                                            &
+             &   * ( - gde3w(ji+1,jj,jk) + gde3w(ji,jj,jk) - z1_12 * ( zdz_i  (ji+1,jj,jk) + zdz_i  (ji,jj,jk) ) )              &
+             &   - (   zdz_i    (ji+1,jj,jk) - zdz_i    (ji,jj,jk) )                                                            &
+             &   * (   rhd    (ji+1,jj,jk) - rhd    (ji,jj,jk) - z1_12 * ( zdrho_i(ji+1,jj,jk) + zdrho_i(ji,jj,jk) ) )  &
+             &                                               )
+         END IF
+  
+         z_rho_j(ji,jj,jk) = zcoef0 * ( rhd    (ji,jj+1,jk) + rhd    (ji,jj,jk) )                                       &
+             &                    * ( gde3w(ji,jj+1,jk) - gde3w(ji,jj,jk) )                                  
+         IF ( vmask(ji, jj-1, jk) > 0.5 .OR. vmask(ji, jj+1, jk) > 0.5 ) THEN
+            z_rho_j(ji,jj,jk) = z_rho_j(ji,jj,jk) - z_grav_10 * (                                                               &
+             &     (   zdrho_j  (ji,jj+1,jk) - zdrho_j  (ji,jj,jk) )                                                            &
+             &   * ( - gde3w(ji,jj+1,jk) + gde3w(ji,jj,jk) - z1_12 * ( zdz_j  (ji,jj+1,jk) + zdz_j  (ji,jj,jk) ) )              &
+             &   - (   zdz_j    (ji,jj+1,jk) - zdz_j    (ji,jj,jk) )                                                            &
+             &   * (   rhd    (ji,jj+1,jk) - rhd    (ji,jj,jk) - z1_12 * ( zdrho_j(ji,jj+1,jk) + zdrho_j(ji,jj,jk) ) )  &
+             &                                                 )
+         END IF
+      END_3D
+
+      !--------------------------------------------------------------
+      ! 8. Integrate in the vertical   
+      !-------------------------------------------------------------
       !
       ! ---------------
@@ -822,6 +911,6 @@
       ! ---------------
       DO_2D( 0, 0, 0, 0 )
-         zhpi(ji,jj,1) = ( rho_k(ji+1,jj  ,1) - rho_k(ji,jj,1) - rho_i(ji,jj,1) ) * r1_e1u(ji,jj)
-         zhpj(ji,jj,1) = ( rho_k(ji  ,jj+1,1) - rho_k(ji,jj,1) - rho_j(ji,jj,1) ) * r1_e2v(ji,jj)
+         zhpi(ji,jj,1) = ( z_rho_k(ji,jj,1) - z_rho_k(ji+1,jj  ,1) - z_rho_i(ji,jj,1) ) * r1_e1u(ji,jj)
+         zhpj(ji,jj,1) = ( z_rho_k(ji,jj,1) - z_rho_k(ji  ,jj+1,1) - z_rho_j(ji,jj,1) ) * r1_e2v(ji,jj)
          IF( ln_wd_il ) THEN
            zhpi(ji,jj,1) = zhpi(ji,jj,1) * zcpx(ji,jj)
@@ -829,6 +918,6 @@
          ENDIF
          ! add to the general momentum trend
-         puu(ji,jj,1,Krhs) = puu(ji,jj,1,Krhs) + zhpi(ji,jj,1) - zpgu(ji,jj)
-         pvv(ji,jj,1,Krhs) = pvv(ji,jj,1,Krhs) + zhpj(ji,jj,1) - zpgv(ji,jj)
+         puu(ji,jj,1,Krhs) = puu(ji,jj,1,Krhs) + zhpi(ji,jj,1)
+         pvv(ji,jj,1,Krhs) = pvv(ji,jj,1,Krhs) + zhpj(ji,jj,1)
       END_2D
 
@@ -838,10 +927,10 @@
       DO_3D( 0, 0, 0, 0, 2, jpkm1 )
          ! hydrostatic pressure gradient along s-surfaces
-         zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)                                &
-            &           + (  ( rho_k(ji+1,jj,jk) - rho_k(ji,jj,jk  ) )    &
-            &              - ( rho_i(ji  ,jj,jk) - rho_i(ji,jj,jk-1) )  ) * r1_e1u(ji,jj)
-         zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)                                &
-            &           + (  ( rho_k(ji,jj+1,jk) - rho_k(ji,jj,jk  ) )    &
-            &               -( rho_j(ji,jj  ,jk) - rho_j(ji,jj,jk-1) )  ) * r1_e2v(ji,jj)
+         zhpi(ji,jj,jk) = zhpi(ji,jj,jk-1)                                                     &
+            &           + (  ( z_rho_k(ji,jj,jk) - z_rho_k(ji+1,jj,jk  ) )                     &
+            &              - ( z_rho_i(ji,jj,jk) - z_rho_i(ji  ,jj,jk-1) )  ) * r1_e1u(ji,jj)
+         zhpj(ji,jj,jk) = zhpj(ji,jj,jk-1)                                                     &
+            &           + (  ( z_rho_k(ji,jj,jk) - z_rho_k(ji,jj+1,jk  ) )                     &
+            &               -( z_rho_j(ji,jj,jk) - z_rho_j(ji,jj  ,jk-1) )  ) * r1_e2v(ji,jj)
          IF( ln_wd_il ) THEN
            zhpi(ji,jj,jk) = zhpi(ji,jj,jk) * zcpx(ji,jj)
@@ -849,6 +938,6 @@
          ENDIF
          ! add to the general momentum trend
-         puu(ji,jj,jk,Krhs) = puu(ji,jj,jk,Krhs) + zhpi(ji,jj,jk) - zpgu(ji,jj)
-         pvv(ji,jj,jk,Krhs) = pvv(ji,jj,jk,Krhs) + zhpj(ji,jj,jk) - zpgv(ji,jj)
+         puu(ji,jj,jk,Krhs) = puu(ji,jj,jk,Krhs) + zhpi(ji,jj,jk)
+         pvv(ji,jj,jk,Krhs) = pvv(ji,jj,jk,Krhs) + zhpj(ji,jj,jk)
       END_3D
       !
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynldf_lap_blp.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynldf_lap_blp.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynldf_lap_blp.F90	(revision 14062)
@@ -5,4 +5,5 @@
    !!======================================================================
    !! History : 3.7  ! 2014-01  (G. Madec, S. Masson)  Original code, re-entrant laplacian
+   !!           4.0  ! 2020-04  (A. Nasser, G. Madec)  Add symmetric mixing tensor 
    !!----------------------------------------------------------------------
 
@@ -19,5 +20,6 @@
    USE in_out_manager ! I/O manager
    USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-
+   USE lib_mpp
+   
    IMPLICIT NONE
    PRIVATE
@@ -47,4 +49,6 @@
       !!
       !! ** Action : - pu_rhs, pv_rhs increased by the harmonic operator applied on pu, pv.
+      !!
+      !! Reference : S.Griffies, R.Hallberg 2000 Mon.Wea.Rev., DOI:/ 
       !!----------------------------------------------------------------------
       INTEGER                         , INTENT(in   ) ::   kt         ! ocean time-step index
@@ -57,5 +61,6 @@
       REAL(wp) ::   zsign        ! local scalars
       REAL(wp) ::   zua, zva     ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   zcur, zdiv
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zcur, zdiv
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zten, zshe   ! tension (diagonal) and shearing (anti-diagonal) terms
       !!----------------------------------------------------------------------
       !
@@ -70,30 +75,78 @@
       ENDIF
       !
-      !                                                ! ===============
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !                                             ! ===============
-         DO_2D( 0, 1, 0, 1 )
-            !                                      ! ahm * e3 * curl  (computed from 1 to jpim1/jpjm1)
-            zcur(ji-1,jj-1) = ahmf(ji-1,jj-1,jk) * e3f(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)       &   ! ahmf already * by fmask
-               &     * (  e2v(ji  ,jj-1) * pv(ji  ,jj-1,jk) - e2v(ji-1,jj-1) * pv(ji-1,jj-1,jk)  &
-               &        - e1u(ji-1,jj  ) * pu(ji-1,jj  ,jk) + e1u(ji-1,jj-1) * pu(ji-1,jj-1,jk)  )
-            !                                      ! ahm * div        (computed from 2 to jpi/jpj)
-            zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / e3t(ji,jj,jk,Kbb)               &   ! ahmt already * by tmask
-               &     * (  e2u(ji,jj)*e3u(ji,jj,jk,Kbb) * pu(ji,jj,jk) - e2u(ji-1,jj)*e3u(ji-1,jj,jk,Kbb) * pu(ji-1,jj,jk)  &
-               &        + e1v(ji,jj)*e3v(ji,jj,jk,Kbb) * pv(ji,jj,jk) - e1v(ji,jj-1)*e3v(ji,jj-1,jk,Kbb) * pv(ji,jj-1,jk)  )
-         END_2D
+      SELECT CASE( nn_dynldf_typ )  
+      !              
+      CASE ( np_typ_rot )       !==  Vorticity-Divergence operator  ==!
          !
-         DO_2D( 0, 0, 0, 0 )                       ! - curl( curl) + grad( div )
-            pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * umask(ji,jj,jk) * (    &    ! * by umask is mandatory for dyn_ldf_blp use
-               &              - ( zcur(ji  ,jj) - zcur(ji,jj-1) ) * r1_e2u(ji,jj) / e3u(ji,jj,jk,Kmm)   &
-               &              + ( zdiv(ji+1,jj) - zdiv(ji,jj  ) ) * r1_e1u(ji,jj)                      )
+         ALLOCATE( zcur(jpi,jpj) , zdiv(jpi,jpj) )
+         !
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !
+            DO_2D( 0, 1, 0, 1 )
+               !                                      ! ahm * e3 * curl  (computed from 1 to jpim1/jpjm1)
+               zcur(ji-1,jj-1) = ahmf(ji-1,jj-1,jk) * e3f(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)       &   ! ahmf already * by fmask
+                  &     * (  e2v(ji  ,jj-1) * pv(ji  ,jj-1,jk) - e2v(ji-1,jj-1) * pv(ji-1,jj-1,jk)  &
+                  &        - e1u(ji-1,jj  ) * pu(ji-1,jj  ,jk) + e1u(ji-1,jj-1) * pu(ji-1,jj-1,jk)  )
+               !                                      ! ahm * div        (computed from 2 to jpi/jpj)
+               zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / e3t(ji,jj,jk,Kbb)               &   ! ahmt already * by tmask
+                  &     * (  e2u(ji,jj)*e3u(ji,jj,jk,Kbb) * pu(ji,jj,jk) - e2u(ji-1,jj)*e3u(ji-1,jj,jk,Kbb) * pu(ji-1,jj,jk)  &
+                  &        + e1v(ji,jj)*e3v(ji,jj,jk,Kbb) * pv(ji,jj,jk) - e1v(ji,jj-1)*e3v(ji,jj-1,jk,Kbb) * pv(ji,jj-1,jk)  )
+            END_2D
+            !
+            DO_2D( 0, 0, 0, 0 )                       ! - curl( curl) + grad( div )
+               pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * umask(ji,jj,jk) * (    &    ! * by umask is mandatory for dyn_ldf_blp use
+                  &              - ( zcur(ji  ,jj) - zcur(ji,jj-1) ) * r1_e2u(ji,jj) / e3u(ji,jj,jk,Kmm)   &
+                  &              + ( zdiv(ji+1,jj) - zdiv(ji,jj  ) ) * r1_e1u(ji,jj)                      )
                !
-            pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * vmask(ji,jj,jk) * (    &    ! * by vmask is mandatory for dyn_ldf_blp use
-               &                ( zcur(ji,jj  ) - zcur(ji-1,jj) ) * r1_e1v(ji,jj) / e3v(ji,jj,jk,Kmm)   &
-               &              + ( zdiv(ji,jj+1) - zdiv(ji  ,jj) ) * r1_e2v(ji,jj)                      )
-         END_2D
-         !                                             ! ===============
-      END DO                                           !   End of slab
-      !                                                ! ===============
+               pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * vmask(ji,jj,jk) * (    &    ! * by vmask is mandatory for dyn_ldf_blp use
+                  &                ( zcur(ji,jj  ) - zcur(ji-1,jj) ) * r1_e1v(ji,jj) / e3v(ji,jj,jk,Kmm)   &
+                  &              + ( zdiv(ji,jj+1) - zdiv(ji  ,jj) ) * r1_e2v(ji,jj)                      )
+            END_2D
+            !
+         END DO                                           !   End of slab
+         !
+         DEALLOCATE( zcur , zdiv )
+         !
+      CASE ( np_typ_sym )       !==  Symmetric operator  ==!
+         !
+         ALLOCATE( zten(jpi,jpj) , zshe(jpi,jpj) )
+         !
+         DO jk = 1, jpkm1                                 ! Horizontal slab
+            !
+            DO_2D( 0, 1, 0, 1 )
+               !                                      ! shearing stress component (F-point)   NB : ahmf has already been multiplied by fmask
+               zshe(ji-1,jj-1) = ahmf(ji-1,jj-1,jk)                                                              &
+                  &     * (    e1f(ji-1,jj-1)    * r1_e2f(ji-1,jj-1)                                             &
+                  &         * ( pu(ji-1,jj  ,jk) * r1_e1u(ji-1,jj  )  - pu(ji-1,jj-1,jk) * r1_e1u(ji-1,jj-1) )   &
+                  &         +  e2f(ji-1,jj-1)    * r1_e1f(ji-1,jj-1)                                             &
+                  &         * ( pv(ji  ,jj-1,jk) * r1_e2v(ji  ,jj-1)  - pv(ji-1,jj-1,jk) * r1_e2v(ji-1,jj-1) )   ) 
+               !                                      ! tension stress component (T-point)   NB : ahmt has already been multiplied by tmask
+               zten(ji,jj)    = ahmt(ji,jj,jk)                                                       &
+                  &     * (    e2t(ji,jj)    * r1_e1t(ji,jj)                                         &
+                  &         * ( pu(ji,jj,jk) * r1_e2u(ji,jj)  - pu(ji-1,jj,jk) * r1_e2u(ji-1,jj) )   &
+                  &         -  e1t(ji,jj)    * r1_e2t(ji,jj)                                         &
+                  &         * ( pv(ji,jj,jk) * r1_e1v(ji,jj)  - pv(ji,jj-1,jk) * r1_e1v(ji,jj-1) )   )   
+            END_2D
+            !
+            DO_2D( 0, 0, 0, 0 )
+               pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * r1_e1e2u(ji,jj) / e3u(ji,jj,jk,Kmm)                               &
+                  &    * (   (   zten(ji+1,jj  ) * e2t(ji+1,jj  )*e2t(ji+1,jj  ) * e3t(ji+1,jj  ,jk,Kmm)                       &
+                  &            - zten(ji  ,jj  ) * e2t(ji  ,jj  )*e2t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm) ) * r1_e2u(ji,jj)     &                                                    
+                  &        + (   zshe(ji  ,jj  ) * e1f(ji  ,jj  )*e1f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                           &
+                  &            - zshe(ji  ,jj-1) * e1f(ji  ,jj-1)*e1f(ji  ,jj-1) * e3f(ji  ,jj-1,jk)     ) * r1_e1u(ji,jj) )   
+               !
+               pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * r1_e1e2v(ji,jj) / e3v(ji,jj,jk,Kmm)                               &
+                  &    * (   (   zshe(ji  ,jj  ) * e2f(ji  ,jj  )*e2f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                           &
+                  &            - zshe(ji-1,jj  ) * e2f(ji-1,jj  )*e2f(ji-1,jj  ) * e3f(ji-1,jj  ,jk)     ) * r1_e2v(ji,jj)     &
+                  &        - (   zten(ji  ,jj+1) * e1t(ji  ,jj+1)*e1t(ji  ,jj+1) * e3t(ji  ,jj+1,jk,Kmm)                       &
+                  &            - zten(ji  ,jj  ) * e1t(ji  ,jj  )*e1t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm) ) * r1_e1v(ji,jj) )
+               !
+            END_2D
+            !
+         END DO
+         !
+         DEALLOCATE( zten , zshe )
+         !
+      END SELECT
       !
    END SUBROUTINE dyn_ldf_lap
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynspg_ts.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynspg_ts.F90	(revision 14062)
@@ -295,7 +295,7 @@
       ENDIF
       !
-      !                                   !=  Add atmospheric pressure forcing  =!
-      !                                   !  ----------------------------------  !
-      IF( ln_bt_fw ) THEN                        ! Add wind forcing
+      !                                   !=  Add wind forcing  =!
+      !                                   !  ------------------  !
+      IF( ln_bt_fw ) THEN
          DO_2D( 0, 0, 0, 0 )
             zu_frc(ji,jj) =  zu_frc(ji,jj) + r1_rho0 * utau(ji,jj) * r1_hu(ji,jj,Kmm)
@@ -375,11 +375,11 @@
       !
       IF( ln_linssh ) THEN    ! mid-step ocean depth is fixed (hup2_e=hu_n=hu_0)
-         zhup2_e(:,:) = hu(:,:,Kmm)
-         zhvp2_e(:,:) = hv(:,:,Kmm)
-         zhtp2_e(:,:) = ht(:,:)
-      ENDIF
-      !
-      IF (ln_bt_fw) THEN                  ! FORWARD integration: start from NOW fields                    
-         sshn_e(:,:) =    pssh(:,:,Kmm)            
+         zhup2_e(:,:) = hu_0(:,:)
+         zhvp2_e(:,:) = hv_0(:,:)
+         zhtp2_e(:,:) = ht_0(:,:)
+      ENDIF
+      !
+      IF( ln_bt_fw ) THEN                 ! FORWARD integration: start from NOW fields                    
+         sshn_e(:,:) =    pssh (:,:,Kmm)            
          un_e  (:,:) =    puu_b(:,:,Kmm)            
          vn_e  (:,:) =    pvv_b(:,:,Kmm)
@@ -390,5 +390,5 @@
          hvr_e (:,:) = r1_hv(:,:,Kmm)
       ELSE                                ! CENTRED integration: start from BEFORE fields
-         sshn_e(:,:) =    pssh(:,:,Kbb)
+         sshn_e(:,:) =    pssh (:,:,Kbb)
          un_e  (:,:) =    puu_b(:,:,Kbb)         
          vn_e  (:,:) =    pvv_b(:,:,Kbb)
@@ -401,9 +401,9 @@
       !
       ! Initialize sums:
-      puu_b  (:,:,Kaa) = 0._wp       ! After barotropic velocities (or transport if flux form)          
-      pvv_b  (:,:,Kaa) = 0._wp
+      puu_b (:,:,Kaa) = 0._wp       ! After barotropic velocities (or transport if flux form)          
+      pvv_b (:,:,Kaa) = 0._wp
       pssh  (:,:,Kaa) = 0._wp       ! Sum for after averaged sea level
-      un_adv(:,:) = 0._wp       ! Sum for now transport issued from ts loop
-      vn_adv(:,:) = 0._wp
+      un_adv(:,:)     = 0._wp       ! Sum for now transport issued from ts loop
+      vn_adv(:,:)     = 0._wp
       !
       IF( ln_wd_dl ) THEN
@@ -464,4 +464,14 @@
             !
             !                          ! ocean u- and v-depth at mid-step   (separate DO-loops remove the need of a lbc_lnk)
+#if defined key_qcoTest_FluxForm
+            !                                ! 'key_qcoTest_FluxForm' : simple ssh average
+            DO_2D( 1, 1, 1, 0 )   ! not jpi-column
+               zhup2_e(ji,jj) = hu_0(ji,jj) + r1_2 * (  zsshp2_e(ji,jj) + zsshp2_e(ji+1,jj  )  ) * ssumask(ji,jj)
+            END_2D
+            DO_2D( 1, 0, 1, 1 )
+               zhvp2_e(ji,jj) = hv_0(ji,jj) + r1_2 * (  zsshp2_e(ji,jj) + zsshp2_e(ji  ,jj+1)  ) * ssvmask(ji,jj)
+            END_2D
+#else
+            !                                ! no 'key_qcoTest_FluxForm' : surface weighted ssh average
             DO_2D( 1, 1, 1, 0 )   ! not jpi-column
                zhup2_e(ji,jj) = hu_0(ji,jj) + r1_2 * r1_e1e2u(ji,jj)                        &
@@ -474,4 +484,5 @@
                     &                                 + e1e2t(ji,jj+1) * zsshp2_e(ji,jj+1)  ) * ssvmask(ji,jj)
             END_2D
+#endif               
             !
          ENDIF
@@ -529,14 +540,22 @@
          !  
          ! Sea Surface Height at u-,v-points (vvl case only)
-         IF( .NOT.ln_linssh ) THEN                                
+         IF( .NOT.ln_linssh ) THEN
+#if defined key_qcoTest_FluxForm
+            !                                ! 'key_qcoTest_FluxForm' : simple ssh average
+            DO_2D( 1, 1, 1, 0 )
+               zsshu_a(ji,jj) = r1_2 * (  ssha_e(ji,jj) + ssha_e(ji+1,jj  )  ) * ssumask(ji,jj)
+            END_2D
+            DO_2D( 1, 0, 1, 1 )
+               zsshv_a(ji,jj) = r1_2 * (  ssha_e(ji,jj) + ssha_e(ji  ,jj+1)  ) * ssvmask(ji,jj)
+            END_2D
+#else
             DO_2D( 0, 0, 0, 0 )
-               zsshu_a(ji,jj) = r1_2 * ssumask(ji,jj) * r1_e1e2u(ji,jj)    &
-                  &              * ( e1e2t(ji  ,jj  )  * ssha_e(ji  ,jj  ) &
-                  &              +   e1e2t(ji+1,jj  )  * ssha_e(ji+1,jj  ) )
-               zsshv_a(ji,jj) = r1_2 * ssvmask(ji,jj) * r1_e1e2v(ji,jj)    &
-                  &              * ( e1e2t(ji  ,jj  )  * ssha_e(ji  ,jj  ) &
-                  &              +   e1e2t(ji  ,jj+1)  * ssha_e(ji  ,jj+1) )
-            END_2D
-         ENDIF   
+               zsshu_a(ji,jj) = r1_2 * r1_e1e2u(ji,jj) * ( e1e2t(ji  ,jj  ) * ssha_e(ji  ,jj  )   &
+                  &                                      + e1e2t(ji+1,jj  ) * ssha_e(ji+1,jj  ) ) * ssumask(ji,jj)
+               zsshv_a(ji,jj) = r1_2 * r1_e1e2v(ji,jj) * ( e1e2t(ji  ,jj  ) * ssha_e(ji  ,jj  )   &
+                  &                                      + e1e2t(ji  ,jj+1) * ssha_e(ji  ,jj+1) ) * ssvmask(ji,jj)
+            END_2D
+#endif
+         ENDIF
          !         
          ! Half-step back interpolation of SSH for surface pressure computation at step jit+1/2
@@ -613,8 +632,14 @@
                !                    ! hu_e, hv_e hold depth at jn,  zhup2_e, zhvp2_e hold extrapolated depth at jn+1/2
                !                    ! backward interpolated depth used in spg terms at jn+1/2
+#if defined key_qcoTest_FluxForm
+            !                                ! 'key_qcoTest_FluxForm' : simple ssh average
+               zhu_bck = hu_0(ji,jj) + r1_2 * (  zsshp2_e(ji,jj) + zsshp2_e(ji+1,jj  )  ) * ssumask(ji,jj)
+               zhv_bck = hv_0(ji,jj) + r1_2 * (  zsshp2_e(ji,jj) + zsshp2_e(ji  ,jj+1)  ) * ssvmask(ji,jj)
+#else
                zhu_bck = hu_0(ji,jj) + r1_2*r1_e1e2u(ji,jj) * (  e1e2t(ji  ,jj) * zsshp2_e(ji  ,jj)    &
                     &                                          + e1e2t(ji+1,jj) * zsshp2_e(ji+1,jj)  ) * ssumask(ji,jj)
                zhv_bck = hv_0(ji,jj) + r1_2*r1_e1e2v(ji,jj) * (  e1e2t(ji,jj  ) * zsshp2_e(ji,jj  )    &
                     &                                          + e1e2t(ji,jj+1) * zsshp2_e(ji,jj+1)  ) * ssvmask(ji,jj)
+#endif
                !                    ! inverse depth at jn+1
                z1_hu = ssumask(ji,jj) / ( hu_0(ji,jj) + zsshu_a(ji,jj) + 1._wp - ssumask(ji,jj) )
@@ -635,14 +660,14 @@
          IF ( ll_wd ) THEN ! revert to explicit for bit comparison tests in non wad runs
             DO_2D( 0, 0, 0, 0 )
-                  ua_e(ji,jj) =  ua_e(ji,jj) /(1.0 -   rDt_e * zCdU_u(ji,jj) * hur_e(ji,jj))
-                  va_e(ji,jj) =  va_e(ji,jj) /(1.0 -   rDt_e * zCdU_v(ji,jj) * hvr_e(ji,jj))
+               ua_e(ji,jj) =  ua_e(ji,jj) / ( 1._wp - rDt_e * zCdU_u(ji,jj) * hur_e(ji,jj) )
+               va_e(ji,jj) =  va_e(ji,jj) / ( 1._wp - rDt_e * zCdU_v(ji,jj) * hvr_e(ji,jj) )
             END_2D
          ENDIF
        
          IF( .NOT.ln_linssh ) THEN !* Update ocean depth (variable volume case only)
-            hu_e (2:jpim1,2:jpjm1) = hu_0(2:jpim1,2:jpjm1) + zsshu_a(2:jpim1,2:jpjm1)
-            hur_e(2:jpim1,2:jpjm1) = ssumask(2:jpim1,2:jpjm1) / ( hu_e(2:jpim1,2:jpjm1) + 1._wp - ssumask(2:jpim1,2:jpjm1) )
-            hv_e (2:jpim1,2:jpjm1) = hv_0(2:jpim1,2:jpjm1) + zsshv_a(2:jpim1,2:jpjm1)
-            hvr_e(2:jpim1,2:jpjm1) = ssvmask(2:jpim1,2:jpjm1) / ( hv_e(2:jpim1,2:jpjm1) + 1._wp - ssvmask(2:jpim1,2:jpjm1) )
+            hu_e (2:jpim1,2:jpjm1) =    hu_0(2:jpim1,2:jpjm1) + zsshu_a(2:jpim1,2:jpjm1)
+            hur_e(2:jpim1,2:jpjm1) = ssumask(2:jpim1,2:jpjm1) / (  hu_e(2:jpim1,2:jpjm1) + 1._wp - ssumask(2:jpim1,2:jpjm1)  )
+            hv_e (2:jpim1,2:jpjm1) =    hv_0(2:jpim1,2:jpjm1) + zsshv_a(2:jpim1,2:jpjm1)
+            hvr_e(2:jpim1,2:jpjm1) = ssvmask(2:jpim1,2:jpjm1) / (  hv_e(2:jpim1,2:jpjm1) + 1._wp - ssvmask(2:jpim1,2:jpjm1)  )
          ENDIF
          !
@@ -732,17 +757,25 @@
       ELSE
          ! At this stage, pssh(:,:,:,Krhs) has been corrected: compute new depths at velocity points
+#if defined key_qcoTest_FluxForm
+         !                                ! 'key_qcoTest_FluxForm' : simple ssh average
          DO_2D( 1, 0, 1, 0 )
-            zsshu_a(ji,jj) = r1_2 * ssumask(ji,jj)  * r1_e1e2u(ji,jj) &
-               &              * ( e1e2t(ji  ,jj) * pssh(ji  ,jj,Kaa)      &
-               &              +   e1e2t(ji+1,jj) * pssh(ji+1,jj,Kaa) )
-            zsshv_a(ji,jj) = r1_2 * ssvmask(ji,jj)  * r1_e1e2v(ji,jj) &
-               &              * ( e1e2t(ji,jj  ) * pssh(ji,jj  ,Kaa)      &
-               &              +   e1e2t(ji,jj+1) * pssh(ji,jj+1,Kaa) )
-         END_2D
+            zsshu_a(ji,jj) = r1_2 * ( pssh(ji,jj,Kaa) + pssh(ji+1,jj  ,Kaa) ) * ssumask(ji,jj)
+            zsshv_a(ji,jj) = r1_2 * ( pssh(ji,jj,Kaa) + pssh(ji  ,jj+1,Kaa) ) * ssvmask(ji,jj)
+         END_2D
+#else
+         DO_2D( 1, 0, 1, 0 )
+            zsshu_a(ji,jj) = r1_2 * r1_e1e2u(ji,jj) * ( e1e2t(ji  ,jj) * pssh(ji  ,jj,Kaa)   &
+               &                                      + e1e2t(ji+1,jj) * pssh(ji+1,jj,Kaa) ) * ssumask(ji,jj)
+            zsshv_a(ji,jj) = r1_2 * r1_e1e2v(ji,jj) * ( e1e2t(ji,jj  ) * pssh(ji,jj  ,Kaa)   &
+               &                                      + e1e2t(ji,jj+1) * pssh(ji,jj+1,Kaa) ) * ssvmask(ji,jj)
+         END_2D
+#endif   
          CALL lbc_lnk_multi( 'dynspg_ts', zsshu_a, 'U', 1._wp, zsshv_a, 'V', 1._wp ) ! Boundary conditions
          !
          DO jk=1,jpkm1
-            puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + r1_hu(:,:,Kmm) * ( puu_b(:,:,Kaa) - puu_b(:,:,Kbb) * hu(:,:,Kbb) ) * r1_Dt_b
-            pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + r1_hv(:,:,Kmm) * ( pvv_b(:,:,Kaa) - pvv_b(:,:,Kbb) * hv(:,:,Kbb) ) * r1_Dt_b
+            puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + r1_hu(:,:,Kmm)   &
+               &             * ( puu_b(:,:,Kaa) - puu_b(:,:,Kbb) * hu(:,:,Kbb) ) * r1_Dt_b
+            pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + r1_hv(:,:,Kmm)   &
+               &             * ( pvv_b(:,:,Kaa) - pvv_b(:,:,Kbb) * hv(:,:,Kbb) ) * r1_Dt_b
          END DO
          ! Save barotropic velocities not transport:
@@ -888,5 +921,5 @@
       IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
          !                                   ! ---------------
-         IF( ln_rstart .AND. ln_bt_fw .AND. (.NOT.l_1st_euler) ) THEN    !* Read the restart file
+         IF( ln_rstart .AND. ln_bt_fw .AND. .NOT.l_1st_euler ) THEN    !* Read the restart file
             CALL iom_get( numror, jpdom_auto, 'ub2_b'  , ub2_b  (:,:), cd_type = 'U', psgn = -1._wp )   
             CALL iom_get( numror, jpdom_auto, 'vb2_b'  , vb2_b  (:,:), cd_type = 'V', psgn = -1._wp ) 
@@ -1049,5 +1082,5 @@
       !! although they should be updated in the variable volume case. Not a big approximation.
       !! To remove this approximation, copy lines below inside barotropic loop
-      !! and update depths at T-F points (ht and zhf resp.) at each barotropic time step
+      !! and update depths at T- points (ht) at each barotropic time step
       !!
       !! Compute zwz = f / ( height of the water colomn )
@@ -1056,28 +1089,31 @@
       INTEGER  ::   ji ,jj, jk              ! dummy loop indices
       REAL(wp) ::   z1_ht
-      REAL(wp), DIMENSION(jpi,jpj) :: zhf
       !!----------------------------------------------------------------------
       !
       SELECT CASE( nvor_scheme )
-      CASE( np_EEN )                != EEN scheme using e3f energy & enstrophy scheme
-         SELECT CASE( nn_een_e3f )              !* ff_f/e3 at F-point
+      CASE( np_EEN, np_ENE, np_ENS , np_MIX )   !=  schemes using the same e3f definition
+         SELECT CASE( nn_e3f_typ )                  !* ff_f/e3 at F-point
          CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) =   ( ht(ji  ,jj+1) + ht(ji+1,jj+1) +                    &
-                    &           ht(ji  ,jj  ) + ht(ji+1,jj  )   ) * 0.25_wp  
+            DO_2D( 0, 0, 0, 0 )
+               zwz(ji,jj) = ( ht(ji,jj+1) + ht(ji+1,jj+1)   &
+                    &       + ht(ji,jj  ) + ht(ji+1,jj  ) ) * 0.25_wp  
                IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff_f(ji,jj) / zwz(ji,jj)
             END_2D
          CASE ( 1 )                                   ! new formulation  (masked averaging of e3t divided by the sum of mask)
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) =             (  ht  (ji  ,jj+1) + ht  (ji+1,jj+1)      &
-                    &                    + ht  (ji  ,jj  ) + ht  (ji+1,jj  )  )   &
-                    &       / ( MAX( 1._wp,  ssmask(ji  ,jj+1) + ssmask(ji+1,jj+1)      &
-                    &                      + ssmask(ji  ,jj  ) + ssmask(ji+1,jj  )  )   )
+            DO_2D( 0, 0, 0, 0 )
+               zwz(ji,jj) =     (    ht(ji,jj+1) +     ht(ji+1,jj+1)      &
+                    &            +   ht(ji,jj  ) +     ht(ji+1,jj  )  )   &
+                    &    / ( MAX(ssmask(ji,jj+1) + ssmask(ji+1,jj+1)      &
+                    &          + ssmask(ji,jj  ) + ssmask(ji+1,jj  ) , 1._wp  )   )
                IF( zwz(ji,jj) /= 0._wp )   zwz(ji,jj) = ff_f(ji,jj) / zwz(ji,jj)
             END_2D
          END SELECT
          CALL lbc_lnk( 'dynspg_ts', zwz, 'F', 1._wp )
-         !
-         ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
+      END SELECT
+      !
+      SELECT CASE( nvor_scheme )
+      CASE( np_EEN )
+         !
+         ftne(1,:) = 0._wp   ;   ftnw(1,:) = 0._wp   ;   ftse(1,:) = 0._wp   ;   ftsw(1,:) = 0._wp
          DO_2D( 0, 1, 0, 1 )
             ftne(ji,jj) = zwz(ji-1,jj  ) + zwz(ji  ,jj  ) + zwz(ji  ,jj-1)
@@ -1087,6 +1123,6 @@
          END_2D
          !
-      CASE( np_EET )                  != EEN scheme using e3t energy conserving scheme
-         ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
+      CASE( np_EET )                            != EEN scheme using e3t energy conserving scheme
+         ftne(1,:) = 0._wp   ;   ftnw(1,:) = 0._wp   ;   ftse(1,:) = 0._wp   ;   ftsw(1,:) = 0._wp
          DO_2D( 0, 1, 0, 1 )
             z1_ht = ssmask(ji,jj) / ( ht(ji,jj) + 1._wp - ssmask(ji,jj) )
@@ -1097,56 +1133,7 @@
          END_2D
          !
-      CASE( np_ENE, np_ENS , np_MIX )  != all other schemes (ENE, ENS, MIX) except ENT !
-         !
-         zwz(:,:) = 0._wp
-         zhf(:,:) = 0._wp
-         
-         !!gm  assume 0 in both cases (which is almost surely WRONG ! ) as hvatf has been removed 
-!!gm    A priori a better value should be something like :
-!!gm          zhf(i,j) = masked sum of  ht(i,j) , ht(i+1,j) , ht(i,j+1) , (i+1,j+1) 
-!!gm                     divided by the sum of the corresponding mask 
-!!gm 
-!!            
-         IF( .NOT.ln_sco ) THEN
-  
-   !!gm  agree the JC comment  : this should be done in a much clear way
-  
-   ! JC: It not clear yet what should be the depth at f-points over land in z-coordinate case
-   !     Set it to zero for the time being 
-   !              IF( rn_hmin < 0._wp ) THEN    ;   jk = - INT( rn_hmin )                                      ! from a nb of level
-   !              ELSE                          ;   jk = MINLOC( gdepw_0, mask = gdepw_0 > rn_hmin, dim = 1 )  ! from a depth
-   !              ENDIF
-   !              zhf(:,:) = gdepw_0(:,:,jk+1)
-            !
-         ELSE
-            !
-            !zhf(:,:) = hbatf(:,:)
-            DO_2D( 1, 0, 1, 0 )
-               zhf(ji,jj) =    (   ht_0  (ji,jj  ) + ht_0  (ji+1,jj  )          &
-                    &            + ht_0  (ji,jj+1) + ht_0  (ji+1,jj+1)   )      &
-                    &     / MAX(   ssmask(ji,jj  ) + ssmask(ji+1,jj  )          &
-                    &            + ssmask(ji,jj+1) + ssmask(ji+1,jj+1) , 1._wp  )
-            END_2D
-         ENDIF
-         !
-         DO jj = 1, jpjm1
-            zhf(:,jj) = zhf(:,jj) * (1._wp- umask(:,jj,1) * umask(:,jj+1,1))
-         END DO
-         !
-         DO jk = 1, jpkm1
-            DO jj = 1, jpjm1
-               zhf(:,jj) = zhf(:,jj) + e3f(:,jj,jk) * umask(:,jj,jk) * umask(:,jj+1,jk)
-            END DO
-         END DO
-         CALL lbc_lnk( 'dynspg_ts', zhf, 'F', 1._wp )
-         ! JC: TBC. hf should be greater than 0 
-         DO_2D( 1, 1, 1, 1 )
-            IF( zhf(ji,jj) /= 0._wp )   zwz(ji,jj) = 1._wp / zhf(ji,jj)
-         END_2D
-         zwz(:,:) = ff_f(:,:) * zwz(:,:)
       END SELECT
       
    END SUBROUTINE dyn_cor_2d_init
-
 
 
@@ -1342,5 +1329,4 @@
    END SUBROUTINE wad_spg
      
-
 
    SUBROUTINE dyn_drg_init( Kbb, Kmm, puu, pvv, puu_b ,pvv_b, pu_RHSi, pv_RHSi, pCdU_u, pCdU_v )
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynvor.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynvor.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/dynvor.F90	(revision 14062)
@@ -21,4 +21,5 @@
    !!             -   ! 2018-03  (G. Madec)  add two new schemes (ln_dynvor_enT and ln_dynvor_eet)
    !!             -   ! 2018-04  (G. Madec)  add pre-computed gradient for metric term calculation
+   !!            4.x  ! 2020-03  (G. Madec, A. Nasser)  make ln_dynvor_msk truly efficient on relative vorticity
    !!            4.2  ! 2020-12  (G. Madec, E. Clementi) add vortex force trends (ln_vortex_force=T)
    !!----------------------------------------------------------------------
@@ -26,7 +27,9 @@
    !!----------------------------------------------------------------------
    !!   dyn_vor       : Update the momentum trend with the vorticity trend
+   !!       vor_enT   : energy conserving scheme at T-pt  (ln_dynvor_enT=T)
+   !!       vor_ene   : energy conserving scheme          (ln_dynvor_ene=T)
    !!       vor_ens   : enstrophy conserving scheme       (ln_dynvor_ens=T)
-   !!       vor_ene   : energy conserving scheme          (ln_dynvor_ene=T)
    !!       vor_een   : energy and enstrophy conserving   (ln_dynvor_een=T)
+   !!       vor_eeT   : energy conserving at T-pt         (ln_dynvor_eeT=T)
    !!   dyn_vor_init  : set and control of the different vorticity option
    !!----------------------------------------------------------------------
@@ -58,7 +61,7 @@
    LOGICAL, PUBLIC ::   ln_dynvor_eeT   !: t-point energy conserving scheme     (EET)
    LOGICAL, PUBLIC ::   ln_dynvor_een   !: energy & enstrophy conserving scheme (EEN)
-   INTEGER, PUBLIC ::      nn_een_e3f      !: e3f=masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
    LOGICAL, PUBLIC ::   ln_dynvor_mix   !: mixed scheme                         (MIX)
    LOGICAL, PUBLIC ::   ln_dynvor_msk   !: vorticity multiplied by fmask (=T) or not (=F) (all vorticity schemes)
+   INTEGER, PUBLIC ::   nn_e3f_typ      !: e3f=masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 
    INTEGER, PUBLIC ::   nvor_scheme     !: choice of the type of advection scheme
@@ -81,6 +84,8 @@
    REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   di_e2u_2        ! = di(e2u)/2          used in T-point metric term calculation
    REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   dj_e1v_2        ! = dj(e1v)/2           -        -      -       - 
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   di_e2v_2e1e2f   ! = di(e2v)/(2*e1e2f)  used in F-point metric term calculation
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   dj_e1u_2e1e2f   ! = dj(e1u)/(2*e1e2f)   -        -      -       - 
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   di_e2v_2e1e2f   ! = di(e2u)/(2*e1e2f)  used in F-point metric term calculation
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   dj_e1u_2e1e2f   ! = dj(e1v)/(2*e1e2f)   -        -      -       -
+   !
+   REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   e3f_0vor   ! e3f used in EEN, ENE and ENS cases (key_qco only)
    
    REAL(wp) ::   r1_4  = 0.250_wp         ! =1/4
@@ -235,6 +240,6 @@
       INTEGER  ::   ji, jj, jk           ! dummy loop indices
       REAL(wp) ::   zx1, zy1, zx2, zy2   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj)       ::   zwx, zwy, zwt   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpkm1) ::   zwz             ! 3D workspace, jpkm1 -> avoid lbc_lnk on jpk that is not defined
+      REAL(wp), DIMENSION(jpi,jpj)     ::   zwx, zwy, zwt   ! 2D workspace
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zwz      ! 3D workspace, jpkm1 -> avoid lbc_lnk on jpk that is not defined
       !!----------------------------------------------------------------------
       !
@@ -246,12 +251,14 @@
       !
       !
-      SELECT CASE( kvor )                 !==  volume weighted vorticity considered  ==!
-      CASE ( np_RVO )                           !* relative vorticity
-         DO jk = 1, jpkm1                                 ! Horizontal slab
+      SELECT CASE( kvor )                 !== relative vorticity considered  ==!
+      !
+      CASE ( np_RVO , np_CRV )                  !* relative vorticity at f-point is used
+         ALLOCATE( zwz(jpi,jpj,jpk) )
+         DO jk = 1, jpkm1                                ! Horizontal slab
             DO_2D( 1, 0, 1, 0 )
                zwz(ji,jj,jk) = (  e2v(ji+1,jj) * pv(ji+1,jj,jk) - e2v(ji,jj) * pv(ji,jj,jk)  &
                   &             - e1u(ji,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
             END_2D
-            IF( ln_dynvor_msk ) THEN                     ! mask/unmask relative vorticity 
+            IF( ln_dynvor_msk ) THEN                     ! mask relative vorticity 
                DO_2D( 1, 0, 1, 0 )
                   zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
@@ -259,58 +266,43 @@
             ENDIF
          END DO
-
          CALL lbc_lnk( 'dynvor', zwz, 'F', 1.0_wp )
-
-      CASE ( np_CRV )                           !* Coriolis + relative vorticity
-         DO jk = 1, jpkm1                                 ! Horizontal slab
-            DO_2D( 1, 0, 1, 0 )                          ! relative vorticity
-               zwz(ji,jj,jk) = (   e2v(ji+1,jj) * pv(ji+1,jj,jk) - e2v(ji,jj) * pv(ji,jj,jk)   &
-                  &              - e1u(ji,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)   ) * r1_e1e2f(ji,jj)
-            END_2D
-            IF( ln_dynvor_msk ) THEN                     ! mask/unmask relative vorticity 
-               DO_2D( 1, 0, 1, 0 )
-                  zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
-               END_2D
-            ENDIF
-         END DO
-
-         CALL lbc_lnk( 'dynvor', zwz, 'F', 1.0_wp )
-
+         !
       END SELECT
 
       !                                                ! ===============
       DO jk = 1, jpkm1                                 ! Horizontal slab
-      !                                                ! ===============
-
+         !                                             ! ===============
+         !
          SELECT CASE( kvor )                 !==  volume weighted vorticity considered  ==!
+         !
          CASE ( np_COR )                           !* Coriolis (planetary vorticity)
             zwt(:,:) = ff_t(:,:) * e1e2t(:,:)*e3t(:,:,jk,Kmm)
          CASE ( np_RVO )                           !* relative vorticity
             DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = r1_4 * (   zwz(ji-1,jj  ,jk) + zwz(ji,jj  ,jk)   &
-                  &                  + zwz(ji-1,jj-1,jk) + zwz(ji,jj-1,jk) ) &
-                  &                  * e1e2t(ji,jj)*e3t(ji,jj,jk,Kmm)
+               zwt(ji,jj) = r1_4 * (   zwz(ji-1,jj  ,jk) + zwz(ji,jj  ,jk)       &
+                  &                  + zwz(ji-1,jj-1,jk) + zwz(ji,jj-1,jk)   )   &
+                  &              * e1e2t(ji,jj)*e3t(ji,jj,jk,Kmm)
             END_2D
          CASE ( np_MET )                           !* metric term
             DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = (   ( pv(ji,jj,jk) + pv(ji,jj-1,jk) ) * di_e2u_2(ji,jj)   &
-                  &           - ( pu(ji,jj,jk) + pu(ji-1,jj,jk) ) * dj_e1v_2(ji,jj)   ) &
-                  &             * e3t(ji,jj,jk,Kmm)
+               zwt(ji,jj) = (   ( pv(ji,jj,jk) + pv(ji,jj-1,jk) ) * di_e2u_2(ji,jj)       &
+                  &           - ( pu(ji,jj,jk) + pu(ji-1,jj,jk) ) * dj_e1v_2(ji,jj)   )   &
+                  &       * e3t(ji,jj,jk,Kmm)
             END_2D
          CASE ( np_CRV )                           !* Coriolis + relative vorticity
             DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = (  ff_t(ji,jj) + r1_4 * ( zwz(ji-1,jj  ,jk) + zwz(ji,jj  ,jk)    &
-                  &                                 + zwz(ji-1,jj-1,jk) + zwz(ji,jj-1,jk) )  ) &
-                  &                                 * e1e2t(ji,jj)*e3t(ji,jj,jk,Kmm)
+               zwt(ji,jj) = (  ff_t(ji,jj) + r1_4 * ( zwz(ji-1,jj  ,jk) + zwz(ji,jj  ,jk)        &
+                  &                                 + zwz(ji-1,jj-1,jk) + zwz(ji,jj-1,jk) )  )   &
+                  &       * e1e2t(ji,jj)*e3t(ji,jj,jk,Kmm)
             END_2D
          CASE ( np_CME )                           !* Coriolis + metric
             DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = (  ff_t(ji,jj) * e1e2t(ji,jj)                           &
-                    &        + ( pv(ji,jj,jk) + pv(ji,jj-1,jk) ) * di_e2u_2(ji,jj)  &
-                    &        - ( pu(ji,jj,jk) + pu(ji-1,jj,jk) ) * dj_e1v_2(ji,jj)  ) &
-                    &          * e3t(ji,jj,jk,Kmm)
+               zwt(ji,jj) = (  ff_t(ji,jj) * e1e2t(ji,jj)                               &
+                    &        + ( pv(ji,jj,jk) + pv(ji,jj-1,jk) ) * di_e2u_2(ji,jj)      &
+                    &        - ( pu(ji,jj,jk) + pu(ji-1,jj,jk) ) * dj_e1v_2(ji,jj)  )   &
+                    &     * e3t(ji,jj,jk,Kmm)
             END_2D
          CASE DEFAULT                                             ! error
-            CALL ctl_stop('STOP','dyn_vor: wrong value for kvor'  )
+            CALL ctl_stop('STOP','dyn_vor: wrong value for kvor')
          END SELECT
          !
@@ -328,4 +320,9 @@
       END DO                                           !   End of slab
       !                                                ! ===============
+      !
+      SELECT CASE( kvor )        ! deallocate zwz if necessary
+      CASE ( np_RVO , np_CRV )   ;   DEALLOCATE( zwz )
+      END SELECT
+      !
    END SUBROUTINE vor_enT
 
@@ -358,5 +355,5 @@
       !
       INTEGER  ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   zx1, zy1, zx2, zy2   ! local scalars
+      REAL(wp) ::   zx1, zy1, zx2, zy2, ze3f, zmsk   ! local scalars
       REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! 2D workspace
       !!----------------------------------------------------------------------
@@ -380,4 +377,9 @@
                   &          - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj) = zwz(ji,jj) * fmask(ji,jj,jk)
+               END_2D
+            ENDIF
          CASE ( np_MET )                           !* metric term
             DO_2D( 1, 0, 1, 0 )
@@ -390,4 +392,9 @@
                   &                        - e1u(ji,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity (NOT the Coriolis term)
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj) = ( zwz(ji,jj) - ff_f(ji,jj) ) * fmask(ji,jj,jk) + ff_f(ji,jj)
+               END_2D
+            ENDIF
          CASE ( np_CME )                           !* Coriolis + metric
             DO_2D( 1, 0, 1, 0 )
@@ -399,18 +406,38 @@
          END SELECT
          !
-         IF( ln_dynvor_msk ) THEN          !==  mask/unmask vorticity ==!
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = zwz(ji,jj) * fmask(ji,jj,jk)
-            END_2D
-         ENDIF
-
-         IF( ln_sco ) THEN
-            zwz(:,:) = zwz(:,:) / e3f(:,:,jk)
-            zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
-            zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-         ELSE
-            zwx(:,:) = e2u(:,:) * pu(:,:,jk)
-            zwy(:,:) = e1v(:,:) * pv(:,:,jk)
-         ENDIF
+#if defined key_qco
+         DO_2D( 1, 0, 1, 0 )                 !==  potential vorticity  ==!   (key_qco)
+            zwz(ji,jj) = zwz(ji,jj) / e3f_vor(ji,jj,jk)
+         END_2D
+#else
+         SELECT CASE( nn_e3f_typ  )           !==  potential vorticity  ==!
+         CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
+            DO_2D( 1, 0, 1, 0 )
+               ze3f = (  e3t(ji  ,jj+1,jk,Kmm)*tmask(ji  ,jj+1,jk)   &
+                  &    + e3t(ji+1,jj+1,jk,Kmm)*tmask(ji+1,jj+1,jk)   &
+                  &    + e3t(ji  ,jj  ,jk,Kmm)*tmask(ji  ,jj  ,jk)   &
+                  &    + e3t(ji+1,jj  ,jk,Kmm)*tmask(ji+1,jj  ,jk)  )
+               IF( ze3f /= 0._wp ) THEN   ;   zwz(ji,jj) = zwz(ji,jj) * 4._wp / ze3f
+               ELSE                       ;   zwz(ji,jj) = 0._wp
+               ENDIF
+            END_2D
+         CASE ( 1 )                                   ! new formulation  (masked averaging of e3t divided by the sum of mask)
+            DO_2D( 1, 0, 1, 0 )
+               ze3f = (   e3t(ji  ,jj+1,jk,Kmm)*tmask(ji  ,jj+1,jk)   &
+                  &     + e3t(ji+1,jj+1,jk,Kmm)*tmask(ji+1,jj+1,jk)   &
+                  &     + e3t(ji  ,jj  ,jk,Kmm)*tmask(ji  ,jj  ,jk)   &
+                  &     + e3t(ji+1,jj  ,jk,Kmm)*tmask(ji+1,jj  ,jk)   )
+               zmsk = (   tmask(ji,jj+1,jk)   + tmask(ji+1,jj+1,jk)   &
+                  &     + tmask(ji,jj  ,jk)   + tmask(ji+1,jj  ,jk)   )
+               IF( ze3f /= 0._wp ) THEN   ;   zwz(ji,jj) = zwz(ji,jj) * zmsk / ze3f
+               ELSE                       ;   zwz(ji,jj) = 0._wp
+               ENDIF
+            END_2D
+         END SELECT
+#endif
+         !                                   !==  horizontal fluxes  ==!
+         zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
+         zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
+         !
          !                                   !==  compute and add the vorticity term trend  =!
          DO_2D( 0, 0, 0, 0 )
@@ -455,5 +482,5 @@
       !
       INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zuav, zvau   ! local scalars
+      REAL(wp) ::   zuav, zvau, ze3f, zmsk   ! local scalars
       REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz, zww   ! 2D workspace
       !!----------------------------------------------------------------------
@@ -476,4 +503,9 @@
                   &          - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj) = zwz(ji,jj) * fmask(ji,jj,jk)
+               END_2D
+            ENDIF
          CASE ( np_MET )                           !* metric term
             DO_2D( 1, 0, 1, 0 )
@@ -486,4 +518,9 @@
                   &                        - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity (NOT the Coriolis term)
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj) = ( zwz(ji,jj) - ff_f(ji,jj) ) * fmask(ji,jj,jk) + ff_f(ji,jj)
+               END_2D
+            ENDIF
          CASE ( np_CME )                           !* Coriolis + metric
             DO_2D( 1, 0, 1, 0 )
@@ -495,18 +532,39 @@
          END SELECT
          !
-         IF( ln_dynvor_msk ) THEN           !==  mask/unmask vorticity ==!
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = zwz(ji,jj) * fmask(ji,jj,jk)
-            END_2D
-         ENDIF
-         !
-         IF( ln_sco ) THEN                   !==  horizontal fluxes  ==!
-            zwz(:,:) = zwz(:,:) / e3f(:,:,jk)
-            zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
-            zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-         ELSE
-            zwx(:,:) = e2u(:,:) * pu(:,:,jk)
-            zwy(:,:) = e1v(:,:) * pv(:,:,jk)
-         ENDIF
+         !
+#if defined key_qco
+         DO_2D( 1, 0, 1, 0 )                 !==  potential vorticity  ==!   (key_qco)
+            zwz(ji,jj) = zwz(ji,jj) / e3f_vor(ji,jj,jk)
+         END_2D
+#else
+         SELECT CASE( nn_e3f_typ )           !==  potential vorticity  ==!
+         CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
+            DO_2D( 1, 0, 1, 0 )
+               ze3f = (  e3t(ji  ,jj+1,jk,Kmm)*tmask(ji  ,jj+1,jk)   &
+                  &    + e3t(ji+1,jj+1,jk,Kmm)*tmask(ji+1,jj+1,jk)   &
+                  &    + e3t(ji  ,jj  ,jk,Kmm)*tmask(ji  ,jj  ,jk)   &
+                  &    + e3t(ji+1,jj  ,jk,Kmm)*tmask(ji+1,jj  ,jk)  )
+               IF( ze3f /= 0._wp ) THEN   ;   zwz(ji,jj) = zwz(ji,jj) * 4._wp / ze3f
+               ELSE                       ;   zwz(ji,jj) = 0._wp
+               ENDIF
+            END_2D
+         CASE ( 1 )                                   ! new formulation  (masked averaging of e3t divided by the sum of mask)
+            DO_2D( 1, 0, 1, 0 )
+               ze3f = (   e3t(ji  ,jj+1,jk,Kmm)*tmask(ji  ,jj+1,jk)   &
+                  &     + e3t(ji+1,jj+1,jk,Kmm)*tmask(ji+1,jj+1,jk)   &
+                  &     + e3t(ji  ,jj  ,jk,Kmm)*tmask(ji  ,jj  ,jk)   &
+                  &     + e3t(ji+1,jj  ,jk,Kmm)*tmask(ji+1,jj  ,jk)   )
+               zmsk = (   tmask(ji,jj+1,jk)   + tmask(ji+1,jj+1,jk)   &
+                  &     + tmask(ji,jj  ,jk)   + tmask(ji+1,jj  ,jk)   )
+               IF( ze3f /= 0._wp ) THEN   ;   zwz(ji,jj) = zwz(ji,jj) * zmsk / ze3f
+               ELSE                       ;   zwz(ji,jj) = 0._wp
+               ENDIF
+            END_2D
+         END SELECT
+#endif
+         !                                   !==  horizontal fluxes  ==!
+         zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
+         zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
+         !
          !                                   !==  compute and add the vorticity term trend  =!
          DO_2D( 0, 0, 0, 0 )
@@ -566,5 +624,10 @@
          !                                             ! ===============
          !
-         SELECT CASE( nn_een_e3f )           ! == reciprocal of e3 at F-point
+#if defined key_qco
+         DO_2D( 1, 0, 1, 0 )                 ! == reciprocal of e3 at F-point (key_qco)
+            z1_e3f(ji,jj) = 1._wp / e3f_vor(ji,jj,jk)
+         END_2D
+#else
+         SELECT CASE( nn_e3f_typ )           ! == reciprocal of e3 at F-point
          CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
             DO_2D( 1, 0, 1, 0 )
@@ -590,6 +653,8 @@
             END_2D
          END SELECT
+#endif
          !
          SELECT CASE( kvor )                 !==  vorticity considered  ==!
+         !
          CASE ( np_COR )                           !* Coriolis (planetary vorticity)
             DO_2D( 1, 0, 1, 0 )
@@ -601,4 +666,9 @@
                   &            - e1u(ji  ,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)*z1_e3f(ji,jj)
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
+               END_2D
+            ENDIF
          CASE ( np_MET )                           !* metric term
             DO_2D( 1, 0, 1, 0 )
@@ -612,4 +682,9 @@
                   &                           * r1_e1e2f(ji,jj)   ) * z1_e3f(ji,jj)
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj,jk) = ( zwz(ji,jj,jk) - ff_f(ji,jj) ) * fmask(ji,jj,jk) + ff_f(ji,jj) 
+               END_2D
+            ENDIF
          CASE ( np_CME )                           !* Coriolis + metric
             DO_2D( 1, 0, 1, 0 )
@@ -620,37 +695,26 @@
             CALL ctl_stop('STOP','dyn_vor: wrong value for kvor'  )
          END SELECT
-         !
-         IF( ln_dynvor_msk ) THEN          !==  mask/unmask vorticity ==!
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
-            END_2D
-         ENDIF
+         !                                             ! ===============
       END DO                                           !   End of slab
-         !
+      !                                                ! ===============
+      !
       CALL lbc_lnk( 'dynvor', zwz, 'F', 1.0_wp )
-
+      !
+      !                                                ! ===============
       DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
          !
          !                                   !==  horizontal fluxes  ==!
          zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
          zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-
+         !
          !                                   !==  compute and add the vorticity term trend  =!
-         jj = 2
-         ztne(1,:) = 0   ;   ztnw(1,:) = 0   ;   ztse(1,:) = 0   ;   ztsw(1,:) = 0
-         DO ji = 2, jpi          ! split in 2 parts due to vector opt.
-               ztne(ji,jj) = zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk)
-               ztnw(ji,jj) = zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk)
-               ztse(ji,jj) = zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk)
-               ztsw(ji,jj) = zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk)
-         END DO
-         DO jj = 3, jpj
-            DO ji = 2, jpi   ! vector opt. ok because we start at jj = 3
-               ztne(ji,jj) = zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk)
-               ztnw(ji,jj) = zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk)
-               ztse(ji,jj) = zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk)
-               ztsw(ji,jj) = zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk)
-            END DO
-         END DO
+         DO_2D( 0, 1, 0, 1 )
+            ztne(ji,jj) = zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk)
+            ztnw(ji,jj) = zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk)
+            ztse(ji,jj) = zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk)
+            ztsw(ji,jj) = zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk)
+         END_2D
+         !
          DO_2D( 0, 0, 0, 0 )
             zua = + r1_12 * r1_e1u(ji,jj) * (  ztne(ji,jj  ) * zwy(ji  ,jj  ) + ztnw(ji+1,jj) * zwy(ji+1,jj  )   &
@@ -667,5 +731,4 @@
 
 
-
    SUBROUTINE vor_eeT( kt, Kmm, kvor, pu, pv, pu_rhs, pv_rhs )
       !!----------------------------------------------------------------------
@@ -685,9 +748,9 @@
       !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
       !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
+      INTEGER                         , INTENT(in   ) ::   kt               ! ocean time-step index
       INTEGER                         , INTENT(in   ) ::   Kmm              ! ocean time level index
-      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu, pv    ! now velocities
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs    ! total v-trend
+      INTEGER                         , INTENT(in   ) ::   kvor             ! total, planetary, relative, or metric
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu, pv           ! now velocities
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs   ! total v-trend
       !
       INTEGER  ::   ji, jj, jk     ! dummy loop indices
@@ -702,5 +765,5 @@
       IF( kt == nit000 ) THEN
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:vor_een : vorticity term: energy and enstrophy conserving scheme'
+         IF(lwp) WRITE(numout,*) 'dyn:vor_eeT : vorticity term: energy and enstrophy conserving scheme'
          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
       ENDIF
@@ -722,4 +785,9 @@
                   &          * r1_e1e2f(ji,jj)
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
+               END_2D
+            ENDIF
          CASE ( np_MET )                           !* metric term
             DO_2D( 1, 0, 1, 0 )
@@ -733,4 +801,9 @@
                   &                         * r1_e1e2f(ji,jj)    )
             END_2D
+            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
+               DO_2D( 1, 0, 1, 0 )
+                  zwz(ji,jj,jk) = ( zwz(ji,jj,jk) - ff_f(ji,jj) ) * fmask(ji,jj,jk) + ff_f(ji,jj) 
+               END_2D
+            ENDIF
          CASE ( np_CME )                           !* Coriolis + metric
             DO_2D( 1, 0, 1, 0 )
@@ -742,38 +815,27 @@
          END SELECT
          !
-         IF( ln_dynvor_msk ) THEN          !==  mask/unmask vorticity ==!
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
-            END_2D
-         ENDIF
-      END DO
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
       !
       CALL lbc_lnk( 'dynvor', zwz, 'F', 1.0_wp )
       !
+      !                                                ! ===============
       DO jk = 1, jpkm1                                 ! Horizontal slab
-
-      !                                   !==  horizontal fluxes  ==!
+         !                                             ! ===============
+         !
+         !                                   !==  horizontal fluxes  ==!
          zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
          zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-
+         !
          !                                   !==  compute and add the vorticity term trend  =!
-         jj = 2
-         ztne(1,:) = 0   ;   ztnw(1,:) = 0   ;   ztse(1,:) = 0   ;   ztsw(1,:) = 0
-         DO ji = 2, jpi          ! split in 2 parts due to vector opt.
-               z1_e3t = 1._wp / e3t(ji,jj,jk,Kmm)
-               ztne(ji,jj) = ( zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) ) * z1_e3t
-               ztnw(ji,jj) = ( zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) ) * z1_e3t
-               ztse(ji,jj) = ( zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) ) * z1_e3t
-               ztsw(ji,jj) = ( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) ) * z1_e3t
-         END DO
-         DO jj = 3, jpj
-            DO ji = 2, jpi   ! vector opt. ok because we start at jj = 3
-               z1_e3t = 1._wp / e3t(ji,jj,jk,Kmm)
-               ztne(ji,jj) = ( zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) ) * z1_e3t
-               ztnw(ji,jj) = ( zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) ) * z1_e3t
-               ztse(ji,jj) = ( zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) ) * z1_e3t
-               ztsw(ji,jj) = ( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) ) * z1_e3t
-            END DO
-         END DO
+         DO_2D( 0, 1, 0, 1 )
+            z1_e3t = 1._wp / e3t(ji,jj,jk,Kmm)
+            ztne(ji,jj) = ( zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) ) * z1_e3t
+            ztnw(ji,jj) = ( zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) ) * z1_e3t
+            ztse(ji,jj) = ( zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) ) * z1_e3t
+            ztsw(ji,jj) = ( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) ) * z1_e3t
+         END_2D
+         !
          DO_2D( 0, 0, 0, 0 )
             zua = + r1_12 * r1_e1u(ji,jj) * (  ztne(ji,jj  ) * zwy(ji  ,jj  ) + ztnw(ji+1,jj) * zwy(ji+1,jj  )   &
@@ -799,7 +861,8 @@
       INTEGER ::   ji, jj, jk    ! dummy loop indices
       INTEGER ::   ioptio, ios   ! local integer
+      REAL(wp) ::   zmsk    ! local scalars
       !!
       NAMELIST/namdyn_vor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_enT, ln_dynvor_eeT,   &
-         &                 ln_dynvor_een, nn_een_e3f   , ln_dynvor_mix, ln_dynvor_msk
+         &                 ln_dynvor_een, nn_e3f_typ   , ln_dynvor_mix, ln_dynvor_msk
       !!----------------------------------------------------------------------
       !
@@ -823,10 +886,8 @@
          WRITE(numout,*) '      energy conserving scheme  (een using e3t)      ln_dynvor_eeT = ', ln_dynvor_eeT
          WRITE(numout,*) '      enstrophy and energy conserving scheme         ln_dynvor_een = ', ln_dynvor_een
-         WRITE(numout,*) '         e3f = averaging /4 (=0) or /sum(tmask) (=1)    nn_een_e3f = ', nn_een_e3f
+         WRITE(numout,*) '         e3f = averaging /4 (=0) or /sum(tmask) (=1)    nn_e3f_typ = ', nn_e3f_typ
          WRITE(numout,*) '      mixed enstrophy/energy conserving scheme       ln_dynvor_mix = ', ln_dynvor_mix
          WRITE(numout,*) '      masked (=T) or unmasked(=F) vorticity          ln_dynvor_msk = ', ln_dynvor_msk
       ENDIF
-
-      IF( ln_dynvor_msk )   CALL ctl_stop( 'dyn_vor_init:   masked vorticity is not currently not available')
 
 !!gm  this should be removed when choosing a unique strategy for fmask at the coast
@@ -891,5 +952,39 @@
          !
       END SELECT
-      
+#if defined key_qco
+      SELECT CASE( nvor_scheme )    ! qco case: pre-computed a specific e3f_0 for some vorticity schemes
+      CASE( np_ENS , np_ENE , np_EEN , np_MIX )
+         !
+         ALLOCATE( e3f_0vor(jpi,jpj,jpk) )
+         !
+         SELECT CASE( nn_e3f_typ )
+         CASE ( 0 )                        ! original formulation  (masked averaging of e3t divided by 4)
+            DO_3D( 0, 0, 0, 0, 1, jpk )
+               e3f_0vor(ji,jj,jk) = (   e3t_0(ji  ,jj+1,jk)*tmask(ji  ,jj+1,jk)   &
+                  &                   + e3t_0(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                  &                   + e3t_0(ji  ,jj  ,jk)*tmask(ji  ,jj  ,jk)   &
+                  &                   + e3t_0(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk)   ) * 0.25_wp
+            END_3D
+         CASE ( 1 )                        ! new formulation  (masked averaging of e3t divided by the sum of mask)
+            DO_3D( 0, 0, 0, 0, 1, jpk )
+               zmsk = (tmask(ji,jj+1,jk) +tmask(ji+1,jj+1,jk)   &
+                  &  + tmask(ji,jj  ,jk) +tmask(ji+1,jj  ,jk)  )
+               !
+               IF( zmsk /= 0._wp ) THEN 
+                  e3f_0vor(ji,jj,jk) = (   e3t_0(ji  ,jj+1,jk)*tmask(ji  ,jj+1,jk)   &
+                     &                   + e3t_0(ji+1,jj+1,jk)*tmask(ji+1,jj+1,jk)   &
+                     &                   + e3t_0(ji  ,jj  ,jk)*tmask(ji  ,jj  ,jk)   &
+                     &                   + e3t_0(ji+1,jj  ,jk)*tmask(ji+1,jj  ,jk)   ) / zmsk
+               ENDIF
+            END_3D
+         END SELECT
+         !
+         CALL lbc_lnk( 'dynvor', e3f_0vor, 'F', 1._wp )
+         !                                 ! insure e3f_0vor /= 0
+         WHERE( e3f_0vor(:,:,:) == 0._wp )   e3f_0vor(:,:,:) = e3f_0(:,:,:)
+         !
+      END SELECT
+      !
+#endif
       IF(lwp) THEN                   ! Print the choice
          WRITE(numout,*)
@@ -898,4 +993,5 @@
          CASE( np_ENE )   ;   WRITE(numout,*) '   ==>>>   energy conserving scheme (Coriolis at F-points) (ENE)'
          CASE( np_ENT )   ;   WRITE(numout,*) '   ==>>>   energy conserving scheme (Coriolis at T-points) (ENT)'
+                              IF( ln_dynadv_vec )   CALL ctl_warn('dyn_vor_init: ENT scheme may not work in vector form')
          CASE( np_EET )   ;   WRITE(numout,*) '   ==>>>   energy conserving scheme (EEN scheme using e3t) (EET)'
          CASE( np_EEN )   ;   WRITE(numout,*) '   ==>>>   energy and enstrophy conserving scheme (EEN)'
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/sshwzv.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/sshwzv.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DYN/sshwzv.F90	(revision 14062)
@@ -6,9 +6,10 @@
    !! History :  3.1  !  2009-02  (G. Madec, M. Leclair)  Original code
    !!            3.3  !  2010-04  (M. Leclair, G. Madec)  modified LF-RA 
-   !!             -   !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
-   !!             -   !  2010-09  (D.Storkey and E.O'Dea) bug fixes for BDY module
-   !!            3.3  !  2011-10  (M. Leclair) split former ssh_wzv routine and remove all vvl related work
-   !!            4.0  !  2018-12  (A. Coward) add mixed implicit/explicit advection
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) Rename ssh_nxt -> ssh_atf. Now only does time filtering.
+   !!             -   !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea)  Assimilation interface
+   !!             -   !  2010-09  (D.Storkey and E.O'Dea)  bug fixes for BDY module
+   !!            3.3  !  2011-10  (M. Leclair)  split former ssh_wzv routine and remove all vvl related work
+   !!            4.0  !  2018-12  (A. Coward)  add mixed implicit/explicit advection
+   !!            4.1  !  2019-08  (A. Coward, D. Storkey)  Rename ssh_nxt -> ssh_atf. Now only does time filtering.
+   !!             -   !  2020-08  (S. Techene, G. Madec)  add here ssh initiatlisation
    !!----------------------------------------------------------------------
 
@@ -17,4 +18,5 @@
    !!   ssh_atf       : time filter the ssh arrays
    !!   wzv           : compute now vertical velocity
+   !!   ssh_init_rst  : ssh set from restart or domcfg.nc file or usr_def_istat_ssh
    !!----------------------------------------------------------------------
    USE oce            ! ocean dynamics and tracers variables
@@ -40,17 +42,18 @@
    USE timing         ! Timing
    USE wet_dry        ! Wetting/Drying flux limiting
-
+   USE usrdef_istate, ONLY : usr_def_istate_ssh   ! user defined ssh initial state 
+   
    IMPLICIT NONE
    PRIVATE
 
-   PUBLIC   ssh_nxt    ! called by step.F90
-   PUBLIC   wzv        ! called by step.F90
-   PUBLIC   wAimp      ! called by step.F90
-   PUBLIC   ssh_atf    ! called by step.F90
+   PUBLIC   ssh_nxt        ! called by step.F90
+   PUBLIC   wzv            ! called by step.F90
+   PUBLIC   wAimp          ! called by step.F90
+   PUBLIC   ssh_atf        ! called by step.F90
+   PUBLIC   ssh_init_rst   ! called by domain.F90
 
    !! * Substitutions
 #  include "do_loop_substitute.h90"
 #  include "domzgr_substitute.h90"
-
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -299,4 +302,5 @@
          !                                                  ! filtered "now" field
          pssh(:,:,Kmm) = pssh(:,:,Kmm) + rn_atfp * ( pssh(:,:,Kbb) - 2 * pssh(:,:,Kmm) + pssh(:,:,Kaa) )
+         !
          IF( .NOT.ln_linssh ) THEN                          ! "now" <-- with forcing removed
             zcoef = rn_atfp * rn_Dt * r1_rho0
@@ -307,10 +311,11 @@
 
             ! ice sheet coupling
-            IF ( ln_isf .AND. ln_isfcpl .AND. kt == nit000+1) pssh(:,:,Kbb) = pssh(:,:,Kbb) - rn_atfp * rn_Dt * ( risfcpl_ssh(:,:) - 0.0 ) * ssmask(:,:)
+            IF( ln_isf .AND. ln_isfcpl .AND. kt == nit000+1 )   &
+               &   pssh(:,:,Kbb) = pssh(:,:,Kbb) - rn_atfp * rn_Dt * ( risfcpl_ssh(:,:) - 0.0 ) * ssmask(:,:)
 
          ENDIF
       ENDIF
       !
-      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab2d_1=pssh(:,:,Kmm), clinfo1=' pssh(:,:,Kmm)  - : ', mask1=tmask )
+      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab2d_1=pssh(:,:,Kmm), clinfo1=' atf  - pssh(:,:,Kmm): ', mask1=tmask )
       !
       IF( ln_timing )   CALL timing_stop('ssh_atf')
@@ -431,4 +436,87 @@
       !
    END SUBROUTINE wAimp
+
+
+   SUBROUTINE ssh_init_rst( Kbb, Kmm, Kaa )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE ssh_init_rst  ***
+      !!
+      !! ** Purpose :   ssh initialization of the sea surface height (ssh)
+      !!
+      !! ** Method  :   set ssh from restart or read configuration, or user_def
+      !!              * ln_rstart = T
+      !!                   USE of IOM library to read ssh in the restart file
+      !!                   Leap-Frog: Kbb and Kmm are read except for l_1st_euler=T
+      !!
+      !!              * otherwise 
+      !!                   call user defined ssh or
+      !!                   set to -ssh_ref in wet and drying case with domcfg.nc
+      !!
+      !!              NB: ssh_b/n are written by restart.F90
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm, Kaa   ! ocean time level indices
+      !
+      INTEGER ::   ji, jj, jk
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'ssh_init_rst : ssh initialization'
+         WRITE(numout,*) '~~~~~~~~~~~~ '
+      ENDIF
+      !
+      !                            !=============================!
+      IF( ln_rstart ) THEN         !==  Read the restart file  ==!
+         !                         !=============================!
+         !
+         !                                     !*  Read ssh at Kmm
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)    '      Kmm sea surface height read in the restart file'
+         CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm) )
+         !
+         IF( l_1st_euler ) THEN                !* Euler at first time-step
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '      Euler first time step : ssh(Kbb) = ssh(Kmm)'
+            ssh(:,:,Kbb) = ssh(:,:,Kmm)
+            !
+         ELSE                                  !* read ssh at Kbb
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '      Kbb sea surface height read in the restart file'
+            CALL iom_get( numror, jpdom_auto, 'sshb', ssh(:,:,Kbb) )
+         ENDIF
+         !                         !============================!
+      ELSE                         !==  Initialize at "rest"  ==!
+         !                         !============================!
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)    '      initialization at rest'
+         !
+         IF( ll_wd ) THEN                      !* wet and dry 
+            !
+            IF( ln_read_cfg  ) THEN                 ! read configuration : ssh_ref is read in domain_cfg file
+!!st  why ssh is not masked : i.e. ssh(:,:,Kmm) = -ssh_ref*ssmask(:,:),
+!!st  since at the 1st time step lbclnk will be applied on ssh at Kaa but not initially at Kbb and Kmm
+               ssh(:,:,Kbb) = -ssh_ref
+               !
+               DO_2D( 1, 1, 1, 1 )
+                  IF( ht_0(ji,jj)-ssh_ref <  rn_wdmin1 ) THEN   ! if total depth is less than min depth
+                     ssh(ji,jj,Kbb) = rn_wdmin1 - ht_0(ji,jj)
+                  ENDIF
+               END_2D
+            ELSE                                    ! user define configuration case  
+               CALL usr_def_istate_ssh( tmask, ssh(:,:,Kbb) )
+            ENDIF
+            !
+         ELSE                                  !* user defined configuration
+            CALL usr_def_istate_ssh( tmask, ssh(:,:,Kbb) )
+            !
+         ENDIF
+         !
+         ssh(:,:,Kmm) = ssh(:,:,Kbb)           !* set now values from to before ones
+         ssh(:,:,Kaa) = 0._wp 
+      ENDIF
+      !
+   END SUBROUTINE ssh_init_rst
+      
    !!======================================================================
 END MODULE sshwzv
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/IOM/iom.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/IOM/iom.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/IOM/iom.F90	(revision 14062)
@@ -174,4 +174,5 @@
          CALL set_grid( "V", glamv, gphiv, .FALSE., .FALSE. )
          CALL set_grid( "W", glamt, gphit, .FALSE., .FALSE. )
+         CALL set_grid( "F", glamf, gphif, .FALSE., .FALSE. )
          CALL set_grid_znl( gphit )
          !
@@ -180,9 +181,11 @@
             CALL iom_set_domain_attr("grid_U", area = real( e1e2u(Nis0:Nie0, Njs0:Nje0), dp))
             CALL iom_set_domain_attr("grid_V", area = real( e1e2v(Nis0:Nie0, Njs0:Nje0), dp))
-            CALL iom_set_domain_attr("grid_W", area = real( e1e2t(Nis0:Nie0, Njs0:Nje0), dp))
+            CALL iom_set_domain_attr("grid_W", area = REAL( e1e2t(Nis0:Nie0, Njs0:Nje0), dp))
+            CALL iom_set_domain_attr("grid_F", area = real( e1e2f(Nis0:Nie0, Njs0:Nje0), dp))
             CALL set_grid_bounds( "T", glamf, gphif, glamt, gphit )
             CALL set_grid_bounds( "U", glamv, gphiv, glamu, gphiu )
             CALL set_grid_bounds( "V", glamu, gphiu, glamv, gphiv )
             CALL set_grid_bounds( "W", glamf, gphif, glamt, gphit )
+            CALL set_grid_bounds( "F", glamt, gphit, glamf, gphif )
          ENDIF
       ENDIF
@@ -191,8 +194,8 @@
          CALL dom_grid_crs   ! Save the parent grid information  & Switch to coarse grid domain
          !
-         CALL set_grid( "T", glamt_crs, gphit_crs, .FALSE., .FALSE. ) 
-         CALL set_grid( "U", glamu_crs, gphiu_crs, .FALSE., .FALSE. ) 
-         CALL set_grid( "V", glamv_crs, gphiv_crs, .FALSE., .FALSE. ) 
-         CALL set_grid( "W", glamt_crs, gphit_crs, .FALSE., .FALSE. ) 
+         CALL set_grid( "T", glamt_crs, gphit_crs, .FALSE., .FALSE. )
+         CALL set_grid( "U", glamu_crs, gphiu_crs, .FALSE., .FALSE. )
+         CALL set_grid( "V", glamv_crs, gphiv_crs, .FALSE., .FALSE. )
+         CALL set_grid( "W", glamt_crs, gphit_crs, .FALSE., .FALSE. )
          CALL set_grid_znl( gphit_crs )
           !
@@ -217,4 +220,5 @@
          CALL iom_set_axis_attr(  "depthv", paxis = gdept_1d )
          CALL iom_set_axis_attr(  "depthw", paxis = gdepw_1d )
+          CALL iom_set_axis_attr(  "depthf", paxis = gdept_1d )
 
           ! ABL
@@ -238,4 +242,5 @@
          CALL iom_set_axis_attr(  "depthv", bounds=zw_bnds )
          CALL iom_set_axis_attr(  "depthw", bounds=zt_bnds )
+          CALL iom_set_axis_attr(  "depthf", bounds=zw_bnds )
 
          ! ABL
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/IOM/restart.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/IOM/restart.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/IOM/restart.F90	(revision 14062)
@@ -11,4 +11,5 @@
    !!            3.7  !  2014-01  (G. Madec) suppression of curl and hdiv from the restart
    !!             -   !  2014-12  (G. Madec) remove KPP scheme
+   !!            4.1  !  2020-11  (S. Techene, G. Madec)  move ssh initiatlisation in DYN/sshwzv:ssh_init_rst
    !!----------------------------------------------------------------------
 
@@ -139,4 +140,7 @@
       !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
       !!              file, save fields which are necessary for restart
+      !!
+      !!                NB: ssh is written here (rst_write)
+      !!                    but is read or set in DYN/sshwzv:shh_init_rst
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   kt         ! ocean time-step
@@ -233,32 +237,24 @@
       !!                   ***  ROUTINE rst_read  ***
       !! 
-      !! ** Purpose :   Read files for NetCDF restart
-      !! 
-      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
+      !! ** Purpose :   Read velocity and T-S fields in the restart file
+      !! 
+      !! ** Method  :   Read in restart.nc fields which are necessary for restart
+      !!
+      !!                NB: restart file openned           in DOM/domain.F90:dom_init
+      !!                    before field in restart tested in DOM/domain.F90:dom_init
+      !!                    (sshb)
+      !!
+      !!                NB: ssh is read or set in DYN/sshwzv:shh_init_rst
+      !!                    but is written     in IOM/restart:rst_write
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
-      REAL(wp) ::   zrdt
       INTEGER  ::   jk
       REAL(wp), DIMENSION(jpi, jpj, jpk) :: w3d
       !!----------------------------------------------------------------------
-
-      CALL rst_read_open           ! open restart for reading (if not already opened)
-
-      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
-      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
-         CALL iom_get( numror, 'rdt', zrdt )
-         IF( zrdt /= rn_Dt ) THEN
-            IF(lwp) WRITE( numout,*)
-            IF(lwp) WRITE( numout,*) 'rst_read:  rdt not equal to the read one'
-            IF(lwp) WRITE( numout,*)
-            IF(lwp) WRITE( numout,*) '      ==>>>   forced euler first time-step'
-            l_1st_euler =  .TRUE.
-         ENDIF
-      ENDIF
-
+      !
       IF(.NOT.lrxios ) CALL iom_delay_rst( 'READ', 'OCE', numror )   ! read only ocean delayed global communication variables
-      
-      ! Diurnal DSST 
-      IF( ln_diurnal ) CALL iom_get( numror, jpdom_auto, 'Dsst' , x_dsst ) 
+      !
+      !                             !*  Diurnal DSST 
+      IF( ln_diurnal )   CALL iom_get( numror, jpdom_auto, 'Dsst' , x_dsst ) 
       IF ( ln_diurnal_only ) THEN 
          IF(lwp) WRITE( numout, * ) &
@@ -269,22 +265,25 @@
          RETURN 
       ENDIF  
-
-      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
-         ! before fields
+      !
+      !                             !*  Read Kmm fields
+      IF(lwp) WRITE(numout,*)    '           Kmm u, v and T-S fields read in the restart file'
+      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), cd_type = 'U', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), cd_type = 'V', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'tn'     , ts(:,:,:,jp_tem,Kmm) )
+      CALL iom_get( numror, jpdom_auto, 'sn'     , ts(:,:,:,jp_sal,Kmm) )
+      !
+      IF( l_1st_euler ) THEN        !*  Euler restart
+         IF(lwp) WRITE(numout,*) '           Kbb u, v and T-S fields set to Kmm values'
+         ts(:,:,:,:,Kbb) = ts(:,:,:,:,Kmm)         ! all before fields set to now values
+         uu(:,:,:  ,Kbb) = uu(:,:,:  ,Kmm)
+         vv(:,:,:  ,Kbb) = vv(:,:,:  ,Kmm)
+      ELSE                          !* Leap frog restart
+         IF(lwp) WRITE(numout,*) '           Kbb u, v and T-S fields read in the restart file'
          CALL iom_get( numror, jpdom_auto, 'ub'     , uu(:,:,:       ,Kbb), cd_type = 'U', psgn = -1._wp )
          CALL iom_get( numror, jpdom_auto, 'vb'     , vv(:,:,:       ,Kbb), cd_type = 'V', psgn = -1._wp )
          CALL iom_get( numror, jpdom_auto, 'tb'     , ts(:,:,:,jp_tem,Kbb) )
          CALL iom_get( numror, jpdom_auto, 'sb'     , ts(:,:,:,jp_sal,Kbb) )
-         CALL iom_get( numror, jpdom_auto, 'sshb'   ,ssh(:,:         ,Kbb) )
-      ELSE
-         l_1st_euler =  .TRUE.      ! before field not found, forced euler 1st time-step
-      ENDIF
-      !
-      ! now fields
-      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), cd_type = 'U', psgn = -1._wp )
-      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), cd_type = 'V', psgn = -1._wp )
-      CALL iom_get( numror, jpdom_auto, 'tn'     , ts(:,:,:,jp_tem,Kmm) )
-      CALL iom_get( numror, jpdom_auto, 'sn'     , ts(:,:,:,jp_sal,Kmm) )
-      CALL iom_get( numror, jpdom_auto, 'sshn'   ,ssh(:,:         ,Kmm) )
+      ENDIF
+      !
       IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN
          CALL iom_get( numror, jpdom_auto, 'rhop'   , rhop )   ! now    potential density
@@ -293,11 +292,4 @@
       ENDIF
       !
-      IF( l_1st_euler ) THEN                                  ! Euler restart 
-         ts   (:,:,:,:,Kbb) = ts   (:,:,:,:,Kmm)              ! all before fields set to now values
-         uu   (:,:,:  ,Kbb) = uu   (:,:,:  ,Kmm)
-         vv   (:,:,:  ,Kbb) = vv   (:,:,:  ,Kmm)
-         ssh  (:,:    ,Kbb) = ssh  (:,:    ,Kmm)
-      ENDIF
-      !
    END SUBROUTINE rst_read
 
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfcpl.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfcpl.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfcpl.F90	(revision 14062)
@@ -10,19 +10,19 @@
 
    !!----------------------------------------------------------------------
-   !!   isfrst : read/write iceshelf variables in/from restart
+   !!   isfrst        : read/write iceshelf variables in/from restart
    !!----------------------------------------------------------------------
-   USE isf_oce                          ! ice shelf variable
+   USE oce            ! ocean dynamics and tracers
+#if defined key_qco
+   USE domqco  , ONLY : dom_qco_zgr      ! vertical scale factor interpolation
+#else
+   USE domvvl  , ONLY : dom_vvl_zgr      ! vertical scale factor interpolation
+#endif
+   USE domutl  , ONLY : dom_ngb          ! find the closest grid point from a given lon/lat position
+   USE isf_oce        ! ice shelf variable
    USE isfutils, ONLY : debug
-   USE lib_mpp , ONLY: mpp_sum, mpp_max ! mpp routine
-#if ! defined key_qco
-   USE domvvl  , ONLY: dom_vvl_zgr      ! vertical scale factor interpolation
-#else
-   USE domqco   , ONLY: dom_qco_zgr      ! vertical scale factor interpolation
-#endif
-   USE domutl  , ONLY: dom_ngb          ! find the closest grid point from a given lon/lat position
    !
-   USE oce            ! ocean dynamics and tracers
    USE in_out_manager ! I/O manager
    USE iom            ! I/O library
+   USE lib_mpp , ONLY : mpp_sum, mpp_max ! mpp routine
    !
    IMPLICIT NONE
@@ -34,13 +34,13 @@
 
    TYPE isfcons
-      INTEGER :: ii     ! i global
-      INTEGER :: jj     ! j global
-      INTEGER :: kk     ! k level
-      REAL(wp):: dvol   ! volume increment
-      REAL(wp):: dsal   ! salt increment
-      REAL(wp):: dtem   ! heat increment
-      REAL(wp):: lon    ! lon
-      REAL(wp):: lat    ! lat
-      INTEGER :: ngb    ! 0/1 (valid location or not (ie on halo or no neigbourg))
+      INTEGER ::   ii     ! i global
+      INTEGER ::   jj     ! j global
+      INTEGER ::   kk     ! k level
+      REAL(wp)::   dvol   ! volume increment
+      REAL(wp)::   dsal   ! salt increment
+      REAL(wp)::   dtem   ! heat increment
+      REAL(wp)::   lon    ! lon
+      REAL(wp)::   lat    ! lat
+      INTEGER ::   ngb    ! 0/1 (valid location or not (ie on halo or no neigbourg))
    END TYPE
    !
@@ -121,6 +121,7 @@
 #endif 
    END SUBROUTINE isfcpl_init
-   ! 
-   SUBROUTINE isfcpl_rst_write(kt, Kmm)
+
+   
+   SUBROUTINE isfcpl_rst_write( kt, Kmm )
       !!---------------------------------------------------------------------
       !!                   ***  ROUTINE iscpl_rst_write  ***
@@ -133,5 +134,5 @@
       !!----------------------------------------------------------------------
       INTEGER :: jk                               ! loop index
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t, ze3u, ze3v, zgdepw  ! e3t , e3u, e3v !!st patch to use substitution
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t, ze3u, ze3v, zgdepw  ! for qco substitution
       !!----------------------------------------------------------------------
       !
@@ -153,4 +154,5 @@
    END SUBROUTINE isfcpl_rst_write
 
+   
    SUBROUTINE isfcpl_ssh(Kbb, Kmm, Kaa)
       !!---------------------------------------------------------------------- 
@@ -184,6 +186,6 @@
          zdssmask(:,:) = ssmask(:,:) - zssmask0(:,:)
          DO_2D( 0, 0, 0, 0 )
-            jip1=ji+1; jim1=ji-1;
-            jjp1=jj+1; jjm1=jj-1;
+            jip1=ji+1   ;   jim1=ji-1
+            jjp1=jj+1   ;   jjm1=jj-1
             !
             zsummsk = zssmask0(jip1,jj) + zssmask0(jim1,jj) + zssmask0(ji,jjp1) + zssmask0(ji,jjm1)
@@ -191,7 +193,7 @@
             IF (zdssmask(ji,jj) == 1._wp .AND. zsummsk /= 0._wp) THEN
                ssh(ji,jj,Kmm)=( zssh(jip1,jj)*zssmask0(jip1,jj)     &
-               &           + zssh(jim1,jj)*zssmask0(jim1,jj)     &
-               &           + zssh(ji,jjp1)*zssmask0(ji,jjp1)     &
-               &           + zssh(ji,jjm1)*zssmask0(ji,jjm1)) / zsummsk
+                  &           + zssh(jim1,jj)*zssmask0(jim1,jj)     &
+                  &           + zssh(ji,jjp1)*zssmask0(ji,jjp1)     &
+                  &           + zssh(ji,jjm1)*zssmask0(ji,jjm1)) / zsummsk
                zssmask_b(ji,jj) = 1._wp
             ENDIF
@@ -222,9 +224,10 @@
       CALL dom_vvl_zgr(Kbb, Kmm, Kaa)
 #else
-      CALL dom_qco_zgr(Kbb, Kmm, Kaa)
+      CALL dom_qco_zgr(Kbb, Kmm)
 #endif
       !
    END SUBROUTINE isfcpl_ssh
 
+   
    SUBROUTINE isfcpl_tra(Kmm)
       !!---------------------------------------------------------------------- 
@@ -375,4 +378,5 @@
       ! 
    END SUBROUTINE isfcpl_tra
+   
 
    SUBROUTINE isfcpl_vol(Kmm)
@@ -466,7 +470,8 @@
          risfcpl_ssh(:,:) = risfcpl_ssh(:,:) + risfcpl_vol(:,:,jk) * r1_e1e2t(:,:)
       END DO
-
+      !
    END SUBROUTINE isfcpl_vol
 
+   
    SUBROUTINE isfcpl_cons(Kmm)
       !!---------------------------------------------------------------------- 
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfdynatf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfdynatf.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfdynatf.F90	(revision 14062)
@@ -15,5 +15,5 @@
    USE phycst , ONLY: r1_rho0         ! physical constant
    USE dom_oce                        ! time and space domain
-   USE oce, ONLY : ssh                ! sea-surface height !!st needed for substitution
+   USE oce, ONLY : ssh                ! sea-surface height for qco substitution
 
    USE in_out_manager
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfrst.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfrst.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ISF/isfrst.F90	(revision 14062)
@@ -28,6 +28,6 @@
    !!----------------------------------------------------------------------
 CONTAINS
-   ! 
-   SUBROUTINE isfrst_read(cdisf, ptsc, pfwf, ptsc_b, pfwf_b )
+   
+   SUBROUTINE isfrst_read( cdisf, ptsc, pfwf, ptsc_b, pfwf_b )
       !!---------------------------------------------------------------------
       !!
@@ -51,5 +51,5 @@
       !
       ! read restart
-      IF( iom_varid( numror, cfwf_b, ldstop = .FALSE. ) > 0 ) THEN
+      IF( .NOT.l_1st_euler ) THEN
          IF(lwp) WRITE(numout,*) '          nit000-1 isf tracer content forcing fields read in the restart file'
          CALL iom_get( numror, jpdom_auto, cfwf_b, pfwf_b(:,:)         )   ! before ice shelf melt
@@ -62,6 +62,7 @@
       !
    END SUBROUTINE isfrst_read
-   ! 
-   SUBROUTINE isfrst_write(kt, cdisf, ptsc, pfwf )
+
+   
+   SUBROUTINE isfrst_write( kt, cdisf, ptsc, pfwf )
       !!---------------------------------------------------------------------
       !!
@@ -94,4 +95,5 @@
       !
    END SUBROUTINE isfrst_write
-   !
+   
+   !!======================================================================
 END MODULE isfrst
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/LBC/mppini.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/LBC/mppini.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/LBC/mppini.F90	(revision 14062)
@@ -217,7 +217,7 @@
       ! then we calculate them here now that we have our communicator size
       IF(lwp) THEN
+         WRITE(numout,*)
          WRITE(numout,*) 'mpp_init:'
          WRITE(numout,*) '~~~~~~~~ '
-         WRITE(numout,*)
       ENDIF
       IF( jpni < 1 .OR. jpnj < 1 ) THEN
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/LDF/ldfdyn.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/LDF/ldfdyn.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/LDF/ldfdyn.F90	(revision 14062)
@@ -34,4 +34,5 @@
    !                                    !!* Namelist namdyn_ldf : lateral mixing on momentum *
    LOGICAL , PUBLIC ::   ln_dynldf_OFF   !: No operator (i.e. no explicit diffusion)
+   INTEGER , PUBLIC ::   nn_dynldf_typ   !: operator type (0: div-rot ; 1: symmetric)
    LOGICAL , PUBLIC ::   ln_dynldf_lap   !: laplacian operator
    LOGICAL , PUBLIC ::   ln_dynldf_blp   !: bilaplacian operator
@@ -52,6 +53,10 @@
 
    !                                    !!* Parameter to control the type of lateral viscous operator
-   INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10                       !: error in setting the operator
-   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00                       !: without operator (i.e. no lateral viscous trend)
+   INTEGER, PARAMETER, PUBLIC ::   np_ERROR   =-10                      !: error in setting the operator
+   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf  = 00                      !: without operator (i.e. no lateral viscous trend)
+   !
+   INTEGER, PARAMETER, PUBLIC ::   np_typ_rot = 0                       !: div-rot   operator
+   INTEGER, PARAMETER, PUBLIC ::   np_typ_sym = 1                       !: symmetric operator
+   !
    !                          !!      laplacian     !    bilaplacian    !
    INTEGER, PARAMETER, PUBLIC ::   np_lap    = 10   ,   np_blp    = 20  !: iso-level operator
@@ -109,8 +114,8 @@
       CHARACTER(len=5) ::   cl_Units               ! units (m2/s or m4/s)
       !!
-      NAMELIST/namdyn_ldf/ ln_dynldf_OFF, ln_dynldf_lap, ln_dynldf_blp,   &   ! type of operator
-         &                 ln_dynldf_lev, ln_dynldf_hor, ln_dynldf_iso,   &   ! acting direction of the operator
-         &                 nn_ahm_ijk_t , rn_Uv    , rn_Lv,   rn_ahm_b,   &   ! lateral eddy coefficient
-         &                 rn_csmc      , rn_minfac    , rn_maxfac            ! Smagorinsky settings
+      NAMELIST/namdyn_ldf/ ln_dynldf_OFF, nn_dynldf_typ, ln_dynldf_lap, ln_dynldf_blp,   &   ! type of operator
+         &                 ln_dynldf_lev, ln_dynldf_hor, ln_dynldf_iso,                  &   ! acting direction of the operator
+         &                 nn_ahm_ijk_t , rn_Uv        , rn_Lv        ,   rn_ahm_b,      &   ! lateral eddy coefficient
+         &                 rn_csmc      , rn_minfac    , rn_maxfac                           ! Smagorinsky settings
       !!----------------------------------------------------------------------
       !
@@ -130,4 +135,5 @@
          WRITE(numout,*) '      type :'
          WRITE(numout,*) '         no explicit diffusion                ln_dynldf_OFF = ', ln_dynldf_OFF
+         WRITE(numout,*) '         type of operator (div-rot or sym)    nn_dynldf_typ = ', nn_dynldf_typ
          WRITE(numout,*) '         laplacian operator                   ln_dynldf_lap = ', ln_dynldf_lap
          WRITE(numout,*) '         bilaplacian operator                 ln_dynldf_blp = ', ln_dynldf_blp
@@ -147,6 +153,6 @@
          WRITE(numout,*) '         Smagorinsky coefficient              rn_csmc       = ', rn_csmc
          WRITE(numout,*) '         factor multiplier for eddy visc.'
-         WRITE(numout,*) '            lower limit (default 1.0)         rn_minfac    = ', rn_minfac
-         WRITE(numout,*) '            upper limit (default 1.0)         rn_maxfac    = ', rn_maxfac
+         WRITE(numout,*) '            lower limit (default 1.0)         rn_minfac     = ', rn_minfac
+         WRITE(numout,*) '            upper limit (default 1.0)         rn_maxfac     = ', rn_maxfac
       ENDIF
 
@@ -160,12 +166,20 @@
       IF( ln_dynldf_lap ) THEN   ;                              ioptio = ioptio + 1   ;   ENDIF
       IF( ln_dynldf_blp ) THEN   ;                              ioptio = ioptio + 1   ;   ENDIF
-      IF( ioptio /= 1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 operator options (NONE/lap/blp)' )
+      IF( ioptio /= 1   )   CALL ctl_stop( 'ldf_dyn_init: use ONE of the 3 operator options (NONE/lap/blp)' )
       !
       IF(.NOT.ln_dynldf_OFF ) THEN     !==  direction ==>> type of operator  ==!
+         !
+         SELECT CASE( nn_dynldf_typ )  ! div-rot or symmetric
+         CASE( np_typ_rot )   ;   IF(lwp)   WRITE(numout,*) '   ==>>>   use div-rot   operator '
+         CASE( np_typ_sym )   ;   IF(lwp)   WRITE(numout,*) '   ==>>>   use symmetric operator '
+         CASE DEFAULT                                     ! error
+            CALL ctl_stop('ldf_dyn_init: wrong value for nn_dynldf_typ (0 or 1)'  )
+         END SELECT
+         !
          ioptio = 0
          IF( ln_dynldf_lev )   ioptio = ioptio + 1
          IF( ln_dynldf_hor )   ioptio = ioptio + 1
          IF( ln_dynldf_iso )   ioptio = ioptio + 1
-         IF( ioptio /= 1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 direction options (level/hor/iso)' )
+         IF( ioptio /= 1   )   CALL ctl_stop( 'ldf_dyn_init: use ONE of the 3 direction options (level/hor/iso)' )
          !
          !                             ! Set nldf_dyn, the type of lateral diffusion, from ln_dynldf_... logicals
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/diaobs.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/diaobs.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/diaobs.F90	(revision 14062)
@@ -57,26 +57,29 @@
    PUBLIC calc_date        ! Compute the date of a timestep
 
-   LOGICAL, PUBLIC :: ln_diaobs          !: Logical switch for the obs operator
-   LOGICAL         :: ln_sstnight        !  Logical switch for night mean SST obs
-   LOGICAL         :: ln_sla_fp_indegs   !  T=> SLA obs footprint size specified in degrees, F=> in metres
-   LOGICAL         :: ln_sst_fp_indegs   !  T=> SST obs footprint size specified in degrees, F=> in metres
-   LOGICAL         :: ln_sss_fp_indegs   !  T=> SSS obs footprint size specified in degrees, F=> in metres
-   LOGICAL         :: ln_sic_fp_indegs   !  T=> sea-ice obs footprint size specified in degrees, F=> in metres
-
-   REAL(wp) ::   rn_sla_avglamscl   ! E/W diameter of SLA observation footprint (metres)
-   REAL(wp) ::   rn_sla_avgphiscl   ! N/S diameter of SLA observation footprint (metres)
-   REAL(wp) ::   rn_sst_avglamscl   ! E/W diameter of SST observation footprint (metres)
-   REAL(wp) ::   rn_sst_avgphiscl   ! N/S diameter of SST observation footprint (metres)
-   REAL(wp) ::   rn_sss_avglamscl   ! E/W diameter of SSS observation footprint (metres)
-   REAL(wp) ::   rn_sss_avgphiscl   ! N/S diameter of SSS observation footprint (metres)
-   REAL(wp) ::   rn_sic_avglamscl   ! E/W diameter of sea-ice observation footprint (metres)
-   REAL(wp) ::   rn_sic_avgphiscl   ! N/S diameter of sea-ice observation footprint (metres)
-
-   INTEGER :: nn_1dint       ! Vertical interpolation method
-   INTEGER :: nn_2dint       ! Default horizontal interpolation method
-   INTEGER :: nn_2dint_sla   ! SLA horizontal interpolation method 
-   INTEGER :: nn_2dint_sst   ! SST horizontal interpolation method 
-   INTEGER :: nn_2dint_sss   ! SSS horizontal interpolation method 
-   INTEGER :: nn_2dint_sic   ! Seaice horizontal interpolation method 
+   LOGICAL, PUBLIC :: ln_diaobs            !: Logical switch for the obs operator
+   LOGICAL         :: ln_sstnight          !  Logical switch for night mean SST obs
+   LOGICAL         :: ln_default_fp_indegs !  T=> Default obs footprint size specified in degrees, F=> in metres
+   LOGICAL         :: ln_sla_fp_indegs     !  T=> SLA obs footprint size specified in degrees, F=> in metres
+   LOGICAL         :: ln_sst_fp_indegs     !  T=> SST obs footprint size specified in degrees, F=> in metres
+   LOGICAL         :: ln_sss_fp_indegs     !  T=> SSS obs footprint size specified in degrees, F=> in metres
+   LOGICAL         :: ln_sic_fp_indegs     !  T=> sea-ice obs footprint size specified in degrees, F=> in metres
+
+   REAL(wp) ::   rn_default_avglamscl      ! E/W diameter of SLA observation footprint (metres)
+   REAL(wp) ::   rn_default_avgphiscl      ! N/S diameter of SLA observation footprint (metre
+   REAL(wp) ::   rn_sla_avglamscl          ! E/W diameter of SLA observation footprint (metres)
+   REAL(wp) ::   rn_sla_avgphiscl          ! N/S diameter of SLA observation footprint (metres)
+   REAL(wp) ::   rn_sst_avglamscl          ! E/W diameter of SST observation footprint (metres)
+   REAL(wp) ::   rn_sst_avgphiscl          ! N/S diameter of SST observation footprint (metres)
+   REAL(wp) ::   rn_sss_avglamscl          ! E/W diameter of SSS observation footprint (metres)
+   REAL(wp) ::   rn_sss_avgphiscl          ! N/S diameter of SSS observation footprint (metres)
+   REAL(wp) ::   rn_sic_avglamscl          ! E/W diameter of sea-ice observation footprint (metres)
+   REAL(wp) ::   rn_sic_avgphiscl          ! N/S diameter of sea-ice observation footprint (metres)
+
+   INTEGER :: nn_1dint                     ! Vertical interpolation method
+   INTEGER :: nn_2dint_default             ! Default horizontal interpolation method
+   INTEGER :: nn_2dint_sla                 ! SLA horizontal interpolation method 
+   INTEGER :: nn_2dint_sst                 ! SST horizontal interpolation method 
+   INTEGER :: nn_2dint_sss                 ! SSS horizontal interpolation method 
+   INTEGER :: nn_2dint_sic                 ! Seaice horizontal interpolation method 
    INTEGER, DIMENSION(imaxavtypes) ::   nn_profdavtypes   ! Profile data types representing a daily average
    INTEGER :: nproftypes     ! Number of profile obs types
@@ -94,5 +97,5 @@
    TYPE(obs_prof), PUBLIC, POINTER, DIMENSION(:) ::   profdataqc   !: Profile data after quality control
 
-   CHARACTER(len=lca), PUBLIC, DIMENSION(:), ALLOCATABLE ::   cobstypesprof, cobstypessurf   !: Profile & surface obs types
+   CHARACTER(len=8), PUBLIC, DIMENSION(:), ALLOCATABLE ::   cobstypesprof, cobstypessurf   !: Profile & surface obs types
 
    !!----------------------------------------------------------------------
@@ -121,5 +124,6 @@
       INTEGER :: jvar            ! Counter for variables
       INTEGER :: jfile           ! Counter for files
-      INTEGER :: jnumsstbias
+      INTEGER :: jnumsstbias     ! Number of SST bias files to read and apply
+      INTEGER :: n2dint_type     ! Local version of nn_2dint*
       !
       CHARACTER(len=128), DIMENSION(jpmaxnfiles) :: &
@@ -130,5 +134,5 @@
          & cn_sicfbfiles, &      ! Seaice concentration input filenames
          & cn_velfbfiles, &      ! Velocity profile input filenames
-         & cn_sstbiasfiles      ! SST bias input filenames
+         & cn_sstbiasfiles       ! SST bias input filenames
       CHARACTER(LEN=128) :: &
          & cn_altbiasfile        ! Altimeter bias input filename
@@ -136,4 +140,6 @@
          & clproffiles, &        ! Profile filenames
          & clsurffiles           ! Surface filenames
+      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: &
+         & clvars                ! Expected variable names
          !
       LOGICAL :: ln_t3d          ! Logical switch for temperature profiles
@@ -150,13 +156,16 @@
       LOGICAL :: ln_s_at_t       ! Logical switch to compute model S at T obs
       LOGICAL :: ln_bound_reject ! Logical to remove obs near boundaries in LAMs.
-      LOGICAL :: llvar1          ! Logical for profile variable 1
-      LOGICAL :: llvar2          ! Logical for profile variable 1
+      LOGICAL :: ltype_fp_indegs ! Local version of ln_*_fp_indegs
+      LOGICAL :: ltype_night     ! Local version of ln_sstnight (false for other variables)
+      LOGICAL, DIMENSION(:), ALLOCATABLE :: llvar   ! Logical for profile variable read
       LOGICAL, DIMENSION(jpmaxnfiles) :: lmask ! Used for finding number of sstbias files
       !
-      REAL(dp) :: rn_dobsini     ! Obs window start date YYYYMMDD.HHMMSS
-      REAL(dp) :: rn_dobsend     ! Obs window end date   YYYYMMDD.HHMMSS
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zglam1, zglam2   ! Model longitudes for profile variable 1 & 2
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zgphi1, zgphi2   ! Model latitudes  for profile variable 1 & 2
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zmask1, zmask2   ! Model land/sea mask associated with variable 1 & 2
+      REAL(dp) :: rn_dobsini      ! Obs window start date YYYYMMDD.HHMMSS
+      REAL(dp) :: rn_dobsend      ! Obs window end date   YYYYMMDD.HHMMSS
+      REAL(wp) :: ztype_avglamscl ! Local version of rn_*_avglamscl
+      REAL(wp) :: ztype_avgphiscl ! Local version of rn_*_avgphiscl
+      REAL(wp), DIMENSION(:,:,:),   ALLOCATABLE :: zglam   ! Model longitudes for profile variables
+      REAL(wp), DIMENSION(:,:,:),   ALLOCATABLE :: zgphi   ! Model latitudes  for profile variables
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: zmask   ! Model land/sea mask associated with variables
       !!
       NAMELIST/namobs/ln_diaobs, ln_t3d, ln_s3d, ln_sla,              &
@@ -165,5 +174,5 @@
          &            ln_grid_global, ln_grid_search_lookup,          &
          &            ln_ignmis, ln_s_at_t, ln_bound_reject,          &
-         &            ln_sstnight,                                    &
+         &            ln_sstnight, ln_default_fp_indegs,              &
          &            ln_sla_fp_indegs, ln_sst_fp_indegs,             &
          &            ln_sss_fp_indegs, ln_sic_fp_indegs,             &
@@ -174,9 +183,10 @@
          &            cn_gridsearchfile, rn_gridsearchres,            &
          &            rn_dobsini, rn_dobsend,                         &
+         &            rn_default_avglamscl, rn_default_avgphiscl,     &
          &            rn_sla_avglamscl, rn_sla_avgphiscl,             &
          &            rn_sst_avglamscl, rn_sst_avgphiscl,             &
          &            rn_sss_avglamscl, rn_sss_avgphiscl,             &
          &            rn_sic_avglamscl, rn_sic_avgphiscl,             &
-         &            nn_1dint, nn_2dint,                             &
+         &            nn_1dint, nn_2dint_default,                     &
          &            nn_2dint_sla, nn_2dint_sst,                     &
          &            nn_2dint_sss, nn_2dint_sic,                     &
@@ -234,5 +244,21 @@
          WRITE(numout,*) '      Final date in window YYYYMMDD.HHMMSS                 rn_dobsend = ', rn_dobsend
          WRITE(numout,*) '      Type of vertical interpolation method                  nn_1dint = ', nn_1dint
-         WRITE(numout,*) '      Type of horizontal interpolation method                nn_2dint = ', nn_2dint
+         WRITE(numout,*) '      Default horizontal interpolation method        nn_2dint_default = ', nn_2dint_default
+         WRITE(numout,*) '      Type of horizontal interpolation method for SLA    nn_2dint_sla = ', nn_2dint_sla
+         WRITE(numout,*) '      Type of horizontal interpolation method for SST    nn_2dint_sst = ', nn_2dint_sst
+         WRITE(numout,*) '      Type of horizontal interpolation method for SSS    nn_2dint_sss = ', nn_2dint_sss        
+         WRITE(numout,*) '      Type of horizontal interpolation method for SIC    nn_2dint_sic = ', nn_2dint_sic
+         WRITE(numout,*) '      Default E/W diameter of obs footprint      rn_default_avglamscl = ', rn_default_avglamscl
+         WRITE(numout,*) '      Default N/S diameter of obs footprint      rn_default_avgphiscl = ', rn_default_avgphiscl
+         WRITE(numout,*) '      Default obs footprint in deg [T] or m [F]  ln_default_fp_indegs = ', ln_default_fp_indegs
+         WRITE(numout,*) '      SLA E/W diameter of obs footprint              rn_sla_avglamscl = ', rn_sla_avglamscl
+         WRITE(numout,*) '      SLA N/S diameter of obs footprint              rn_sla_avgphiscl = ', rn_sla_avgphiscl
+         WRITE(numout,*) '      SLA obs footprint in deg [T] or m [F]          ln_sla_fp_indegs = ', ln_sla_fp_indegs
+         WRITE(numout,*) '      SST E/W diameter of obs footprint              rn_sst_avglamscl = ', rn_sst_avglamscl
+         WRITE(numout,*) '      SST N/S diameter of obs footprint              rn_sst_avgphiscl = ', rn_sst_avgphiscl
+         WRITE(numout,*) '      SST obs footprint in deg [T] or m [F]          ln_sst_fp_indegs = ', ln_sst_fp_indegs
+         WRITE(numout,*) '      SIC E/W diameter of obs footprint              rn_sic_avglamscl = ', rn_sic_avglamscl
+         WRITE(numout,*) '      SIC N/S diameter of obs footprint              rn_sic_avgphiscl = ', rn_sic_avgphiscl
+         WRITE(numout,*) '      SIC obs footprint in deg [T] or m [F]          ln_sic_fp_indegs = ', ln_sic_fp_indegs
          WRITE(numout,*) '      Rejection of observations near land switch               ln_nea = ', ln_nea
          WRITE(numout,*) '      Rejection of obs near open bdys                 ln_bound_reject = ', ln_bound_reject
@@ -278,12 +304,14 @@
          IF( ln_t3d .OR. ln_s3d ) THEN
             jtype = jtype + 1
-            CALL obs_settypefiles( nproftypes, jpmaxnfiles, jtype, 'prof  ', &
-               &                   cn_profbfiles, ifilesprof, cobstypesprof, clproffiles )
+            cobstypesprof(jtype) = 'prof'
+            clproffiles(jtype,:) = cn_profbfiles
          ENDIF
          IF( ln_vel3d ) THEN
             jtype = jtype + 1
-            CALL obs_settypefiles( nproftypes, jpmaxnfiles, jtype, 'vel   ', &
-               &                   cn_velfbfiles, ifilesprof, cobstypesprof, clproffiles )
+            cobstypesprof(jtype) = 'vel'
+            clproffiles(jtype,:) = cn_velfbfiles
          ENDIF
+         !
+         CALL obs_settypefiles( nproftypes, jpmaxnfiles, ifilesprof, cobstypesprof, clproffiles )
          !
       ENDIF
@@ -303,48 +331,85 @@
          IF( ln_sla ) THEN
             jtype = jtype + 1
-            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sla   ', &
-               &                   cn_slafbfiles, ifilessurf, cobstypessurf, clsurffiles )
-            CALL obs_setinterpopts( nsurftypes, jtype, 'sla   ',      &
-               &                  nn_2dint, nn_2dint_sla,             &
-               &                  rn_sla_avglamscl, rn_sla_avgphiscl, &
-               &                  ln_sla_fp_indegs, .FALSE.,          &
-               &                  n2dintsurf, zavglamscl, zavgphiscl, &
-               &                  lfpindegs, llnightav )
+            cobstypessurf(jtype) = 'sla'
+            clsurffiles(jtype,:) = cn_slafbfiles
          ENDIF
          IF( ln_sst ) THEN
             jtype = jtype + 1
-            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sst   ', &
-               &                   cn_sstfbfiles, ifilessurf, cobstypessurf, clsurffiles )
-            CALL obs_setinterpopts( nsurftypes, jtype, 'sst   ',      &
-               &                  nn_2dint, nn_2dint_sst,             &
-               &                  rn_sst_avglamscl, rn_sst_avgphiscl, &
-               &                  ln_sst_fp_indegs, ln_sstnight,      &
-               &                  n2dintsurf, zavglamscl, zavgphiscl, &
-               &                  lfpindegs, llnightav )
+            cobstypessurf(jtype) = 'sst'
+            clsurffiles(jtype,:) = cn_sstfbfiles
          ENDIF
 #if defined key_si3 || defined key_cice
          IF( ln_sic ) THEN
             jtype = jtype + 1
-            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sic   ', &
-               &                   cn_sicfbfiles, ifilessurf, cobstypessurf, clsurffiles )
-            CALL obs_setinterpopts( nsurftypes, jtype, 'sic   ',      &
-               &                  nn_2dint, nn_2dint_sic,             &
-               &                  rn_sic_avglamscl, rn_sic_avgphiscl, &
-               &                  ln_sic_fp_indegs, .FALSE.,          &
-               &                  n2dintsurf, zavglamscl, zavgphiscl, &
-               &                  lfpindegs, llnightav )
+            cobstypessurf(jtype) = 'sic'
+            clsurffiles(jtype,:) = cn_sicfbfiles
          ENDIF
 #endif
          IF( ln_sss ) THEN
             jtype = jtype + 1
-            CALL obs_settypefiles( nsurftypes, jpmaxnfiles, jtype, 'sss   ', &
-               &                   cn_sssfbfiles, ifilessurf, cobstypessurf, clsurffiles )
-            CALL obs_setinterpopts( nsurftypes, jtype, 'sss   ',      &
-               &                  nn_2dint, nn_2dint_sss,             &
-               &                  rn_sss_avglamscl, rn_sss_avgphiscl, &
-               &                  ln_sss_fp_indegs, .FALSE.,          &
-               &                  n2dintsurf, zavglamscl, zavgphiscl, &
-               &                  lfpindegs, llnightav )
+            cobstypessurf(jtype) = 'sss'
+            clsurffiles(jtype,:) = cn_sssfbfiles
          ENDIF
+         !
+         CALL obs_settypefiles( nsurftypes, jpmaxnfiles, ifilessurf, cobstypessurf, clsurffiles )
+
+         DO jtype = 1, nsurftypes
+
+            IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) THEN
+               IF ( nn_2dint_sla == -1 ) THEN
+                  n2dint_type  = nn_2dint_default
+               ELSE
+                  n2dint_type  = nn_2dint_sla
+               ENDIF
+               ztype_avglamscl = rn_sla_avglamscl
+               ztype_avgphiscl = rn_sla_avgphiscl
+               ltype_fp_indegs = ln_sla_fp_indegs
+               ltype_night     = .FALSE.
+            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sst' ) THEN
+               IF ( nn_2dint_sst == -1 ) THEN
+                  n2dint_type  = nn_2dint_default
+               ELSE
+                  n2dint_type  = nn_2dint_sst
+               ENDIF
+               ztype_avglamscl = rn_sst_avglamscl
+               ztype_avgphiscl = rn_sst_avgphiscl
+               ltype_fp_indegs = ln_sst_fp_indegs
+               ltype_night     = ln_sstnight
+            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sic' ) THEN
+               IF ( nn_2dint_sic == -1 ) THEN
+                  n2dint_type  = nn_2dint_default
+               ELSE
+                  n2dint_type  = nn_2dint_sic
+               ENDIF
+               ztype_avglamscl = rn_sic_avglamscl
+               ztype_avgphiscl = rn_sic_avgphiscl
+               ltype_fp_indegs = ln_sic_fp_indegs
+               ltype_night     = .FALSE.
+            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sss' ) THEN
+               IF ( nn_2dint_sss == -1 ) THEN
+                  n2dint_type  = nn_2dint_default
+               ELSE
+                  n2dint_type  = nn_2dint_sss
+               ENDIF
+               ztype_avglamscl = rn_sss_avglamscl
+               ztype_avgphiscl = rn_sss_avgphiscl
+               ltype_fp_indegs = ln_sss_fp_indegs
+               ltype_night     = .FALSE.
+            ELSE
+               n2dint_type     = nn_2dint_default
+               ztype_avglamscl = rn_default_avglamscl
+               ztype_avgphiscl = rn_default_avgphiscl
+               ltype_fp_indegs = ln_default_fp_indegs
+               ltype_night     = .FALSE.
+            ENDIF
+            
+            CALL obs_setinterpopts( nsurftypes, jtype, TRIM(cobstypessurf(jtype)), &
+               &                    nn_2dint_default, n2dint_type,                 &
+               &                    ztype_avglamscl, ztype_avgphiscl,              &
+               &                    ltype_fp_indegs, ltype_night,                  &
+               &                    n2dintsurf, zavglamscl, zavgphiscl,            &
+               &                    lfpindegs, llnightav )
+
+         END DO
          !
       ENDIF
@@ -368,6 +433,6 @@
       ENDIF
       !
-      IF( nn_2dint < 0  .OR.  nn_2dint > 6  ) THEN
-         CALL ctl_stop('dia_obs_init: Choice of horizontal (2D) interpolation method is not available')
+      IF( nn_2dint_default < 0  .OR.  nn_2dint_default > 6  ) THEN
+         CALL ctl_stop('dia_obs_init: Choice of default horizontal (2D) interpolation method is not available')
       ENDIF
       !
@@ -388,26 +453,52 @@
          DO jtype = 1, nproftypes
             !
-            nvarsprof(jtype) = 2
             IF ( TRIM(cobstypesprof(jtype)) == 'prof' ) THEN
-               nextrprof(jtype) = 1
-               llvar1 = ln_t3d
-               llvar2 = ln_s3d
-               zglam1 = glamt
-               zgphi1 = gphit
-               zmask1 = tmask
-               zglam2 = glamt
-               zgphi2 = gphit
-               zmask2 = tmask
-            ENDIF
-            IF ( TRIM(cobstypesprof(jtype)) == 'vel' )  THEN
+               nvarsprof(jtype) = 2
+               nextrprof(jtype) = 1             
+               ALLOCATE( llvar (nvarsprof(jtype)) )
+               ALLOCATE( clvars(nvarsprof(jtype)) )
+               ALLOCATE( zglam(jpi, jpj,      nvarsprof(jtype)) )
+               ALLOCATE( zgphi(jpi, jpj,      nvarsprof(jtype)) )
+               ALLOCATE( zmask(jpi, jpj, jpk, nvarsprof(jtype)) )
+               llvar(1)       = ln_t3d
+               llvar(2)       = ln_s3d
+               clvars(1)      = 'POTM'
+               clvars(2)      = 'PSAL'
+               zglam(:,:,1)   = glamt(:,:)
+               zglam(:,:,2)   = glamt(:,:)
+               zgphi(:,:,1)   = gphit(:,:)
+               zgphi(:,:,2)   = gphit(:,:)
+               zmask(:,:,:,1) = tmask(:,:,:)
+               zmask(:,:,:,2) = tmask(:,:,:)
+            ELSE IF ( TRIM(cobstypesprof(jtype)) == 'vel' )  THEN
+               nvarsprof(jtype) = 2
                nextrprof(jtype) = 2
-               llvar1 = ln_vel3d
-               llvar2 = ln_vel3d
-               zglam1 = glamu
-               zgphi1 = gphiu
-               zmask1 = umask
-               zglam2 = glamv
-               zgphi2 = gphiv
-               zmask2 = vmask
+               ALLOCATE( llvar (nvarsprof(jtype)) )
+               ALLOCATE( clvars(nvarsprof(jtype)) )
+               ALLOCATE( zglam(jpi, jpj,      nvarsprof(jtype)) )
+               ALLOCATE( zgphi(jpi, jpj,      nvarsprof(jtype)) )
+               ALLOCATE( zmask(jpi, jpj, jpk, nvarsprof(jtype)) )
+               llvar(1)       = ln_vel3d
+               llvar(2)       = ln_vel3d
+               clvars(1)      = 'UVEL'
+               clvars(2)      = 'VVEL'
+               zglam(:,:,1)   = glamu(:,:)
+               zglam(:,:,2)   = glamv(:,:)
+               zgphi(:,:,1)   = gphiu(:,:)
+               zgphi(:,:,2)   = gphiv(:,:)
+               zmask(:,:,:,1) = umask(:,:,:)
+               zmask(:,:,:,2) = vmask(:,:,:)
+            ELSE
+               nvarsprof(jtype) = 1
+               nextrprof(jtype) = 0
+               ALLOCATE( llvar (nvarsprof(jtype)) )
+               ALLOCATE( clvars(nvarsprof(jtype)) )
+               ALLOCATE( zglam(jpi, jpj,      nvarsprof(jtype)) )
+               ALLOCATE( zgphi(jpi, jpj,      nvarsprof(jtype)) )
+               ALLOCATE( zmask(jpi, jpj, jpk, nvarsprof(jtype)) )
+               llvar(1)       = .TRUE.
+               zglam(:,:,1)   = glamt(:,:)
+               zgphi(:,:,1)   = gphit(:,:)
+               zmask(:,:,:,1) = tmask(:,:,:)
             ENDIF
             !
@@ -416,6 +507,6 @@
                &               clproffiles(jtype,1:ifilesprof(jtype)), &
                &               nvarsprof(jtype), nextrprof(jtype), nitend-nit000+2, &
-               &               rn_dobsini, rn_dobsend, llvar1, llvar2, &
-               &               ln_ignmis, ln_s_at_t, .FALSE., &
+               &               rn_dobsini, rn_dobsend, llvar, &
+               &               ln_ignmis, ln_s_at_t, .FALSE., clvars, &
                &               kdailyavtypes = nn_profdavtypes )
                !
@@ -425,9 +516,12 @@
             !
             CALL obs_pre_prof( profdata(jtype), profdataqc(jtype), &
-               &               llvar1, llvar2, &
+               &               llvar, &
                &               jpi, jpj, jpk, &
-               &               zmask1, zglam1, zgphi1, zmask2, zglam2, zgphi2,  &
+               &               zmask, zglam, zgphi, &
                &               ln_nea, ln_bound_reject, Kmm, &
                &               kdailyavtypes = nn_profdavtypes )
+            !
+            DEALLOCATE( llvar, clvars, zglam, zgphi, zmask )
+            !
          END DO
          !
@@ -449,9 +543,21 @@
             IF( TRIM(cobstypessurf(jtype)) == 'sst' )   llnightav(jtype) = ln_sstnight
             !
+            ALLOCATE( clvars( nvarssurf(jtype) ) )
+            IF ( TRIM(cobstypessurf(jtype)) == 'sla' ) THEN
+               clvars(1) = 'SLA'
+            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sst' ) THEN
+               clvars(1) = 'SST'
+            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sic' ) THEN
+               clvars(1) = 'ICECONC'
+            ELSE IF ( TRIM(cobstypessurf(jtype)) == 'sss' ) THEN
+               clvars(1) = 'SSS'
+            ENDIF
+            !
             ! Read in surface obs types
             CALL obs_rea_surf( surfdata(jtype), ifilessurf(jtype), &
                &               clsurffiles(jtype,1:ifilessurf(jtype)), &
                &               nvarssurf(jtype), nextrsurf(jtype), nitend-nit000+2, &
-               &               rn_dobsini, rn_dobsend, ln_ignmis, .FALSE., llnightav(jtype) )
+               &               rn_dobsini, rn_dobsend, ln_ignmis, .FALSE., llnightav(jtype), &
+               &               clvars )
                !
             CALL obs_pre_surf( surfdata(jtype), surfdataqc(jtype), ln_nea, ln_bound_reject )
@@ -473,4 +579,6 @@
                   &                  jnumsstbias      , cn_sstbiasfiles(1:jnumsstbias) ) 
             ENDIF
+            !
+            DEALLOCATE( clvars )
          END DO
          !
@@ -516,18 +624,14 @@
       INTEGER :: jvar              ! Variable number
       INTEGER :: ji, jj            ! Loop counters
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: &
-         & zprofvar1, &            ! Model values for 1st variable in a prof ob
-         & zprofvar2               ! Model values for 2nd variable in a prof ob
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: &
-         & zprofmask1, &           ! Mask associated with zprofvar1
-         & zprofmask2              ! Mask associated with zprofvar2
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
+         & zprofvar                ! Model values for variables in a prof ob
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
+         & zprofmask               ! Mask associated with zprofvar
       REAL(wp), DIMENSION(jpi,jpj) :: &
          & zsurfvar, &             ! Model values equivalent to surface ob.
          & zsurfmask               ! Mask associated with surface variable
-      REAL(wp), DIMENSION(jpi,jpj) :: &
-         & zglam1,    &            ! Model longitudes for prof variable 1
-         & zglam2,    &            ! Model longitudes for prof variable 2
-         & zgphi1,    &            ! Model latitudes for prof variable 1
-         & zgphi2                  ! Model latitudes for prof variable 2
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
+         & zglam,    &             ! Model longitudes for prof variables
+         & zgphi                   ! Model latitudes for prof variables
 
       !-----------------------------------------------------------------------
@@ -549,35 +653,46 @@
          DO jtype = 1, nproftypes
 
+            ! Allocate local work arrays
+            ALLOCATE( zprofvar (jpi, jpj, jpk, profdataqc(jtype)%nvar) )
+            ALLOCATE( zprofmask(jpi, jpj, jpk, profdataqc(jtype)%nvar) )
+            ALLOCATE( zglam    (jpi, jpj,      profdataqc(jtype)%nvar) )
+            ALLOCATE( zgphi    (jpi, jpj,      profdataqc(jtype)%nvar) )  
+                              
+            ! Defaults which might change
+            DO jvar = 1, profdataqc(jtype)%nvar
+               zprofmask(:,:,:,jvar) = tmask(:,:,:)
+               zglam(:,:,jvar)       = glamt(:,:)
+               zgphi(:,:,jvar)       = gphit(:,:)
+            END DO
+
             SELECT CASE ( TRIM(cobstypesprof(jtype)) )
             CASE('prof')
-               zprofvar1(:,:,:) = ts(:,:,:,jp_tem,Kmm)
-               zprofvar2(:,:,:) = ts(:,:,:,jp_sal,Kmm)
-               zprofmask1(:,:,:) = tmask(:,:,:)
-               zprofmask2(:,:,:) = tmask(:,:,:)
-               zglam1(:,:) = glamt(:,:)
-               zglam2(:,:) = glamt(:,:)
-               zgphi1(:,:) = gphit(:,:)
-               zgphi2(:,:) = gphit(:,:)
+               zprofvar(:,:,:,1) = ts(:,:,:,jp_tem,Kmm)
+               zprofvar(:,:,:,2) = ts(:,:,:,jp_sal,Kmm)
             CASE('vel')
-               zprofvar1(:,:,:) = uu(:,:,:,Kmm)
-               zprofvar2(:,:,:) = vv(:,:,:,Kmm)
-               zprofmask1(:,:,:) = umask(:,:,:)
-               zprofmask2(:,:,:) = vmask(:,:,:)
-               zglam1(:,:) = glamu(:,:)
-               zglam2(:,:) = glamv(:,:)
-               zgphi1(:,:) = gphiu(:,:)
-               zgphi2(:,:) = gphiv(:,:)
+               zprofvar(:,:,:,1) = uu(:,:,:,Kmm)
+               zprofvar(:,:,:,2) = vv(:,:,:,Kmm)
+               zprofmask(:,:,:,1) = umask(:,:,:)
+               zprofmask(:,:,:,2) = vmask(:,:,:)
+               zglam(:,:,1) = glamu(:,:)
+               zglam(:,:,2) = glamv(:,:)
+               zgphi(:,:,1) = gphiu(:,:)
+               zgphi(:,:,2) = gphiv(:,:)
             CASE DEFAULT
                CALL ctl_stop( 'Unknown profile observation type '//TRIM(cobstypesprof(jtype))//' in dia_obs' )
             END SELECT
 
-            CALL obs_prof_opt( profdataqc(jtype), kstp, jpi, jpj, jpk,  &
-               &               nit000, idaystp,                         &
-               &               zprofvar1, zprofvar2,                    &
-               &               gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm),      & 
-               &               zprofmask1, zprofmask2,                  &
-               &               zglam1, zglam2, zgphi1, zgphi2,          &
-               &               nn_1dint, nn_2dint,                      &
-               &               kdailyavtypes = nn_profdavtypes )
+            DO jvar = 1, profdataqc(jtype)%nvar
+               CALL obs_prof_opt( profdataqc(jtype), kstp, jpi, jpj, jpk,  &
+                  &               nit000, idaystp, jvar,                   &
+                  &               zprofvar(:,:,:,jvar),                    &
+                  &               gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm),      & 
+                  &               zprofmask(:,:,:,jvar),                   &
+                  &               zglam(:,:,jvar), zgphi(:,:,jvar),        &
+                  &               nn_1dint, nn_2dint_default,              &
+                  &               kdailyavtypes = nn_profdavtypes )
+            END DO
+            
+            DEALLOCATE( zprofvar, zprofmask, zglam, zgphi )
 
          END DO
@@ -680,5 +795,5 @@
                   & )
 
-               CALL obs_rotvel( profdataqc(jtype), nn_2dint, zu, zv )
+               CALL obs_rotvel( profdataqc(jtype), nn_2dint_default, zu, zv )
 
                DO jo = 1, profdataqc(jtype)%nprof
@@ -896,118 +1011,118 @@
    END SUBROUTINE fin_date
    
-    SUBROUTINE obs_settypefiles( ntypes, jpmaxnfiles, jtype, ctypein, &
-       &                         cfilestype, ifiles, cobstypes, cfiles )
-
-    INTEGER, INTENT(IN) :: ntypes      ! Total number of obs types
-    INTEGER, INTENT(IN) :: jpmaxnfiles ! Maximum number of files allowed for each type
-    INTEGER, INTENT(IN) :: jtype       ! Index of the current type of obs
-    INTEGER, DIMENSION(ntypes), INTENT(INOUT) :: &
-       &                   ifiles      ! Out appended number of files for this type
-
-    CHARACTER(len=6), INTENT(IN) :: ctypein 
-    CHARACTER(len=128), DIMENSION(jpmaxnfiles), INTENT(IN) :: &
-       &                   cfilestype  ! In list of files for this obs type
-    CHARACTER(len=6), DIMENSION(ntypes), INTENT(INOUT) :: &
-       &                   cobstypes   ! Out appended list of obs types
-    CHARACTER(len=128), DIMENSION(ntypes, jpmaxnfiles), INTENT(INOUT) :: &
-       &                   cfiles      ! Out appended list of files for all types
-
-    !Local variables
-    INTEGER :: jfile
-
-    cfiles(jtype,:) = cfilestype(:)
-    cobstypes(jtype) = ctypein
-    ifiles(jtype) = 0
-    DO jfile = 1, jpmaxnfiles
-       IF ( trim(cfiles(jtype,jfile)) /= '' ) &
-                 ifiles(jtype) = ifiles(jtype) + 1
-    END DO
-
-    IF ( ifiles(jtype) == 0 ) THEN
-         CALL ctl_stop( 'Logical for observation type '//TRIM(ctypein)//   &
-            &           ' set to true but no files available to read' )
-    ENDIF
-
-    IF(lwp) THEN    
-       WRITE(numout,*) '             '//cobstypes(jtype)//' input observation file names:'
-       DO jfile = 1, ifiles(jtype)
-          WRITE(numout,*) '                '//TRIM(cfiles(jtype,jfile))
-       END DO
-    ENDIF
-
-    END SUBROUTINE obs_settypefiles
-
-    SUBROUTINE obs_setinterpopts( ntypes, jtype, ctypein,             &
-               &                  n2dint_default, n2dint_type,        &
-               &                  zavglamscl_type, zavgphiscl_type,   &
-               &                  lfp_indegs_type, lavnight_type,     &
-               &                  n2dint, zavglamscl, zavgphiscl,     &
-               &                  lfpindegs, lavnight )
-
-    INTEGER, INTENT(IN)  :: ntypes             ! Total number of obs types
-    INTEGER, INTENT(IN)  :: jtype              ! Index of the current type of obs
-    INTEGER, INTENT(IN)  :: n2dint_default     ! Default option for interpolation type
-    INTEGER, INTENT(IN)  :: n2dint_type        ! Option for interpolation type
-    REAL(wp), INTENT(IN) :: &
-       &                    zavglamscl_type, & !E/W diameter of obs footprint for this type
-       &                    zavgphiscl_type    !N/S diameter of obs footprint for this type
-    LOGICAL, INTENT(IN)  :: lfp_indegs_type    !T=> footprint in degrees, F=> in metres
-    LOGICAL, INTENT(IN)  :: lavnight_type      !T=> obs represent night time average
-    CHARACTER(len=6), INTENT(IN) :: ctypein 
-
-    INTEGER, DIMENSION(ntypes), INTENT(INOUT) :: &
-       &                    n2dint 
-    REAL(wp), DIMENSION(ntypes), INTENT(INOUT) :: &
-       &                    zavglamscl, zavgphiscl
-    LOGICAL, DIMENSION(ntypes), INTENT(INOUT) :: &
-       &                    lfpindegs, lavnight
-
-    lavnight(jtype) = lavnight_type
-
-    IF ( (n2dint_type >= 1) .AND. (n2dint_type <= 6) ) THEN
-       n2dint(jtype) = n2dint_type
-    ELSE
-       n2dint(jtype) = n2dint_default
-    ENDIF
-
-    ! For averaging observation footprints set options for size of footprint 
-    IF ( (n2dint(jtype) > 4) .AND. (n2dint(jtype) <= 6) ) THEN
-       IF ( zavglamscl_type > 0._wp ) THEN
-          zavglamscl(jtype) = zavglamscl_type
-       ELSE
-          CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
-                         'scale (zavglamscl) for observation type '//TRIM(ctypein) )      
-       ENDIF
-
-       IF ( zavgphiscl_type > 0._wp ) THEN
-          zavgphiscl(jtype) = zavgphiscl_type
-       ELSE
-          CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
-                         'scale (zavgphiscl) for observation type '//TRIM(ctypein) )      
-       ENDIF
-
-       lfpindegs(jtype) = lfp_indegs_type 
-
-    ENDIF
-
-    ! Write out info 
-    IF(lwp) THEN
-       IF ( n2dint(jtype) <= 4 ) THEN
-          WRITE(numout,*) '             '//TRIM(ctypein)// &
-             &            ' model counterparts will be interpolated horizontally'
-       ELSE IF ( n2dint(jtype) <= 6 ) THEN
-          WRITE(numout,*) '             '//TRIM(ctypein)// &
-             &            ' model counterparts will be averaged horizontally'
-          WRITE(numout,*) '             '//'    with E/W scale: ',zavglamscl(jtype)
-          WRITE(numout,*) '             '//'    with N/S scale: ',zavgphiscl(jtype)
-          IF ( lfpindegs(jtype) ) THEN
-              WRITE(numout,*) '             '//'    (in degrees)'
-          ELSE
-              WRITE(numout,*) '             '//'    (in metres)'
-          ENDIF
-       ENDIF
-    ENDIF
-
-    END SUBROUTINE obs_setinterpopts
+   SUBROUTINE obs_settypefiles( ntypes, jpmaxnfiles, ifiles, cobstypes, cfiles )
+
+      INTEGER, INTENT(IN) :: ntypes      ! Total number of obs types
+      INTEGER, INTENT(IN) :: jpmaxnfiles ! Maximum number of files allowed for each type
+      INTEGER, DIMENSION(ntypes), INTENT(OUT) :: &
+         &                   ifiles      ! Out number of files for each type
+      CHARACTER(len=8), DIMENSION(ntypes), INTENT(IN) :: &
+         &                   cobstypes   ! List of obs types
+      CHARACTER(len=128), DIMENSION(ntypes, jpmaxnfiles), INTENT(IN) :: &
+         &                   cfiles      ! List of files for all types
+
+      !Local variables
+      INTEGER :: jfile
+      INTEGER :: jtype
+
+      DO jtype = 1, ntypes
+
+         ifiles(jtype) = 0
+         DO jfile = 1, jpmaxnfiles
+            IF ( trim(cfiles(jtype,jfile)) /= '' ) &
+                      ifiles(jtype) = ifiles(jtype) + 1
+         END DO
+
+         IF ( ifiles(jtype) == 0 ) THEN
+              CALL ctl_stop( 'Logical for observation type '//TRIM(cobstypes(jtype))//   &
+                 &           ' set to true but no files available to read' )
+         ENDIF
+
+         IF(lwp) THEN    
+            WRITE(numout,*) '             '//cobstypes(jtype)//' input observation file names:'
+            DO jfile = 1, ifiles(jtype)
+               WRITE(numout,*) '                '//TRIM(cfiles(jtype,jfile))
+            END DO
+         ENDIF
+
+      END DO
+
+   END SUBROUTINE obs_settypefiles
+
+   SUBROUTINE obs_setinterpopts( ntypes, jtype, ctypein,             &
+              &                  n2dint_default, n2dint_type,        &
+              &                  ravglamscl_type, ravgphiscl_type,   &
+              &                  lfp_indegs_type, lavnight_type,     &
+              &                  n2dint, ravglamscl, ravgphiscl,     &
+              &                  lfpindegs, lavnight )
+
+      INTEGER, INTENT(IN)  :: ntypes             ! Total number of obs types
+      INTEGER, INTENT(IN)  :: jtype              ! Index of the current type of obs
+      INTEGER, INTENT(IN)  :: n2dint_default     ! Default option for interpolation type
+      INTEGER, INTENT(IN)  :: n2dint_type        ! Option for interpolation type
+      REAL(wp), INTENT(IN) :: &
+         &                    ravglamscl_type, & !E/W diameter of obs footprint for this type
+         &                    ravgphiscl_type    !N/S diameter of obs footprint for this type
+      LOGICAL, INTENT(IN)  :: lfp_indegs_type    !T=> footprint in degrees, F=> in metres
+      LOGICAL, INTENT(IN)  :: lavnight_type      !T=> obs represent night time average
+      CHARACTER(len=8), INTENT(IN) :: ctypein 
+
+      INTEGER, DIMENSION(ntypes), INTENT(INOUT) :: &
+         &                    n2dint 
+      REAL(wp), DIMENSION(ntypes), INTENT(INOUT) :: &
+         &                    ravglamscl, ravgphiscl
+      LOGICAL, DIMENSION(ntypes), INTENT(INOUT) :: &
+         &                    lfpindegs, lavnight
+
+      lavnight(jtype) = lavnight_type
+
+      IF ( (n2dint_type >= 0) .AND. (n2dint_type <= 6) ) THEN
+         n2dint(jtype) = n2dint_type
+      ELSE IF ( n2dint_type == -1 ) THEN
+         n2dint(jtype) = n2dint_default
+      ELSE
+         CALL ctl_stop(' Choice of '//TRIM(ctypein)//' horizontal (2D) interpolation method', &
+           &                    ' is not available')
+      ENDIF
+
+      ! For averaging observation footprints set options for size of footprint 
+      IF ( (n2dint(jtype) > 4) .AND. (n2dint(jtype) <= 6) ) THEN
+         IF ( ravglamscl_type > 0._wp ) THEN
+            ravglamscl(jtype) = ravglamscl_type
+         ELSE
+            CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
+                           'scale (ravglamscl) for observation type '//TRIM(ctypein) )      
+         ENDIF
+
+         IF ( ravgphiscl_type > 0._wp ) THEN
+            ravgphiscl(jtype) = ravgphiscl_type
+         ELSE
+            CALL ctl_stop( 'Incorrect value set for averaging footprint '// &
+                           'scale (ravgphiscl) for observation type '//TRIM(ctypein) )      
+         ENDIF
+
+         lfpindegs(jtype) = lfp_indegs_type 
+
+      ENDIF
+
+      ! Write out info 
+      IF(lwp) THEN
+         IF ( n2dint(jtype) <= 4 ) THEN
+            WRITE(numout,*) '             '//TRIM(ctypein)// &
+               &            ' model counterparts will be interpolated horizontally'
+         ELSE IF ( n2dint(jtype) <= 6 ) THEN
+            WRITE(numout,*) '             '//TRIM(ctypein)// &
+               &            ' model counterparts will be averaged horizontally'
+            WRITE(numout,*) '             '//'    with E/W scale: ',ravglamscl(jtype)
+            WRITE(numout,*) '             '//'    with N/S scale: ',ravgphiscl(jtype)
+            IF ( lfpindegs(jtype) ) THEN
+                WRITE(numout,*) '             '//'    (in degrees)'
+            ELSE
+                WRITE(numout,*) '             '//'    (in metres)'
+            ENDIF
+         ENDIF
+      ENDIF
+
+   END SUBROUTINE obs_setinterpopts
 
 END MODULE diaobs
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_oper.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_oper.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_oper.F90	(revision 14062)
@@ -40,9 +40,9 @@
 CONTAINS
 
-   SUBROUTINE obs_prof_opt( prodatqc, kt, kpi, kpj, kpk,          &
-      &                     kit000, kdaystp,                      &
-      &                     pvar1, pvar2, pgdept, pgdepw,         &
-      &                     pmask1, pmask2,                       &  
-      &                     plam1, plam2, pphi1, pphi2,           &
+   SUBROUTINE obs_prof_opt( prodatqc, kt, kpi, kpj, kpk, &
+      &                     kit000, kdaystp, kvar,       &
+      &                     pvar, pgdept, pgdepw,        &
+      &                     pmask,                       &  
+      &                     plam, pphi,                  &
       &                     k1dint, k2dint, kdailyavtypes )
       !!-----------------------------------------------------------------------
@@ -105,8 +105,9 @@
       INTEGER       , INTENT(in   ) ::   k2dint          ! Horizontal interpolation type (see header)
       INTEGER       , INTENT(in   ) ::   kdaystp         ! Number of time steps per day
-      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj,kpk) ::   pvar1 , pvar2    ! Model field     1 and 2
-      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj,kpk) ::   pmask1, pmask2   ! Land-sea mask   1 and 2
-      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj)     ::   plam1 , plam2    ! Model longitude 1 and 2
-      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj)     ::   pphi1 , pphi2    ! Model latitudes 1 and 2
+      INTEGER       , INTENT(in   ) ::   kvar            ! Number of variables in prodatqc
+      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj,kpk) ::   pvar             ! Model field
+      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj,kpk) ::   pmask            ! Land-sea mask
+      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj)     ::   plam             ! Model longitude
+      REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj)     ::   pphi             ! Model latitudes
       REAL(KIND=wp) , INTENT(in   ), DIMENSION(kpi,kpj,kpk) ::   pgdept, pgdepw   ! depth of T and W levels 
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL ::   kdailyavtypes             ! Types for daily averages
@@ -128,8 +129,6 @@
          & idailyavtypes
       INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: &
-         & igrdi1, &
-         & igrdi2, &
-         & igrdj1, &
-         & igrdj2
+         & igrdi, &
+         & igrdj
       INTEGER, ALLOCATABLE, DIMENSION(:) :: iv_indic
 
@@ -138,27 +137,19 @@
       REAL(KIND=wp) :: zdaystp
       REAL(KIND=wp), DIMENSION(kpk) :: &
-         & zobsmask1, &
-         & zobsmask2, &
-         & zobsk,    &
+         & zobsk,  &
          & zobs2k
       REAL(KIND=wp), DIMENSION(2,2,1) :: &
          & zweig1, &
-         & zweig2, &
          & zweig
       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: &
-         & zmask1, &
-         & zmask2, &
-         & zint1,  &
-         & zint2,  &
-         & zinm1,  &
-         & zinm2,  &
+         & zmask,  &
+         & zint,   &
+         & zinm,   &
          & zgdept, & 
          & zgdepw
       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: &
-         & zglam1, &
-         & zglam2, &
-         & zgphi1, &
-         & zgphi2
-      REAL(KIND=wp), DIMENSION(1) :: zmsk_1, zmsk_2   
+         & zglam,  &
+         & zgphi
+      REAL(KIND=wp), DIMENSION(1) :: zmsk
       REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: interp_corner
 
@@ -190,6 +181,5 @@
          IF ( idayend == 1 .OR. kt == 0 ) THEN
             DO_3D( 1, 1, 1, 1, 1, jpk )
-               prodatqc%vdmean(ji,jj,jk,1) = 0.0
-               prodatqc%vdmean(ji,jj,jk,2) = 0.0
+               prodatqc%vdmean(ji,jj,jk,kvar) = 0.0
             END_3D
          ENDIF
@@ -197,9 +187,6 @@
          DO_3D( 1, 1, 1, 1, 1, jpk )
             ! Increment field 1 for computing daily mean
-            prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) &
-               &                        + pvar1(ji,jj,jk)
-            ! Increment field 2 for computing daily mean
-            prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) &
-               &                        + pvar2(ji,jj,jk)
+            prodatqc%vdmean(ji,jj,jk,kvar) = prodatqc%vdmean(ji,jj,jk,kvar) &
+               &                           + pvar(ji,jj,jk)
          END_3D
 
@@ -210,8 +197,6 @@
             CALL FLUSH(numout)
             DO_3D( 1, 1, 1, 1, 1, jpk )
-               prodatqc%vdmean(ji,jj,jk,1) = prodatqc%vdmean(ji,jj,jk,1) &
-                  &                        * zdaystp
-               prodatqc%vdmean(ji,jj,jk,2) = prodatqc%vdmean(ji,jj,jk,2) &
-                  &                        * zdaystp
+               prodatqc%vdmean(ji,jj,jk,kvar) = prodatqc%vdmean(ji,jj,jk,kvar) &
+                  &                           * zdaystp
             END_3D
          ENDIF
@@ -221,38 +206,24 @@
       ! Get the data for interpolation
       ALLOCATE( &
-         & igrdi1(2,2,ipro),      &
-         & igrdi2(2,2,ipro),      &
-         & igrdj1(2,2,ipro),      &
-         & igrdj2(2,2,ipro),      &
-         & zglam1(2,2,ipro),      &
-         & zglam2(2,2,ipro),      &
-         & zgphi1(2,2,ipro),      &
-         & zgphi2(2,2,ipro),      &
-         & zmask1(2,2,kpk,ipro),  &
-         & zmask2(2,2,kpk,ipro),  &
-         & zint1(2,2,kpk,ipro),   &
-         & zint2(2,2,kpk,ipro),   &
-         & zgdept(2,2,kpk,ipro),  & 
-         & zgdepw(2,2,kpk,ipro)   & 
+         & igrdi(2,2,ipro),      &
+         & igrdj(2,2,ipro),      &
+         & zglam(2,2,ipro),      &
+         & zgphi(2,2,ipro),      &
+         & zmask(2,2,kpk,ipro),  &
+         & zint(2,2,kpk,ipro),   &
+         & zgdept(2,2,kpk,ipro), & 
+         & zgdepw(2,2,kpk,ipro)  & 
          & )
 
       DO jobs = prodatqc%nprofup + 1, prodatqc%nprofup + ipro
          iobs = jobs - prodatqc%nprofup
-         igrdi1(1,1,iobs) = prodatqc%mi(jobs,1)-1
-         igrdj1(1,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdi1(1,2,iobs) = prodatqc%mi(jobs,1)-1
-         igrdj1(1,2,iobs) = prodatqc%mj(jobs,1)
-         igrdi1(2,1,iobs) = prodatqc%mi(jobs,1)
-         igrdj1(2,1,iobs) = prodatqc%mj(jobs,1)-1
-         igrdi1(2,2,iobs) = prodatqc%mi(jobs,1)
-         igrdj1(2,2,iobs) = prodatqc%mj(jobs,1)
-         igrdi2(1,1,iobs) = prodatqc%mi(jobs,2)-1
-         igrdj2(1,1,iobs) = prodatqc%mj(jobs,2)-1
-         igrdi2(1,2,iobs) = prodatqc%mi(jobs,2)-1
-         igrdj2(1,2,iobs) = prodatqc%mj(jobs,2)
-         igrdi2(2,1,iobs) = prodatqc%mi(jobs,2)
-         igrdj2(2,1,iobs) = prodatqc%mj(jobs,2)-1
-         igrdi2(2,2,iobs) = prodatqc%mi(jobs,2)
-         igrdj2(2,2,iobs) = prodatqc%mj(jobs,2)
+         igrdi(1,1,iobs) = prodatqc%mi(jobs,kvar)-1
+         igrdj(1,1,iobs) = prodatqc%mj(jobs,kvar)-1
+         igrdi(1,2,iobs) = prodatqc%mi(jobs,kvar)-1
+         igrdj(1,2,iobs) = prodatqc%mj(jobs,kvar)
+         igrdi(2,1,iobs) = prodatqc%mi(jobs,kvar)
+         igrdj(2,1,iobs) = prodatqc%mj(jobs,kvar)-1
+         igrdi(2,2,iobs) = prodatqc%mi(jobs,kvar)
+         igrdj(2,2,iobs) = prodatqc%mj(jobs,kvar)
       END DO
 
@@ -261,29 +232,19 @@
       zgdepw(:,:,:,:) = 0.0
 
-      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi1, igrdj1, plam1, zglam1 )
-      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi1, igrdj1, pphi1, zgphi1 )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, pmask1, zmask1 )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, pvar1,   zint1 )
-      
-      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi2, igrdj2, plam2, zglam2 )
-      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi2, igrdj2, pphi2, zgphi2 )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi2, igrdj2, pmask2, zmask2 )
-      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi2, igrdj2, pvar2,   zint2 )
-
-      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, pgdept, zgdept ) 
-      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, pgdepw, zgdepw ) 
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi, igrdj, plam, zglam )
+      CALL obs_int_comm_2d( 2, 2, ipro, kpi, kpj, igrdi, igrdj, pphi, zgphi )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, pmask, zmask )
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, pvar,   zint )
+
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, pgdept, zgdept ) 
+      CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, pgdepw, zgdepw ) 
 
       ! At the end of the day also get interpolated means
       IF ( ld_dailyav .AND. idayend == 0 ) THEN
 
-         ALLOCATE( &
-            & zinm1(2,2,kpk,ipro),  &
-            & zinm2(2,2,kpk,ipro)   &
-            & )
-
-         CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi1, igrdj1, &
-            &                  prodatqc%vdmean(:,:,:,1), zinm1 )
-         CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi2, igrdj2, &
-            &                  prodatqc%vdmean(:,:,:,2), zinm2 )
+         ALLOCATE( zinm(2,2,kpk,ipro) )
+
+         CALL obs_int_comm_3d( 2, 2, ipro, kpi, kpj, kpk, igrdi, igrdj, &
+            &                  prodatqc%vdmean(:,:,:,kvar), zinm )
 
       ENDIF
@@ -320,21 +281,13 @@
          ! Horizontal weights 
          ! Masked values are calculated later.  
-         IF ( prodatqc%npvend(jobs,1) > 0 ) THEN
+         IF ( prodatqc%npvend(jobs,kvar) > 0 ) THEN
 
             CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,     &
-               &                   zglam1(:,:,iobs), zgphi1(:,:,iobs), &
-               &                   zmask1(:,:,1,iobs), zweig1, zmsk_1 )
-
-         ENDIF
-
-         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
-
-            CALL obs_int_h2d_init( 1, 1, k2dint, zlam, zphi,     &
-               &                   zglam2(:,:,iobs), zgphi2(:,:,iobs), &
-               &                   zmask2(:,:,1,iobs), zweig2, zmsk_2)
- 
-         ENDIF
-
-         IF ( prodatqc%npvend(jobs,1) > 0 ) THEN
+               &                   zglam(:,:,iobs), zgphi(:,:,iobs), &
+               &                   zmask(:,:,1,iobs), zweig1, zmsk )
+
+         ENDIF
+
+         IF ( prodatqc%npvend(jobs,kvar) > 0 ) THEN
 
             zobsk(:) = obfillflt
@@ -346,6 +299,6 @@
 
                   ! vertically interpolate all 4 corners 
-                  ista = prodatqc%npvsta(jobs,1) 
-                  iend = prodatqc%npvend(jobs,1) 
+                  ista = prodatqc%npvsta(jobs,kvar) 
+                  iend = prodatqc%npvend(jobs,kvar) 
                   inum_obs = iend - ista + 1 
                   ALLOCATE(interp_corner(2,2,inum_obs),iv_indic(inum_obs)) 
@@ -356,20 +309,20 @@
                         IF ( k1dint == 1 ) THEN 
                            CALL obs_int_z1d_spl( kpk, & 
-                              &     zinm1(iin,ijn,:,iobs), & 
+                              &     zinm(iin,ijn,:,iobs), & 
                               &     zobs2k, zgdept(iin,ijn,:,iobs), & 
-                              &     zmask1(iin,ijn,:,iobs)) 
+                              &     zmask(iin,ijn,:,iobs)) 
                         ENDIF 
        
                         CALL obs_level_search(kpk, & 
                            &    zgdept(iin,ijn,:,iobs), & 
-                           &    inum_obs, prodatqc%var(1)%vdep(ista:iend), & 
+                           &    inum_obs, prodatqc%var(kvar)%vdep(ista:iend), & 
                            &    iv_indic) 
 
                         CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs, & 
-                           &    prodatqc%var(1)%vdep(ista:iend), & 
-                           &    zinm1(iin,ijn,:,iobs), & 
+                           &    prodatqc%var(kvar)%vdep(ista:iend), & 
+                           &    zinm(iin,ijn,:,iobs), & 
                            &    zobs2k, interp_corner(iin,ijn,:), & 
                            &    zgdept(iin,ijn,:,iobs), & 
-                           &    zmask1(iin,ijn,:,iobs)) 
+                           &    zmask(iin,ijn,:,iobs)) 
        
                      ENDDO 
@@ -383,6 +336,6 @@
      
                ! vertically interpolate all 4 corners 
-               ista = prodatqc%npvsta(jobs,1) 
-               iend = prodatqc%npvend(jobs,1) 
+               ista = prodatqc%npvsta(jobs,kvar) 
+               iend = prodatqc%npvend(jobs,kvar) 
                inum_obs = iend - ista + 1 
                ALLOCATE(interp_corner(2,2,inum_obs), iv_indic(inum_obs)) 
@@ -392,7 +345,7 @@
                      IF ( k1dint == 1 ) THEN 
                         CALL obs_int_z1d_spl( kpk, & 
-                           &    zint1(iin,ijn,:,iobs),& 
+                           &    zint(iin,ijn,:,iobs),& 
                            &    zobs2k, zgdept(iin,ijn,:,iobs), & 
-                           &    zmask1(iin,ijn,:,iobs)) 
+                           &    zmask(iin,ijn,:,iobs)) 
   
                      ENDIF 
@@ -400,13 +353,13 @@
                      CALL obs_level_search(kpk, & 
                          &        zgdept(iin,ijn,:,iobs),& 
-                         &        inum_obs, prodatqc%var(1)%vdep(ista:iend), & 
+                         &        inum_obs, prodatqc%var(kvar)%vdep(ista:iend), & 
                          &        iv_indic) 
 
                      CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs,     & 
-                         &          prodatqc%var(1)%vdep(ista:iend),     & 
-                         &          zint1(iin,ijn,:,iobs),            & 
+                         &          prodatqc%var(kvar)%vdep(ista:iend),     & 
+                         &          zint(iin,ijn,:,iobs),            & 
                          &          zobs2k,interp_corner(iin,ijn,:), & 
                          &          zgdept(iin,ijn,:,iobs),         & 
-                         &          zmask1(iin,ijn,:,iobs) )      
+                         &          zmask(iin,ijn,:,iobs) )      
          
                   ENDDO 
@@ -432,17 +385,17 @@
                   DO ijn=1,2 
      
-                     depth_loop1: DO ik=kpk,2,-1 
-                        IF(zmask1(iin,ijn,ik-1,iobs ) > 0.9 )THEN   
+                     depth_loop: DO ik=kpk,2,-1 
+                        IF(zmask(iin,ijn,ik-1,iobs ) > 0.9 )THEN   
                             
                            zweig(iin,ijn,1) = &  
                               & zweig1(iin,ijn,1) * & 
                               & MAX( SIGN(1._wp,(zgdepw(iin,ijn,ik,iobs) ) & 
-                              &  - prodatqc%var(1)%vdep(iend)),0._wp) 
+                              &  - prodatqc%var(kvar)%vdep(iend)),0._wp) 
                             
-                           EXIT depth_loop1 
+                           EXIT depth_loop 
 
                         ENDIF 
 
-                     ENDDO depth_loop1 
+                     ENDDO depth_loop
      
                   ENDDO 
@@ -450,9 +403,9 @@
    
                CALL obs_int_h2d( 1, 1, zweig, interp_corner(:,:,ikn), & 
-                  &              prodatqc%var(1)%vmod(iend:iend) ) 
+                  &              prodatqc%var(kvar)%vmod(iend:iend) ) 
 
                   ! Set QC flag for any observations found below the bottom
                   ! needed as the check here is more strict than that in obs_prep
-               IF (sum(zweig) == 0.0_wp) prodatqc%var(1)%nvqc(iend:iend)=4
+               IF (sum(zweig) == 0.0_wp) prodatqc%var(kvar)%nvqc(iend:iend)=4
  
             ENDDO 
@@ -460,149 +413,16 @@
             DEALLOCATE(interp_corner,iv_indic) 
           
-         ENDIF 
-
-         ! For the second variable
-         IF ( prodatqc%npvend(jobs,2) > 0 ) THEN
-
-            zobsk(:) = obfillflt
-
-            IF ( ANY (idailyavtypes(:) == prodatqc%ntyp(jobs)) ) THEN
-
-               IF ( idayend == 0 )  THEN
-                  ! Daily averaged data
-
-                  ! vertically interpolate all 4 corners 
-                  ista = prodatqc%npvsta(jobs,2) 
-                  iend = prodatqc%npvend(jobs,2) 
-                  inum_obs = iend - ista + 1 
-                  ALLOCATE(interp_corner(2,2,inum_obs),iv_indic(inum_obs)) 
-
-                  DO iin=1,2 
-                     DO ijn=1,2 
-
-                        IF ( k1dint == 1 ) THEN 
-                           CALL obs_int_z1d_spl( kpk, & 
-                              &     zinm2(iin,ijn,:,iobs), & 
-                              &     zobs2k, zgdept(iin,ijn,:,iobs), & 
-                              &     zmask2(iin,ijn,:,iobs)) 
-                        ENDIF 
-       
-                        CALL obs_level_search(kpk, & 
-                           &    zgdept(iin,ijn,:,iobs), & 
-                           &    inum_obs, prodatqc%var(2)%vdep(ista:iend), & 
-                           &    iv_indic) 
-
-                        CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs, & 
-                           &    prodatqc%var(2)%vdep(ista:iend), & 
-                           &    zinm2(iin,ijn,:,iobs), & 
-                           &    zobs2k, interp_corner(iin,ijn,:), & 
-                           &    zgdept(iin,ijn,:,iobs), & 
-                           &    zmask2(iin,ijn,:,iobs)) 
-       
-                     ENDDO 
-                  ENDDO 
-
-               ENDIF !idayend
-
-            ELSE   
-
-               ! Point data 
-     
-               ! vertically interpolate all 4 corners 
-               ista = prodatqc%npvsta(jobs,2) 
-               iend = prodatqc%npvend(jobs,2) 
-               inum_obs = iend - ista + 1 
-               ALLOCATE(interp_corner(2,2,inum_obs), iv_indic(inum_obs)) 
-               DO iin=1,2  
-                  DO ijn=1,2 
-                    
-                     IF ( k1dint == 1 ) THEN 
-                        CALL obs_int_z1d_spl( kpk, & 
-                           &    zint2(iin,ijn,:,iobs),& 
-                           &    zobs2k, zgdept(iin,ijn,:,iobs), & 
-                           &    zmask2(iin,ijn,:,iobs)) 
-  
-                     ENDIF 
-       
-                     CALL obs_level_search(kpk, & 
-                         &        zgdept(iin,ijn,:,iobs),& 
-                         &        inum_obs, prodatqc%var(2)%vdep(ista:iend), & 
-                         &        iv_indic) 
-
-                     CALL obs_int_z1d(kpk, iv_indic, k1dint, inum_obs,     & 
-                         &          prodatqc%var(2)%vdep(ista:iend),     & 
-                         &          zint2(iin,ijn,:,iobs),            & 
-                         &          zobs2k,interp_corner(iin,ijn,:), & 
-                         &          zgdept(iin,ijn,:,iobs),         & 
-                         &          zmask2(iin,ijn,:,iobs) )      
-         
-                  ENDDO 
-               ENDDO 
-             
-            ENDIF 
-
-            !------------------------------------------------------------- 
-            ! Compute the horizontal interpolation for every profile level 
-            !------------------------------------------------------------- 
-             
-            DO ikn=1,inum_obs 
-               iend=ista+ikn-1
-                  
-               zweig(:,:,1) = 0._wp 
-   
-               ! This code forces the horizontal weights to be  
-               ! zero IF the observation is below the bottom of the  
-               ! corners of the interpolation nodes, Or if it is in  
-               ! the mask. This is important for observations near  
-               ! steep bathymetry 
-               DO iin=1,2 
-                  DO ijn=1,2 
-     
-                     depth_loop2: DO ik=kpk,2,-1 
-                        IF(zmask2(iin,ijn,ik-1,iobs ) > 0.9 )THEN   
-                            
-                           zweig(iin,ijn,1) = &  
-                              & zweig2(iin,ijn,1) * & 
-                              & MAX( SIGN(1._wp,(zgdepw(iin,ijn,ik,iobs) ) & 
-                              &  - prodatqc%var(2)%vdep(iend)),0._wp) 
-                            
-                           EXIT depth_loop2 
-
-                        ENDIF 
-
-                     ENDDO depth_loop2 
-     
-                  ENDDO 
-               ENDDO 
-   
-               CALL obs_int_h2d( 1, 1, zweig, interp_corner(:,:,ikn), & 
-                  &              prodatqc%var(2)%vmod(iend:iend) ) 
-
-                  ! Set QC flag for any observations found below the bottom
-                  ! needed as the check here is more strict than that in obs_prep
-               IF (sum(zweig) == 0.0_wp) prodatqc%var(2)%nvqc(iend:iend)=4
- 
-            ENDDO 
- 
-            DEALLOCATE(interp_corner,iv_indic) 
-          
-         ENDIF 
+         ENDIF
 
       ENDDO
 
       ! Deallocate the data for interpolation
-      DEALLOCATE( &
-         & igrdi1, &
-         & igrdi2, &
-         & igrdj1, &
-         & igrdj2, &
-         & zglam1, &
-         & zglam2, &
-         & zgphi1, &
-         & zgphi2, &
-         & zmask1, &
-         & zmask2, &
-         & zint1,  &
-         & zint2,  &
+      DEALLOCATE(  &
+         & igrdi,  &
+         & igrdj,  &
+         & zglam,  &
+         & zgphi,  &
+         & zmask,  &
+         & zint,   &
          & zgdept, &
          & zgdepw  &
@@ -611,11 +431,10 @@
       ! At the end of the day also get interpolated means
       IF ( ld_dailyav .AND. idayend == 0 ) THEN
-         DEALLOCATE( &
-            & zinm1,  &
-            & zinm2   &
-            & )
+         DEALLOCATE( zinm )
       ENDIF
 
-      prodatqc%nprofup = prodatqc%nprofup + ipro 
+      IF ( kvar == prodatqc%nvar ) THEN
+         prodatqc%nprofup = prodatqc%nprofup + ipro 
+      ENDIF
 
    END SUBROUTINE obs_prof_opt
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_prep.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_prep.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_prep.F90	(revision 14062)
@@ -241,7 +241,7 @@
 
 
-   SUBROUTINE obs_pre_prof( profdata, prodatqc, ld_var1, ld_var2, &
+   SUBROUTINE obs_pre_prof( profdata, prodatqc, ld_var, &
       &                     kpi, kpj, kpk, &
-      &                     zmask1, pglam1, pgphi1, zmask2, pglam2, pgphi2,  &
+      &                     zmask, pglam, pgphi,  &
       &                     ld_nea, ld_bound_reject, Kmm, kdailyavtypes,  kqc_cutoff )
 
@@ -269,6 +269,6 @@
       TYPE(obs_prof), INTENT(INOUT) :: profdata   ! Full set of profile data
       TYPE(obs_prof), INTENT(INOUT) :: prodatqc   ! Subset of profile data not failing screening
-      LOGICAL, INTENT(IN) :: ld_var1              ! Observed variables switches
-      LOGICAL, INTENT(IN) :: ld_var2
+      LOGICAL, DIMENSION(profdata%nvar), INTENT(IN) :: &
+         & ld_var                                 ! Observed variables switches
       LOGICAL, INTENT(IN) :: ld_nea               ! Switch for rejecting observation near land
       LOGICAL, INTENT(IN) :: ld_bound_reject      ! Switch for rejecting observations near the boundary
@@ -277,12 +277,9 @@
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
          & kdailyavtypes                          ! Types for daily averages
-      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj,kpk) :: &
-         & zmask1, &
-         & zmask2
-      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj) :: &
-         & pglam1, &
-         & pglam2, &
-         & pgphi1, &
-         & pgphi2
+      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj,kpk,profdata%nvar) :: &
+         & zmask
+      REAL(wp), INTENT(IN), DIMENSION(kpi,kpj,profdata%nvar) :: &
+         & pglam, &
+         & pgphi
       INTEGER, INTENT(IN), OPTIONAL :: kqc_cutoff   ! cut off for QC value
 
@@ -295,37 +292,31 @@
       INTEGER :: imin0
       INTEGER :: icycle       ! Current assimilation cycle
-                              ! Counters for observations that are
-      INTEGER :: iotdobs      !  - outside time domain
-      INTEGER :: iosdv1obs    !  - outside space domain (variable 1)
-      INTEGER :: iosdv2obs    !  - outside space domain (variable 2)
-      INTEGER :: ilanv1obs    !  - within a model land cell (variable 1)
-      INTEGER :: ilanv2obs    !  - within a model land cell (variable 2)
-      INTEGER :: inlav1obs    !  - close to land (variable 1)
-      INTEGER :: inlav2obs    !  - close to land (variable 2)
-      INTEGER :: ibdyv1obs    !  - boundary (variable 1) 
-      INTEGER :: ibdyv2obs    !  - boundary (variable 2)      
-      INTEGER :: igrdobs      !  - fail the grid search
-      INTEGER :: iuvchku      !  - reject u if v rejected and vice versa
-      INTEGER :: iuvchkv      !
-                              ! Global counters for observations that are
-      INTEGER :: iotdobsmpp   !  - outside time domain
-      INTEGER :: iosdv1obsmpp !  - outside space domain (variable 1)
-      INTEGER :: iosdv2obsmpp !  - outside space domain (variable 2)
-      INTEGER :: ilanv1obsmpp !  - within a model land cell (variable 1)
-      INTEGER :: ilanv2obsmpp !  - within a model land cell (variable 2)
-      INTEGER :: inlav1obsmpp !  - close to land (variable 1)
-      INTEGER :: inlav2obsmpp !  - close to land (variable 2)
-      INTEGER :: ibdyv1obsmpp !  - boundary (variable 1) 
-      INTEGER :: ibdyv2obsmpp !  - boundary (variable 2)      
-      INTEGER :: igrdobsmpp   !  - fail the grid search
-      INTEGER :: iuvchkumpp   !  - reject var1 if var2 rejected and vice versa
-      INTEGER :: iuvchkvmpp   !
+                                                       ! Counters for observations that are
+      INTEGER                           :: iotdobs     !  - outside time domain
+      INTEGER, DIMENSION(profdata%nvar) :: iosdvobs    !  - outside space domain
+      INTEGER, DIMENSION(profdata%nvar) :: ilanvobs    !  - within a model land cell
+      INTEGER, DIMENSION(profdata%nvar) :: inlavobs    !  - close to land
+      INTEGER, DIMENSION(profdata%nvar) :: ibdyvobs    !  - boundary   
+      INTEGER                           :: igrdobs     !  - fail the grid search
+      INTEGER                           :: iuvchku     !  - reject UVEL if VVEL rejected
+      INTEGER                           :: iuvchkv     !  - reject VVEL if UVEL rejected
+                                                       ! Global counters for observations that are
+      INTEGER                           :: iotdobsmpp  !  - outside time domain
+      INTEGER, DIMENSION(profdata%nvar) :: iosdvobsmpp !  - outside space domain
+      INTEGER, DIMENSION(profdata%nvar) :: ilanvobsmpp !  - within a model land cell
+      INTEGER, DIMENSION(profdata%nvar) :: inlavobsmpp !  - close to land
+      INTEGER, DIMENSION(profdata%nvar) :: ibdyvobsmpp !  - boundary
+      INTEGER :: igrdobsmpp                            !  - fail the grid search
+      INTEGER :: iuvchkumpp                            !  - reject UVEL if VVEL rejected
+      INTEGER :: iuvchkvmpp                            !  - reject VVEL if UVEL rejected
       TYPE(obs_prof_valid) ::  llvalid      ! Profile selection 
       TYPE(obs_prof_valid), DIMENSION(profdata%nvar) :: &
-         & llvvalid           ! var1,var2 selection 
+         & llvvalid           ! var selection 
       INTEGER :: jvar         ! Variable loop variable
       INTEGER :: jobs         ! Obs. loop variable
       INTEGER :: jstp         ! Time loop variable
       INTEGER :: inrc         ! Time index variable
+      CHARACTER(LEN=256) :: cout1  ! Diagnostic output line
+      CHARACTER(LEN=256) :: cout2  ! Diagnostic output line
       !!----------------------------------------------------------------------
 
@@ -342,18 +333,14 @@
       icycle = nn_no     ! Assimilation cycle
 
-      ! Diagnotics counters for various failures.
-
-      iotdobs   = 0
-      igrdobs   = 0
-      iosdv1obs = 0
-      iosdv2obs = 0
-      ilanv1obs = 0
-      ilanv2obs = 0
-      inlav1obs = 0
-      inlav2obs = 0
-      ibdyv1obs = 0
-      ibdyv2obs = 0
-      iuvchku   = 0
-      iuvchkv   = 0
+      ! Diagnostic counters for various failures.
+
+      iotdobs     = 0
+      igrdobs     = 0
+      iosdvobs(:) = 0
+      ilanvobs(:) = 0
+      inlavobs(:) = 0
+      ibdyvobs(:) = 0
+      iuvchku     = 0
+      iuvchkv     = 0
 
 
@@ -388,8 +375,8 @@
       ! -----------------------------------------------------------------------
 
-      CALL obs_coo_grd( profdata%nprof,   profdata%mi(:,1), profdata%mj(:,1), &
-         &              profdata%nqc,     igrdobs                         )
-      CALL obs_coo_grd( profdata%nprof,   profdata%mi(:,2), profdata%mj(:,2), &
-         &              profdata%nqc,     igrdobs                         )
+      DO jvar = 1, profdata%nvar
+         CALL obs_coo_grd( profdata%nprof,   profdata%mi(:,jvar), profdata%mj(:,jvar), &
+            &              profdata%nqc,     igrdobs                         )
+      END DO
 
       CALL obs_mpp_sum_integer( igrdobs, igrdobsmpp )
@@ -406,47 +393,26 @@
       ! -----------------------------------------------------------------------
 
-      ! Variable 1
-      CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(1),   &
-         &                 profdata%npvsta(:,1),  profdata%npvend(:,1), &
-         &                 jpi,                   jpj,                  &
-         &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          &
-         &                 profdata%var(1)%mvk,                         &
-         &                 profdata%rlam,         profdata%rphi,        &
-         &                 profdata%var(1)%vdep,                        &
-         &                 pglam1,                pgphi1,               &
-         &                 gdept_1d,              zmask1,               &
-         &                 profdata%nqc,          profdata%var(1)%nvqc, &
-         &                 iosdv1obs,             ilanv1obs,            &
-         &                 inlav1obs,             ld_nea,               &
-         &                 ibdyv1obs,             ld_bound_reject,      &
-         &                 iqc_cutoff,            Kmm                 )
-
-      CALL obs_mpp_sum_integer( iosdv1obs, iosdv1obsmpp )
-      CALL obs_mpp_sum_integer( ilanv1obs, ilanv1obsmpp )
-      CALL obs_mpp_sum_integer( inlav1obs, inlav1obsmpp )
-      CALL obs_mpp_sum_integer( ibdyv1obs, ibdyv1obsmpp )
-
-      ! Variable 2
-      CALL obs_coo_spc_3d( profdata%nprof,        profdata%nvprot(2),   &
-         &                 profdata%npvsta(:,2),  profdata%npvend(:,2), &
-         &                 jpi,                   jpj,                  &
-         &                 jpk,                                         &
-         &                 profdata%mi,           profdata%mj,          & 
-         &                 profdata%var(2)%mvk,                         &
-         &                 profdata%rlam,         profdata%rphi,        &
-         &                 profdata%var(2)%vdep,                        &
-         &                 pglam2,                pgphi2,               &
-         &                 gdept_1d,              zmask2,               &
-         &                 profdata%nqc,          profdata%var(2)%nvqc, &
-         &                 iosdv2obs,             ilanv2obs,            &
-         &                 inlav2obs,             ld_nea,               &
-         &                 ibdyv2obs,             ld_bound_reject,      &
-         &                 iqc_cutoff,            Kmm                 )
-
-      CALL obs_mpp_sum_integer( iosdv2obs, iosdv2obsmpp )
-      CALL obs_mpp_sum_integer( ilanv2obs, ilanv2obsmpp )
-      CALL obs_mpp_sum_integer( inlav2obs, inlav2obsmpp )
-      CALL obs_mpp_sum_integer( ibdyv2obs, ibdyv2obsmpp )
+      DO jvar = 1, profdata%nvar
+         CALL obs_coo_spc_3d( profdata%nprof,          profdata%nvprot(jvar),   &
+            &                 profdata%npvsta(:,jvar), profdata%npvend(:,jvar), &
+            &                 jpi,                     jpj,                     &
+            &                 jpk,                                              &
+            &                 profdata%mi,             profdata%mj,             &
+            &                 profdata%var(jvar)%mvk,                           &
+            &                 profdata%rlam,           profdata%rphi,           &
+            &                 profdata%var(jvar)%vdep,                          &
+            &                 pglam(:,:,jvar),         pgphi(:,:,jvar),         &
+            &                 gdept_1d,                zmask(:,:,:,jvar),       &
+            &                 profdata%nqc,            profdata%var(jvar)%nvqc, &
+            &                 iosdvobs(jvar),          ilanvobs(jvar),          &
+            &                 inlavobs(jvar),          ld_nea,                  &
+            &                 ibdyvobs(jvar),          ld_bound_reject,         &
+            &                 iqc_cutoff,              Kmm       )
+
+         CALL obs_mpp_sum_integer( iosdvobs(jvar), iosdvobsmpp(jvar) )
+         CALL obs_mpp_sum_integer( ilanvobs(jvar), ilanvobsmpp(jvar) )
+         CALL obs_mpp_sum_integer( inlavobs(jvar), inlavobsmpp(jvar) )
+         CALL obs_mpp_sum_integer( ibdyvobs(jvar), ibdyvobsmpp(jvar) )
+      END DO
 
       ! -----------------------------------------------------------------------
@@ -499,54 +465,44 @@
       
          WRITE(numout,*)
-         WRITE(numout,*) ' Profiles outside time domain                     = ', &
+         WRITE(numout,*) ' Profiles outside time domain                       = ', &
             &            iotdobsmpp
-         WRITE(numout,*) ' Remaining profiles that failed grid search       = ', &
+         WRITE(numout,*) ' Remaining profiles that failed grid search         = ', &
             &            igrdobsmpp
-         WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data outside space domain       = ', &
-            &            iosdv1obsmpp
-         WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data at land points             = ', &
-            &            ilanv1obsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data near land points (removed) = ',&
-               &            inlav1obsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data near land points (kept)    = ',&
-               &            inlav1obsmpp
-         ENDIF
-         IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
-            WRITE(numout,*) ' U observation rejected since V rejected     = ', &
-               &            iuvchku
-         ENDIF
-         WRITE(numout,*) ' Remaining '//prodatqc%cvars(1)//' data near open boundary (removed) = ',&
-               &            ibdyv1obsmpp
-         WRITE(numout,*) ' '//prodatqc%cvars(1)//' data accepted                             = ', &
-            &            prodatqc%nvprotmpp(1)
-         WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data outside space domain       = ', &
-            &            iosdv2obsmpp
-         WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data at land points             = ', &
-            &            ilanv2obsmpp
-         IF (ld_nea) THEN
-            WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data near land points (removed) = ',&
-               &            inlav2obsmpp
-         ELSE
-            WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data near land points (kept)    = ',&
-               &            inlav2obsmpp
-         ENDIF
-         IF ( TRIM(profdata%cvars(1)) == 'UVEL' ) THEN
-            WRITE(numout,*) ' V observation rejected since U rejected     = ', &
-               &            iuvchkv
-         ENDIF
-         WRITE(numout,*) ' Remaining '//prodatqc%cvars(2)//' data near open boundary (removed) = ',&
-               &            ibdyv2obsmpp
-         WRITE(numout,*) ' '//prodatqc%cvars(2)//' data accepted                             = ', &
-            &            prodatqc%nvprotmpp(2)
+         DO jvar = 1, profdata%nvar
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(jvar)//' data outside space domain       = ', &
+               &            iosdvobsmpp(jvar)
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(jvar)//' data at land points             = ', &
+               &            ilanvobsmpp(jvar)
+            IF (ld_nea) THEN
+               WRITE(numout,*) ' Remaining '//prodatqc%cvars(jvar)//' data near land points (removed) = ',&
+                  &            inlavobsmpp(jvar)
+            ELSE
+               WRITE(numout,*) ' Remaining '//prodatqc%cvars(jvar)//' data near land points (kept)    = ',&
+                  &            inlavobsmpp(jvar)
+            ENDIF
+            IF ( TRIM(profdata%cvars(jvar)) == 'UVEL' ) THEN
+               WRITE(numout,*) ' U observation rejected since V rejected     = ', &
+                  &            iuvchku
+            ELSE IF ( TRIM(profdata%cvars(jvar)) == 'VVEL' ) THEN
+               WRITE(numout,*) ' V observation rejected since U rejected     = ', &
+                  &            iuvchkv
+            ENDIF
+            WRITE(numout,*) ' Remaining '//prodatqc%cvars(jvar)//' data near open boundary (removed) = ',&
+                  &            ibdyvobsmpp(jvar)
+            WRITE(numout,*) ' '//prodatqc%cvars(jvar)//' data accepted                             = ', &
+               &            prodatqc%nvprotmpp(jvar)
+         END DO
 
          WRITE(numout,*)
          WRITE(numout,*) ' Number of observations per time step :'
          WRITE(numout,*)
-         WRITE(numout,'(10X,A,5X,A,5X,A,A)')'Time step','Profiles', &
-            &                               '     '//prodatqc%cvars(1)//'     ', &
-            &                               '     '//prodatqc%cvars(2)//'     '
-         WRITE(numout,998)
+         WRITE(cout1,'(10X,A9,5X,A8)') 'Time step', 'Profiles'
+         WRITE(cout2,'(10X,A9,5X,A8)') '---------', '--------'
+         DO jvar = 1, prodatqc%nvar
+            WRITE(cout1,'(A,5X,A11)') TRIM(cout1), TRIM(prodatqc%cvars(jvar))
+            WRITE(cout2,'(A,5X,A11)') TRIM(cout2), '-----------'
+         END DO
+         WRITE(numout,*) cout1
+         WRITE(numout,*) cout2
       ENDIF
       
@@ -575,12 +531,11 @@
          DO jstp = nit000 - 1, nitend
             inrc = jstp - nit000 + 2
-            WRITE(numout,999) jstp, prodatqc%npstpmpp(inrc), &
-               &                    prodatqc%nvstpmpp(inrc,1), &
-               &                    prodatqc%nvstpmpp(inrc,2)
+            WRITE(cout1,'(10X,I9,5X,I8)') jstp, prodatqc%npstpmpp(inrc)
+            DO jvar = 1, prodatqc%nvar
+               WRITE(cout1,'(A,5X,I11)') TRIM(cout1), prodatqc%nvstpmpp(inrc,jvar)
+            END DO
+            WRITE(numout,*) cout1
          END DO
       ENDIF
-
-998   FORMAT(10X,'---------',5X,'--------',5X,'-----------',5X,'----------------')
-999   FORMAT(10X,I9,5X,I8,5X,I11,5X,I8)
 
    END SUBROUTINE obs_pre_prof
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_read_prof.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_read_prof.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_read_prof.F90	(revision 14062)
@@ -45,6 +45,6 @@
    SUBROUTINE obs_rea_prof( profdata, knumfiles, cdfilenames, &
       &                     kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                     ldvar1, ldvar2, ldignmis, ldsatt, &
-      &                     ldmod, kdailyavtypes )
+      &                     ldvar, ldignmis, ldsatt, &
+      &                     ldmod, cdvars, kdailyavtypes )
       !!---------------------------------------------------------------------
       !!
@@ -74,6 +74,5 @@
       INTEGER, INTENT(IN) :: kextr      ! Number of extra fields for each var
       INTEGER, INTENT(IN) :: kstp       ! Ocean time-step index
-      LOGICAL, INTENT(IN) :: ldvar1     ! Observed variables switches
-      LOGICAL, INTENT(IN) :: ldvar2
+      LOGICAL, DIMENSION(kvars), INTENT(IN) :: ldvar     ! Observed variables switches
       LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
       LOGICAL, INTENT(IN) :: ldsatt     ! Compute salinity at all temperature points
@@ -81,4 +80,5 @@
       REAL(dp), INTENT(IN) :: ddobsini  ! Obs. ini time in YYYYMMDD.HHMMSS
       REAL(dp), INTENT(IN) :: ddobsend  ! Obs. end time in YYYYMMDD.HHMMSS
+      CHARACTER(len=8), DIMENSION(kvars), INTENT(IN) :: cdvars
       INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
          & kdailyavtypes                ! Types of daily average observations
@@ -87,5 +87,5 @@
       CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_prof'
       CHARACTER(len=8) :: clrefdate
-      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: clvars
+      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: clvarsin
       INTEGER :: jvar
       INTEGER :: ji
@@ -105,29 +105,22 @@
       INTEGER :: iprof
       INTEGER :: iproftot
-      INTEGER :: ivar1t0
-      INTEGER :: ivar2t0
-      INTEGER :: ivar1t
-      INTEGER :: ivar2t
+      INTEGER, DIMENSION(kvars) :: ivart0
+      INTEGER, DIMENSION(kvars) :: ivart
       INTEGER :: ip3dt
       INTEGER :: ios
       INTEGER :: ioserrcount
-      INTEGER :: ivar1tmpp
-      INTEGER :: ivar2tmpp
+      INTEGER, DIMENSION(kvars) :: ivartmpp
       INTEGER :: ip3dtmpp
       INTEGER :: itype
       INTEGER, DIMENSION(knumfiles) :: &
          & irefdate
-      INTEGER, DIMENSION(ntyp1770+1) :: &
-         & itypvar1,    &
-         & itypvar1mpp, &
-         & itypvar2,    &
-         & itypvar2mpp 
+      INTEGER, DIMENSION(ntyp1770+1,kvars) :: &
+         & itypvar,    &
+         & itypvarmpp
+      INTEGER, DIMENSION(:,:), ALLOCATABLE :: &
+         & iobsi,    &
+         & iobsj,    &
+         & iproc
       INTEGER, DIMENSION(:), ALLOCATABLE :: &
-         & iobsi1,    &
-         & iobsj1,    &
-         & iproc1,    &
-         & iobsi2,    &
-         & iobsj2,    &
-         & iproc2,    &
          & iindx,    &
          & ifileidx, &
@@ -147,4 +140,5 @@
       LOGICAL :: llvalprof
       LOGICAL :: lldavtimset
+      LOGICAL :: llcycle
       TYPE(obfbdata), POINTER, DIMENSION(:) :: &
          & inpfiles
@@ -152,6 +146,5 @@
       ! Local initialization
       iprof = 0
-      ivar1t0 = 0
-      ivar2t0 = 0
+      ivart0(:) = 0
       ip3dt = 0
 
@@ -219,7 +212,7 @@
                &                ldgrid = .TRUE. )
 
-            IF ( inpfiles(jj)%nvar < 2 ) THEN
+            IF ( inpfiles(jj)%nvar /= kvars ) THEN
                CALL ctl_stop( 'Feedback format error: ', &
-                  &           ' less than 2 vars in profile file' )
+                  &           ' unexpected number of vars in profile file' )
             ENDIF
 
@@ -229,11 +222,15 @@
 
             IF ( jj == 1 ) THEN
-               ALLOCATE( clvars( inpfiles(jj)%nvar ) )
+               ALLOCATE( clvarsin( inpfiles(jj)%nvar ) )
                DO ji = 1, inpfiles(jj)%nvar
-                 clvars(ji) = inpfiles(jj)%cname(ji)
+                 clvarsin(ji) = inpfiles(jj)%cname(ji)
+                 IF ( clvarsin(ji) /= cdvars(ji) ) THEN
+                    CALL ctl_stop( 'Feedback file variables do not match', &
+                        &           ' expected variable names for this type' )
+                 ENDIF
                END DO
             ELSE
                DO ji = 1, inpfiles(jj)%nvar
-                  IF ( inpfiles(jj)%cname(ji) /= clvars(ji) ) THEN
+                  IF ( inpfiles(jj)%cname(ji) /= clvarsin(ji) ) THEN
                      CALL ctl_stop( 'Feedback file variables not consistent', &
                         &           ' with previous files for this type' )
@@ -308,6 +305,12 @@
             DO ji = 1, inpfiles(jj)%nobs
                IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+               llcycle = .TRUE.
+               DO jvar = 1, kvars
+                  IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+                     llcycle = .FALSE.
+                     EXIT
+                  ENDIF
+               END DO
+               IF ( llcycle ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -317,15 +320,18 @@
             ALLOCATE( zlam(inowin)  )
             ALLOCATE( zphi(inowin)  )
-            ALLOCATE( iobsi1(inowin) )
-            ALLOCATE( iobsj1(inowin) )
-            ALLOCATE( iproc1(inowin) )
-            ALLOCATE( iobsi2(inowin) )
-            ALLOCATE( iobsj2(inowin) )
-            ALLOCATE( iproc2(inowin) )
+            ALLOCATE( iobsi(inowin,kvars) )
+            ALLOCATE( iobsj(inowin,kvars) )
+            ALLOCATE( iproc(inowin,kvars) )
             inowin = 0
             DO ji = 1, inpfiles(jj)%nobs
                IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+               llcycle = .TRUE.
+               DO jvar = 1, kvars
+                  IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+                     llcycle = .FALSE.
+                     EXIT
+                  ENDIF
+               END DO
+               IF ( llcycle ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -336,15 +342,20 @@
             END DO
 
-            IF ( TRIM( inpfiles(jj)%cname(1) ) == 'POTM' ) THEN
-               CALL obs_grid_search( inowin, zlam, zphi, iobsi1, iobsj1, &
-                  &                  iproc1, 'T' )
-               iobsi2(:) = iobsi1(:)
-               iobsj2(:) = iobsj1(:)
-               iproc2(:) = iproc1(:)
-            ELSEIF ( TRIM( inpfiles(jj)%cname(1) ) == 'UVEL' ) THEN
-               CALL obs_grid_search( inowin, zlam, zphi, iobsi1, iobsj1, &
-                  &                  iproc1, 'U' )
-               CALL obs_grid_search( inowin, zlam, zphi, iobsi2, iobsj2, &
-                  &                  iproc2, 'V' )
+            ! Assume anything other than velocity is on T grid
+            IF ( TRIM( inpfiles(jj)%cname(1) ) == 'UVEL' ) THEN
+               CALL obs_grid_search( inowin, zlam, zphi, iobsi(:,1), iobsj(:,1), &
+                  &                  iproc(:,1), 'U' )
+               CALL obs_grid_search( inowin, zlam, zphi, iobsi(:,2), iobsj(:,2), &
+                  &                  iproc(:,2), 'V' )
+            ELSE
+               CALL obs_grid_search( inowin, zlam, zphi, iobsi(:,1), iobsj(:,1), &
+                  &                  iproc(:,1), 'T' )
+               IF ( kvars > 1 ) THEN
+                  DO jvar = 2, kvars
+                     iobsi(:,jvar) = iobsi(:,1)
+                     iobsj(:,jvar) = iobsj(:,1)
+                     iproc(:,jvar) = iproc(:,1)
+                  END DO
+               ENDIF
             ENDIF
 
@@ -352,28 +363,43 @@
             DO ji = 1, inpfiles(jj)%nobs
                IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+               llcycle = .TRUE.
+               DO jvar = 1, kvars
+                  IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+                     llcycle = .FALSE.
+                     EXIT
+                  ENDIF
+               END DO
+               IF ( llcycle ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
                   inowin = inowin + 1
-                  inpfiles(jj)%iproc(ji,1) = iproc1(inowin)
-                  inpfiles(jj)%iobsi(ji,1) = iobsi1(inowin)
-                  inpfiles(jj)%iobsj(ji,1) = iobsj1(inowin)
-                  inpfiles(jj)%iproc(ji,2) = iproc2(inowin)
-                  inpfiles(jj)%iobsi(ji,2) = iobsi2(inowin)
-                  inpfiles(jj)%iobsj(ji,2) = iobsj2(inowin)
-                  IF ( inpfiles(jj)%iproc(ji,1) /= &
-                     & inpfiles(jj)%iproc(ji,2) ) THEN
-                     CALL ctl_stop( 'Error in obs_read_prof:', &
-                        & 'var1 and var2 observation on different processors')
+                  DO jvar = 1, kvars
+                     inpfiles(jj)%iproc(ji,jvar) = iproc(inowin,jvar)
+                     inpfiles(jj)%iobsi(ji,jvar) = iobsi(inowin,jvar)
+                     inpfiles(jj)%iobsj(ji,jvar) = iobsj(inowin,jvar)
+                  END DO
+                  IF ( kvars > 1 ) THEN
+                     DO jvar = 2, kvars
+                        IF ( inpfiles(jj)%iproc(ji,jvar) /= &
+                           & inpfiles(jj)%iproc(ji,1) ) THEN
+                           CALL ctl_stop( 'Error in obs_read_prof:', &
+                              & 'observation on different processors for different vars')
+                        ENDIF
+                     END DO
                   ENDIF
                ENDIF
             END DO
-            DEALLOCATE( zlam, zphi, iobsi1, iobsj1, iproc1, iobsi2, iobsj2, iproc2 )
+            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
 
             DO ji = 1, inpfiles(jj)%nobs
                IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-               IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-                  & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+               llcycle = .TRUE.
+               DO jvar = 1, kvars
+                  IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+                     llcycle = .FALSE.
+                     EXIT
+                  ENDIF
+               END DO
+               IF ( llcycle ) CYCLE
                IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                   & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -384,37 +410,29 @@
                   ENDIF
                   llvalprof = .FALSE.
-                  IF ( ldvar1 ) THEN
-                     loop_t_count : DO ij = 1,inpfiles(jj)%nlev
-                        IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                           & CYCLE
-                        IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
-                           & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
-                           ivar1t0 = ivar1t0 + 1
-                        ENDIF
-                     END DO loop_t_count
-                  ENDIF
-                  IF ( ldvar2 ) THEN
-                     loop_s_count : DO ij = 1,inpfiles(jj)%nlev
-                        IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
-                           & CYCLE
-                        IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
-                           & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
-                           ivar2t0 = ivar2t0 + 1
-                        ENDIF
-                     END DO loop_s_count
-                  ENDIF
-                  loop_p_count : DO ij = 1,inpfiles(jj)%nlev
+                  DO jvar = 1, kvars
+                     IF ( ldvar(jvar) ) THEN
+                        DO ij = 1,inpfiles(jj)%nlev
+                           IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
+                              & CYCLE
+                           IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,jvar),2) .AND. &
+                              & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
+                              ivart0(jvar) = ivart0(jvar) + 1
+                           ENDIF
+                        END DO
+                     ENDIF
+                  END DO
+                  DO ij = 1,inpfiles(jj)%nlev
                      IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
                         & CYCLE
-                     IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
-                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
-                        &    ldvar1 ) .OR. &
-                        & ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
-                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
-                        &     ldvar2 ) ) THEN
-                        ip3dt = ip3dt + 1
-                        llvalprof = .TRUE.
-                     ENDIF
-                  END DO loop_p_count
+                     DO jvar = 1, kvars
+                        IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,jvar),2) .AND. &
+                           &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
+                           &    ldvar(jvar) ) ) THEN
+                           ip3dt = ip3dt + 1
+                           llvalprof = .TRUE.
+                           EXIT
+                        ENDIF
+                     END DO
+                  END DO
 
                   IF ( llvalprof ) iprof = iprof + 1
@@ -438,6 +456,12 @@
          DO ji = 1, inpfiles(jj)%nobs
             IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+            llcycle = .TRUE.
+            DO jvar = 1, kvars
+               IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+                  llcycle = .FALSE.
+                  EXIT
+               ENDIF
+            END DO
+            IF ( llcycle ) CYCLE
             IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -453,6 +477,12 @@
          DO ji = 1, inpfiles(jj)%nobs
             IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+            llcycle = .TRUE.
+            DO jvar = 1, kvars
+               IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+                  llcycle = .FALSE.
+                  EXIT
+               ENDIF
+            END DO
+            IF ( llcycle ) CYCLE
             IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
                & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
@@ -470,9 +500,7 @@
       iv3dt(:) = -1
       IF (ldsatt) THEN
-         iv3dt(1) = ip3dt
-         iv3dt(2) = ip3dt
+         iv3dt(:) = ip3dt
       ELSE
-         iv3dt(1) = ivar1t0
-         iv3dt(2) = ivar2t0
+         iv3dt(:) = ivart0(:)
       ENDIF
       CALL obs_prof_alloc( profdata, kvars, kextr, iprof, iv3dt, &
@@ -483,15 +511,11 @@
       profdata%nprof     = 0
       profdata%nvprot(:) = 0
-      profdata%cvars(:)  = clvars(:)
+      profdata%cvars(:)  = clvarsin(:)
       iprof = 0
 
       ip3dt = 0
-      ivar1t = 0
-      ivar2t = 0
-      itypvar1   (:) = 0
-      itypvar1mpp(:) = 0
-
-      itypvar2   (:) = 0
-      itypvar2mpp(:) = 0
+      ivart(:) = 0
+      itypvar   (:,:) = 0
+      itypvarmpp(:,:) = 0
 
       ioserrcount = 0
@@ -501,7 +525,13 @@
          ji = iprofidx(iindx(jk))
 
-            IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+         IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
+         llcycle = .TRUE.
+         DO jvar = 1, kvars
+            IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+               llcycle = .FALSE.
+               EXIT
+            ENDIF
+         END DO
+         IF ( llcycle ) CYCLE
 
          IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
@@ -519,6 +549,12 @@
 
             IF ( BTEST(inpfiles(jj)%ioqc(ji),2 ) ) CYCLE
-            IF ( BTEST(inpfiles(jj)%ivqc(ji,1),2) .AND. &
-               & BTEST(inpfiles(jj)%ivqc(ji,2),2) ) CYCLE
+            llcycle = .TRUE.
+            DO jvar = 1, kvars
+               IF ( .NOT. ( BTEST(inpfiles(jj)%ivqc(ji,jvar),2) ) ) THEN
+                  llcycle = .FALSE.
+                  EXIT
+               ENDIF
+            END DO
+            IF ( llcycle ) CYCLE
 
             loop_prof : DO ij = 1, inpfiles(jj)%nlev
@@ -527,19 +563,13 @@
                   & CYCLE
 
-               IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
-                  & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
-
-                  llvalprof = .TRUE. 
-                  EXIT loop_prof
-
-               ENDIF
-
-               IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
-                  & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
-
-                  llvalprof = .TRUE. 
-                  EXIT loop_prof
-
-               ENDIF
+               DO jvar = 1, kvars
+                  IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,jvar),2) .AND. &
+                     & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
+
+                     llvalprof = .TRUE. 
+                     EXIT loop_prof
+
+                  ENDIF
+               END DO
 
             END DO loop_prof
@@ -573,8 +603,8 @@
 
                ! Coordinate search parameters
-               profdata%mi  (iprof,1) = inpfiles(jj)%iobsi(ji,1)
-               profdata%mj  (iprof,1) = inpfiles(jj)%iobsj(ji,1)
-               profdata%mi  (iprof,2) = inpfiles(jj)%iobsi(ji,2)
-               profdata%mj  (iprof,2) = inpfiles(jj)%iobsj(ji,2)
+               DO jvar = 1, kvars
+                  profdata%mi  (iprof,jvar) = inpfiles(jj)%iobsi(ji,jvar)
+                  profdata%mj  (iprof,jvar) = inpfiles(jj)%iobsj(ji,jvar)
+               END DO
 
                ! Profile WMO number
@@ -616,138 +646,84 @@
                   IF (ldsatt) THEN
 
-                     IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
-                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
-                        &    ldvar1 ) .OR. &
-                        & ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
-                        &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
-                        &   ldvar2 ) ) THEN
-                        ip3dt = ip3dt + 1
-                     ELSE
-                        CYCLE
+                     DO jvar = 1, kvars
+                        IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,jvar),2) .AND. &
+                           &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
+                           &    ldvar(jvar) ) ) THEN
+                           ip3dt = ip3dt + 1
+                           EXIT
+                        ELSE IF ( jvar == kvars ) THEN
+                           CYCLE loop_p
+                        ENDIF
+                     END DO
+
+                  ENDIF
+
+                  DO jvar = 1, kvars
+                  
+                     IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,jvar),2) .AND. &
+                       &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
+                       &    ldvar(jvar) ) .OR. ldsatt ) THEN
+
+                        IF (ldsatt) THEN
+
+                           ivart(jvar) = ip3dt
+
+                        ELSE
+
+                           ivart(jvar) = ivart(jvar) + 1
+
+                        ENDIF
+
+                        ! Depth of jvar observation
+                        profdata%var(jvar)%vdep(ivart(jvar)) = &
+                           &                inpfiles(jj)%pdep(ij,ji)
+
+                        ! Depth of jvar observation QC
+                        profdata%var(jvar)%idqc(ivart(jvar)) = &
+                           &                inpfiles(jj)%idqc(ij,ji)
+
+                        ! Depth of jvar observation QC flags
+                        profdata%var(jvar)%idqcf(:,ivart(jvar)) = &
+                           &                inpfiles(jj)%idqcf(:,ij,ji)
+
+                        ! Profile index
+                        profdata%var(jvar)%nvpidx(ivart(jvar)) = iprof
+
+                        ! Vertical index in original profile
+                        profdata%var(jvar)%nvlidx(ivart(jvar)) = ij
+
+                        ! Profile jvar value
+                        IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,jvar),2) .AND. &
+                           & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
+                           profdata%var(jvar)%vobs(ivart(jvar)) = &
+                              &                inpfiles(jj)%pob(ij,ji,jvar)
+                           IF ( ldmod ) THEN
+                              profdata%var(jvar)%vmod(ivart(jvar)) = &
+                                 &                inpfiles(jj)%padd(ij,ji,1,jvar)
+                           ENDIF
+                           ! Count number of profile var1 data as function of type
+                           itypvar( profdata%ntyp(iprof) + 1, jvar ) = &
+                              & itypvar( profdata%ntyp(iprof) + 1, jvar ) + 1
+                        ELSE
+                           profdata%var(jvar)%vobs(ivart(jvar)) = fbrmdi
+                        ENDIF
+
+                        ! Profile jvar qc
+                        profdata%var(jvar)%nvqc(ivart(jvar)) = &
+                           & inpfiles(jj)%ivlqc(ij,ji,jvar)
+
+                        ! Profile jvar qc flags
+                        profdata%var(jvar)%nvqcf(:,ivart(jvar)) = &
+                           & inpfiles(jj)%ivlqcf(:,ij,ji,jvar)
+
+                        ! Profile insitu T value
+                        IF ( TRIM( inpfiles(jj)%cname(jvar) ) == 'POTM' ) THEN
+                           profdata%var(jvar)%vext(ivart(jvar),1) = &
+                              &                inpfiles(jj)%pext(ij,ji,1)
+                        ENDIF
+
                      ENDIF
-
-                  ENDIF
-
-                  IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
-                    &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) .AND. &
-                    &    ldvar1 ) .OR. ldsatt ) THEN
-
-                     IF (ldsatt) THEN
-
-                        ivar1t = ip3dt
-
-                     ELSE
-
-                        ivar1t = ivar1t + 1
-
-                     ENDIF
-
-                     ! Depth of var1 observation
-                     profdata%var(1)%vdep(ivar1t) = &
-                        &                inpfiles(jj)%pdep(ij,ji)
-
-                     ! Depth of var1 observation QC
-                     profdata%var(1)%idqc(ivar1t) = &
-                        &                inpfiles(jj)%idqc(ij,ji)
-
-                     ! Depth of var1 observation QC flags
-                     profdata%var(1)%idqcf(:,ivar1t) = &
-                        &                inpfiles(jj)%idqcf(:,ij,ji)
-
-                     ! Profile index
-                     profdata%var(1)%nvpidx(ivar1t) = iprof
-
-                     ! Vertical index in original profile
-                     profdata%var(1)%nvlidx(ivar1t) = ij
-
-                     ! Profile var1 value
-                     IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,1),2) .AND. &
-                        & .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2) ) THEN
-                        profdata%var(1)%vobs(ivar1t) = &
-                           &                inpfiles(jj)%pob(ij,ji,1)
-                        IF ( ldmod ) THEN
-                           profdata%var(1)%vmod(ivar1t) = &
-                              &                inpfiles(jj)%padd(ij,ji,1,1)
-                        ENDIF
-                        ! Count number of profile var1 data as function of type
-                        itypvar1( profdata%ntyp(iprof) + 1 ) = &
-                           & itypvar1( profdata%ntyp(iprof) + 1 ) + 1
-                     ELSE
-                        profdata%var(1)%vobs(ivar1t) = fbrmdi
-                     ENDIF
-
-                     ! Profile var1 qc
-                     profdata%var(1)%nvqc(ivar1t) = &
-                        & inpfiles(jj)%ivlqc(ij,ji,1)
-
-                     ! Profile var1 qc flags
-                     profdata%var(1)%nvqcf(:,ivar1t) = &
-                        & inpfiles(jj)%ivlqcf(:,ij,ji,1)
-
-                     ! Profile insitu T value
-                     IF ( TRIM( inpfiles(jj)%cname(1) ) == 'POTM' ) THEN
-                        profdata%var(1)%vext(ivar1t,1) = &
-                           &                inpfiles(jj)%pext(ij,ji,1)
-                     ENDIF
-
-                  ENDIF
-
-                  IF ( ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) .AND. &
-                     &   .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2)    .AND. &
-                     &   ldvar2 ) .OR. ldsatt ) THEN
-
-                     IF (ldsatt) THEN
-
-                        ivar2t = ip3dt
-
-                     ELSE
-
-                        ivar2t = ivar2t + 1
-
-                     ENDIF
-
-                     ! Depth of var2 observation
-                     profdata%var(2)%vdep(ivar2t) = &
-                        &                inpfiles(jj)%pdep(ij,ji)
-
-                     ! Depth of var2 observation QC
-                     profdata%var(2)%idqc(ivar2t) = &
-                        &                inpfiles(jj)%idqc(ij,ji)
-
-                     ! Depth of var2 observation QC flags
-                     profdata%var(2)%idqcf(:,ivar2t) = &
-                        &                inpfiles(jj)%idqcf(:,ij,ji)
-
-                     ! Profile index
-                     profdata%var(2)%nvpidx(ivar2t) = iprof
-
-                     ! Vertical index in original profile
-                     profdata%var(2)%nvlidx(ivar2t) = ij
-
-                     ! Profile var2 value
-                  IF (  ( .NOT. BTEST(inpfiles(jj)%ivlqc(ij,ji,2),2) ) .AND. &
-                    &   ( .NOT. BTEST(inpfiles(jj)%idqc(ij,ji),2)    )  ) THEN
-                        profdata%var(2)%vobs(ivar2t) = &
-                           &                inpfiles(jj)%pob(ij,ji,2)
-                        IF ( ldmod ) THEN
-                           profdata%var(2)%vmod(ivar2t) = &
-                              &                inpfiles(jj)%padd(ij,ji,1,2)
-                        ENDIF
-                        ! Count number of profile var2 data as function of type
-                        itypvar2( profdata%ntyp(iprof) + 1 ) = &
-                           & itypvar2( profdata%ntyp(iprof) + 1 ) + 1
-                     ELSE
-                        profdata%var(2)%vobs(ivar2t) = fbrmdi
-                     ENDIF
-
-                     ! Profile var2 qc
-                     profdata%var(2)%nvqc(ivar2t) = &
-                        & inpfiles(jj)%ivlqc(ij,ji,2)
-
-                     ! Profile var2 qc flags
-                     profdata%var(2)%nvqcf(:,ivar2t) = &
-                        & inpfiles(jj)%ivlqcf(:,ij,ji,2)
-
-                  ENDIF
+                  
+                  END DO
 
                END DO loop_p
@@ -763,10 +739,12 @@
       !-----------------------------------------------------------------------
 
-      CALL obs_mpp_sum_integer ( ivar1t0, ivar1tmpp )
-      CALL obs_mpp_sum_integer ( ivar2t0, ivar2tmpp )
+      DO jvar = 1, kvars
+         CALL obs_mpp_sum_integer ( ivart0(jvar), ivartmpp(jvar) )
+      END DO
       CALL obs_mpp_sum_integer ( ip3dt,   ip3dtmpp  )
 
-      CALL obs_mpp_sum_integers( itypvar1, itypvar1mpp, ntyp1770 + 1 )
-      CALL obs_mpp_sum_integers( itypvar2, itypvar2mpp, ntyp1770 + 1 )
+      DO jvar = 1, kvars
+         CALL obs_mpp_sum_integers( itypvar(:,jvar), itypvarmpp(:,jvar), ntyp1770 + 1 )
+      END DO
 
       !-----------------------------------------------------------------------
@@ -778,50 +756,33 @@
          WRITE(numout,'(1X,A)') '------------'
          WRITE(numout,*) 
-         WRITE(numout,'(1X,A)') 'Profile data, '//TRIM( profdata%cvars(1) )
-         WRITE(numout,'(1X,A)') '------------------------'
-         DO ji = 0, ntyp1770
-            IF ( itypvar1mpp(ji+1) > 0 ) THEN
-               WRITE(numout,'(1X,A3,1X,A48,A3,I8)') ctypshort(ji), &
-                  & cwmonam1770(ji)(1:52),' = ', &
-                  & itypvar1mpp(ji+1)
-            ENDIF
+         DO jvar = 1, kvars
+            WRITE(numout,'(1X,A)') 'Profile data, '//TRIM( profdata%cvars(jvar) )
+            WRITE(numout,'(1X,A)') '------------------------'
+            DO ji = 0, ntyp1770
+               IF ( itypvarmpp(ji+1,jvar) > 0 ) THEN
+                  WRITE(numout,'(1X,A3,1X,A48,A3,I8)') ctypshort(ji), &
+                     & cwmonam1770(ji)(1:52),' = ', &
+                     & itypvarmpp(ji+1,jvar)
+               ENDIF
+            END DO
+            WRITE(numout,'(1X,A)') &
+               & '---------------------------------------------------------------'
+            WRITE(numout,'(1X,A55,I8)') &
+               & 'Total profile data for variable '//TRIM( profdata%cvars(jvar) )// &
+               & '             = ', ivartmpp(jvar)
+            WRITE(numout,'(1X,A)') &
+               & '---------------------------------------------------------------'
+            WRITE(numout,*) 
          END DO
-         WRITE(numout,'(1X,A)') &
-            & '---------------------------------------------------------------'
-         WRITE(numout,'(1X,A55,I8)') &
-            & 'Total profile data for variable '//TRIM( profdata%cvars(1) )// &
-            & '             = ', ivar1tmpp
-         WRITE(numout,'(1X,A)') &
-            & '---------------------------------------------------------------'
-         WRITE(numout,*) 
-         WRITE(numout,'(1X,A)') 'Profile data, '//TRIM( profdata%cvars(2) )
-         WRITE(numout,'(1X,A)') '------------------------'
-         DO ji = 0, ntyp1770
-            IF ( itypvar2mpp(ji+1) > 0 ) THEN
-               WRITE(numout,'(1X,A3,1X,A48,A3,I8)') ctypshort(ji), &
-                  & cwmonam1770(ji)(1:52),' = ', &
-                  & itypvar2mpp(ji+1)
-            ENDIF
+      ENDIF
+
+      IF (ldsatt) THEN
+         profdata%nvprot(:)    = ip3dt
+         profdata%nvprotmpp(:) = ip3dtmpp
+      ELSE
+         DO jvar = 1, kvars
+            profdata%nvprot(jvar)    = ivart(jvar)
+            profdata%nvprotmpp(jvar) = ivartmpp(jvar)
          END DO
-         WRITE(numout,'(1X,A)') &
-            & '---------------------------------------------------------------'
-         WRITE(numout,'(1X,A55,I8)') &
-            & 'Total profile data for variable '//TRIM( profdata%cvars(2) )// &
-            & '             = ', ivar2tmpp
-         WRITE(numout,'(1X,A)') &
-            & '---------------------------------------------------------------'
-         WRITE(numout,*) 
-      ENDIF
-
-      IF (ldsatt) THEN
-         profdata%nvprot(1)    = ip3dt
-         profdata%nvprot(2)    = ip3dt
-         profdata%nvprotmpp(1) = ip3dtmpp
-         profdata%nvprotmpp(2) = ip3dtmpp
-      ELSE
-         profdata%nvprot(1)    = ivar1t
-         profdata%nvprot(2)    = ivar2t
-         profdata%nvprotmpp(1) = ivar1tmpp
-         profdata%nvprotmpp(2) = ivar2tmpp
       ENDIF
       profdata%nprof        = iprof
@@ -830,14 +791,11 @@
       ! Model level search
       !-----------------------------------------------------------------------
-      IF ( ldvar1 ) THEN
-         CALL obs_level_search( jpk, gdept_1d, &
-            & profdata%nvprot(1), profdata%var(1)%vdep, &
-            & profdata%var(1)%mvk )
-      ENDIF
-      IF ( ldvar2 ) THEN
-         CALL obs_level_search( jpk, gdept_1d, &
-            & profdata%nvprot(2), profdata%var(2)%vdep, &
-            & profdata%var(2)%mvk )
-      ENDIF
+      DO jvar = 1, kvars
+         IF ( ldvar(jvar) ) THEN
+            CALL obs_level_search( jpk, gdept_1d, &
+               & profdata%nvprot(jvar), profdata%var(jvar)%vdep, &
+               & profdata%var(jvar)%mvk )
+         ENDIF
+      END DO
 
       !-----------------------------------------------------------------------
@@ -852,5 +810,5 @@
       ! Deallocate temporary data
       !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, iprofidx, zdat, clvars )
+      DEALLOCATE( ifileidx, iprofidx, zdat, clvarsin )
 
       !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_read_surf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_read_surf.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_read_surf.F90	(revision 14062)
@@ -40,5 +40,5 @@
    SUBROUTINE obs_rea_surf( surfdata, knumfiles, cdfilenames, &
       &                     kvars, kextr, kstp, ddobsini, ddobsend, &
-      &                     ldignmis, ldmod, ldnightav )
+      &                     ldignmis, ldmod, ldnightav, cdvars )
       !!---------------------------------------------------------------------
       !!
@@ -73,9 +73,10 @@
       REAL(dp), INTENT(IN) :: ddobsini   ! Obs. ini time in YYYYMMDD.HHMMSS
       REAL(dp), INTENT(IN) :: ddobsend   ! Obs. end time in YYYYMMDD.HHMMSS
+      CHARACTER(len=8), DIMENSION(kvars), INTENT(IN) :: cdvars
 
       !! * Local declarations
       CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_surf'
       CHARACTER(len=8) :: clrefdate
-      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: clvars
+      CHARACTER(len=8), DIMENSION(:), ALLOCATABLE :: clvarsin
       INTEGER :: ji
       INTEGER :: jj
@@ -178,4 +179,9 @@
                &                ldgrid = .TRUE. )
 
+            IF ( inpfiles(jj)%nvar /= kvars ) THEN
+               CALL ctl_stop( 'Feedback format error: ', &
+                  &           ' unexpected number of vars in feedback file' )
+            ENDIF
+
             IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
                CALL ctl_stop( 'Model not in input data' )
@@ -184,11 +190,15 @@
 
             IF ( jj == 1 ) THEN
-               ALLOCATE( clvars( inpfiles(jj)%nvar ) )
+               ALLOCATE( clvarsin( inpfiles(jj)%nvar ) )
                DO ji = 1, inpfiles(jj)%nvar
-                 clvars(ji) = inpfiles(jj)%cname(ji)
+                 clvarsin(ji) = inpfiles(jj)%cname(ji)
+                 IF ( clvarsin(ji) /= cdvars(ji) ) THEN
+                    CALL ctl_stop( 'Feedback file variables do not match', &
+                        &           ' expected variable names for this type' )
+                 ENDIF
                END DO
             ELSE
                DO ji = 1, inpfiles(jj)%nvar
-                  IF ( inpfiles(jj)%cname(ji) /= clvars(ji) ) THEN
+                  IF ( inpfiles(jj)%cname(ji) /= clvarsin(ji) ) THEN
                      CALL ctl_stop( 'Feedback file variables not consistent', &
                         &           ' with previous files for this type' )
@@ -347,5 +357,5 @@
       iobs = 0
 
-      surfdata%cvars(:)  = clvars(:)
+      surfdata%cvars(:)  = clvarsin(:)
 
       ityp   (:) = 0
@@ -480,5 +490,5 @@
       ! Deallocate temporary data
       !-----------------------------------------------------------------------
-      DEALLOCATE( ifileidx, isurfidx, zdat, clvars )
+      DEALLOCATE( ifileidx, isurfidx, zdat, clvarsin )
 
       !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_write.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_write.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/OBS/obs_write.F90	(revision 14062)
@@ -86,4 +86,7 @@
       CHARACTER(LEN=40) :: clfname
       CHARACTER(LEN=10) :: clfiletype
+      CHARACTER(LEN=ilenlong) :: cllongname  ! Long name of variable
+      CHARACTER(LEN=ilenunit) :: clunits     ! Units of variable
+      CHARACTER(LEN=ilengrid) :: clgrid      ! Grid of variable
       CHARACTER(LEN=12) :: clfmt            ! writing format
       INTEGER :: idg                        ! number of digits
@@ -115,5 +118,5 @@
       ! Find maximum level
       ilevel = 0
-      DO jvar = 1, 2
+      DO jvar = 1, profdata%nvar
          ilevel = MAX( ilevel, MAXVAL( profdata%var(jvar)%nvlidx(:) ) )
       END DO
@@ -180,4 +183,26 @@
 
       END SELECT
+      
+      IF ( ( TRIM(profdata%cvars(1)) /= 'POTM' ) .AND. &
+         & ( TRIM(profdata%cvars(1)) /= 'UVEL' ) ) THEN
+         CALL alloc_obfbdata( fbdata, 1, profdata%nprof, ilevel, &
+            &                 1 + iadd, iext, .TRUE. )
+         fbdata%cname(1)      = profdata%cvars(1)
+         fbdata%coblong(1)    = cllongname
+         fbdata%cobunit(1)    = clunits
+         fbdata%caddlong(1,1) = 'Model interpolated ' // TRIM(cllongname)
+         fbdata%caddunit(1,1) = clunits
+         fbdata%cgrid(:)      = clgrid
+         DO je = 1, iext
+            fbdata%cextname(je) = pext%cdname(je)
+            fbdata%cextlong(je) = pext%cdlong(je,1)
+            fbdata%cextunit(je) = pext%cdunit(je,1)
+         END DO
+         DO ja = 1, iadd
+            fbdata%caddname(1+ja) = padd%cdname(ja)
+            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
+            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
+         END DO
+      ENDIF
 
       fbdata%caddname(1)   = 'Hx'
@@ -234,5 +259,5 @@
             &           krefdate = 19500101 )
          ! Reform the profiles arrays for output
-         DO jvar = 1, 2
+         DO jvar = 1, profdata%nvar
             DO jk = profdata%npvsta(jo,jvar), profdata%npvend(jo,jvar)
                ik = profdata%var(jvar)%nvlidx(jk)
@@ -329,4 +354,7 @@
       CHARACTER(LEN=40) :: clfname         ! netCDF filename
       CHARACTER(LEN=10) :: clfiletype
+      CHARACTER(LEN=ilenlong) :: cllongname  ! Long name of variable
+      CHARACTER(LEN=ilenunit) :: clunits     ! Units of variable
+      CHARACTER(LEN=ilengrid) :: clgrid      ! Grid of variable
       CHARACTER(LEN=12), PARAMETER :: cpname = 'obs_wri_surf'
       CHARACTER(LEN=12) :: clfmt           ! writing format
@@ -354,4 +382,8 @@
       SELECT CASE ( TRIM(surfdata%cvars(1)) )
       CASE('SLA')
+         
+         ! SLA needs special treatment because of MDT, so is all done here
+         ! Other variables are done more generically
+         ! No climatology for SLA, MDT is our best estimate of that and is already output.
 
          CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
@@ -384,19 +416,52 @@
       CASE('SST')
 
+         clfiletype = 'sstfb'
+         cllongname = 'Sea surface temperature'
+         clunits    = 'Degree centigrade'
+         clgrid     = 'T'
+         
+      CASE('ICECONC')
+
+         clfiletype = 'sicfb'
+         cllongname = 'Sea ice concentration'
+         clunits    = 'Fraction'
+         clgrid     = 'T'
+
+      CASE('SSS')
+
+         clfiletype = 'sssfb'
+         cllongname = 'Sea surface salinity'
+         clunits    = 'psu'
+         clgrid     = 'T'
+
+      CASE DEFAULT
+
+         CALL ctl_stop( 'Unknown observation type '//TRIM(surfdata%cvars(1))//' in obs_wri_surf' )
+
+      END SELECT
+
+      ! SLA needs special treatment because of MDT, so is done above
+      ! Remaining variables treated more generically
+
+      IF ( TRIM(surfdata%cvars(1)) /= 'SLA' ) THEN
+      
          CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
             &                 1 + iadd, iext, .TRUE. )
 
-         clfiletype = 'sstfb'
          fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Sea surface temperature'
-         fbdata%cobunit(1)    = 'Degree centigrade'
+         fbdata%coblong(1)    = cllongname
+         fbdata%cobunit(1)    = clunits
          DO je = 1, iext
             fbdata%cextname(je) = pext%cdname(je)
             fbdata%cextlong(je) = pext%cdlong(je,1)
             fbdata%cextunit(je) = pext%cdunit(je,1)
-         END DO
-         fbdata%caddlong(1,1) = 'Model interpolated SST'
-         fbdata%caddunit(1,1) = 'Degree centigrade'
-         fbdata%cgrid(1)      = 'T'
+         END DO        
+         IF ( TRIM(surfdata%cvars(1)) == 'ICECONC' ) THEN
+            fbdata%caddlong(1,1) = 'Model interpolated ICE'
+         ELSE
+            fbdata%caddlong(1,1) = 'Model interpolated ' // TRIM(surfdata%cvars(1))
+         ENDIF
+         fbdata%caddunit(1,1) = clunits
+         fbdata%cgrid(1)      = clgrid
          DO ja = 1, iadd
             fbdata%caddname(1+ja) = padd%cdname(ja)
@@ -404,56 +469,5 @@
             fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
          END DO
-
-      CASE('ICECONC')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'sicfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Sea ice'
-         fbdata%cobunit(1)    = 'Fraction'
-         DO je = 1, iext
-            fbdata%cextname(je) = pext%cdname(je)
-            fbdata%cextlong(je) = pext%cdlong(je,1)
-            fbdata%cextunit(je) = pext%cdunit(je,1)
-         END DO
-         fbdata%caddlong(1,1) = 'Model interpolated ICE'
-         fbdata%caddunit(1,1) = 'Fraction'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            fbdata%caddname(1+ja) = padd%cdname(ja)
-            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
-            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
-         END DO
-
-      CASE('SSS')
-
-         CALL alloc_obfbdata( fbdata, 1, surfdata%nsurf, 1, &
-            &                 1 + iadd, iext, .TRUE. )
-
-         clfiletype = 'sssfb'
-         fbdata%cname(1)      = surfdata%cvars(1)
-         fbdata%coblong(1)    = 'Sea surface salinity'
-         fbdata%cobunit(1)    = 'psu'
-         DO je = 1, iext
-            fbdata%cextname(je) = pext%cdname(je)
-            fbdata%cextlong(je) = pext%cdlong(je,1)
-            fbdata%cextunit(je) = pext%cdunit(je,1)
-         END DO
-         fbdata%caddlong(1,1) = 'Model interpolated SSS'
-         fbdata%caddunit(1,1) = 'psu'
-         fbdata%cgrid(1)      = 'T'
-         DO ja = 1, iadd
-            fbdata%caddname(1+ja) = padd%cdname(ja)
-            fbdata%caddlong(1+ja,1) = padd%cdlong(ja,1)
-            fbdata%caddunit(1+ja,1) = padd%cdunit(ja,1)
-         END DO
-
-      CASE DEFAULT
-
-         CALL ctl_stop( 'Unknown observation type '//TRIM(surfdata%cvars(1))//' in obs_wri_surf' )
-
-      END SELECT
+      ENDIF
 
       fbdata%caddname(1)   = 'Hx'
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcapr.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcapr.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcapr.F90	(revision 14062)
@@ -148,5 +148,5 @@
          !                                      ! ---------------------------------------- !
          !                                            !* Restart: read in restart file
-         IF( ln_rstart .AND. iom_varid( numror, 'ssh_ibb', ldstop = .FALSE. ) > 0 ) THEN 
+         IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN 
             IF(lwp) WRITE(numout,*) 'sbc_apr:   ssh_ibb read in the restart file'
             CALL iom_get( numror, jpdom_auto, 'ssh_ibb', ssh_ibb )   ! before inv. barometer ssh
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcice_cice.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcice_cice.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcice_cice.F90	(revision 14062)
@@ -12,8 +12,8 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
-# if ! defined key_qco
-   USE domvvl
+# if defined key_qco
+   USE domqco         ! Variable volume
 # else
-   USE domqco
+   USE domvvl         ! Variable volume
 # endif
    USE phycst, only : rcp, rho0, r1_rho0, rhos, rhoi
@@ -238,5 +238,5 @@
 !!gm especially here it is assumed zstar coordinate, but it can be ztilde....
 #if defined key_qco
-            IF( .NOT.ln_linssh )   CALL dom_qco_zgr( Kbb, Kmm, Kaa )   ! interpolation scale factor, depth and water column
+            IF( .NOT.ln_linssh )   CALL dom_qco_zgr( Kbb, Kmm )   ! interpolation scale factor, depth and water column
 #else
             IF( .NOT.ln_linssh ) THEN
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcmod.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcmod.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcmod.F90	(revision 14062)
@@ -523,13 +523,11 @@
       IF( kt == nit000 ) THEN                          !   set the forcing field at nit000 - 1    !
          !                                             ! ---------------------------------------- !
-         IF( ln_rstart .AND.    &                               !* Restart: read in restart file
-            & iom_varid( numror, 'utau_b', ldstop = .FALSE. ) > 0 ) THEN
-            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields red in the restart file'
-            CALL iom_get( numror, jpdom_auto, 'utau_b', utau_b )   ! before i-stress  (U-point)
-            CALL iom_get( numror, jpdom_auto, 'vtau_b', vtau_b )   ! before j-stress  (V-point)
-            CALL iom_get( numror, jpdom_auto,  'qns_b',  qns_b )   ! before non solar heat flux (T-point)
-            ! The 3D heat content due to qsr forcing is treated in traqsr
-            ! CALL iom_get( numror, jpdom_auto, 'qsr_b' , qsr_b  ) ! before     solar heat flux (T-point)
-            CALL iom_get( numror, jpdom_auto, 'emp_b', emp_b  )    ! before     freshwater flux (T-point)
+         IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN            !* Restart: read in restart file
+            IF(lwp) WRITE(numout,*) '          nit000-1 surface forcing fields read in the restart file'
+            CALL iom_get( numror, jpdom_auto, 'utau_b', utau_b )   ! i-stress
+            CALL iom_get( numror, jpdom_auto, 'vtau_b', vtau_b )   ! j-stress
+            CALL iom_get( numror, jpdom_auto,  'qns_b',  qns_b )   ! non solar heat flux
+            CALL iom_get( numror, jpdom_auto,  'emp_b',  emp_b )   ! freshwater flux
+            ! NB: The 3D heat content due to qsr forcing (qsr_hc_b) is treated in traqsr
             ! To ensure restart capability with 3.3x/3.4 restart files    !! to be removed in v3.6
             IF( iom_varid( numror, 'sfx_b', ldstop = .FALSE. ) > 0 ) THEN
@@ -566,25 +564,25 @@
       !                                                ! ---------------------------------------- !
       IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN
-         CALL iom_put( "empmr"  , emp    - rnf )                ! upward water flux
-         CALL iom_put( "empbmr" , emp_b  - rnf )                ! before upward water flux ( needed to recalculate the time evolution of ssh in offline )
-         CALL iom_put( "saltflx", sfx  )                        ! downward salt flux (includes virtual salt flux beneath ice in linear free surface case)
-         CALL iom_put( "fmmflx", fmmflx  )                      ! Freezing-melting water flux
-         CALL iom_put( "qt"    , qns  + qsr )                   ! total heat flux
-         CALL iom_put( "qns"   , qns        )                   ! solar heat flux
-         CALL iom_put( "qsr"   ,       qsr  )                   ! solar heat flux
+         CALL iom_put( "empmr"  , emp   - rnf )                ! upward water flux
+         CALL iom_put( "empbmr" , emp_b - rnf )                ! before upward water flux ( needed to recalculate the time evolution of ssh in offline )
+         CALL iom_put( "saltflx", sfx         )                ! downward salt flux (includes virtual salt flux beneath ice in linear free surface case)
+         CALL iom_put( "fmmflx" , fmmflx      )                ! Freezing-melting water flux
+         CALL iom_put( "qt"     , qns + qsr   )                ! total heat flux
+         CALL iom_put( "qns"    , qns         )                ! solar heat flux
+         CALL iom_put( "qsr"    ,       qsr   )                ! solar heat flux
          IF( nn_ice > 0 .OR. ll_opa )   CALL iom_put( "ice_cover", fr_i )   ! ice fraction
-         CALL iom_put( "taum"  , taum       )                   ! wind stress module
-         CALL iom_put( "wspd"  , wndm       )                   ! wind speed  module over free ocean or leads in presence of sea-ice
-         CALL iom_put( "qrp", qrp )                             ! heat flux damping
-         CALL iom_put( "erp", erp )                             ! freshwater flux damping
+         CALL iom_put( "taum"   , taum        )                ! wind stress module
+         CALL iom_put( "wspd"   , wndm        )                ! wind speed  module over free ocean or leads in presence of sea-ice
+         CALL iom_put( "qrp"    , qrp         )                ! heat flux damping
+         CALL iom_put( "erp"    , erp         )                ! freshwater flux damping
       ENDIF
       !
       IF(sn_cfctl%l_prtctl) THEN     ! print mean trends (used for debugging)
-         CALL prt_ctl(tab2d_1=fr_i             , clinfo1=' fr_i     - : ', mask1=tmask )
-         CALL prt_ctl(tab2d_1=(emp-rnf)        , clinfo1=' emp-rnf  - : ', mask1=tmask )
-         CALL prt_ctl(tab2d_1=(sfx-rnf)        , clinfo1=' sfx-rnf  - : ', mask1=tmask )
-         CALL prt_ctl(tab2d_1=qns              , clinfo1=' qns      - : ', mask1=tmask )
-         CALL prt_ctl(tab2d_1=qsr              , clinfo1=' qsr      - : ', mask1=tmask )
-         CALL prt_ctl(tab3d_1=tmask            , clinfo1=' tmask    - : ', mask1=tmask, kdim=jpk )
+         CALL prt_ctl(tab2d_1=fr_i                , clinfo1=' fr_i     - : ', mask1=tmask )
+         CALL prt_ctl(tab2d_1=(emp-rnf)           , clinfo1=' emp-rnf  - : ', mask1=tmask )
+         CALL prt_ctl(tab2d_1=(sfx-rnf)           , clinfo1=' sfx-rnf  - : ', mask1=tmask )
+         CALL prt_ctl(tab2d_1=qns                 , clinfo1=' qns      - : ', mask1=tmask )
+         CALL prt_ctl(tab2d_1=qsr                 , clinfo1=' qsr      - : ', mask1=tmask )
+         CALL prt_ctl(tab3d_1=tmask               , clinfo1=' tmask    - : ', mask1=tmask, kdim=jpk )
          CALL prt_ctl(tab3d_1=ts(:,:,:,jp_tem,Kmm), clinfo1=' sst      - : ', mask1=tmask, kdim=1   )
          CALL prt_ctl(tab3d_1=ts(:,:,:,jp_sal,Kmm), clinfo1=' sss      - : ', mask1=tmask, kdim=1   )
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcrnf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcrnf.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/SBC/sbcrnf.F90	(revision 14062)
@@ -157,11 +157,10 @@
       IF( kt == nit000 ) THEN                          !   set the forcing field at nit000 - 1    !
          !                                             ! ---------------------------------------- !
-         IF( ln_rstart .AND.    &                               !* Restart: read in restart file
-            & iom_varid( numror, 'rnf_b', ldstop = .FALSE. ) > 0 ) THEN
+         IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN         !* Restart: read in restart file
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields red in the restart file', lrxios
-            CALL iom_get( numror, jpdom_auto, 'rnf_b', rnf_b )     ! before runoff
+            CALL iom_get( numror, jpdom_auto, 'rnf_b'   , rnf_b                 )   ! before runoff
             CALL iom_get( numror, jpdom_auto, 'rnf_hc_b', rnf_tsc_b(:,:,jp_tem) )   ! before heat content of runoff
             CALL iom_get( numror, jpdom_auto, 'rnf_sc_b', rnf_tsc_b(:,:,jp_sal) )   ! before salinity content of runoff
-         ELSE                                                   !* no restart: set from nit000 values
+         ELSE                                                !* no restart: set from nit000 values
             IF(lwp) WRITE(numout,*) '          nit000-1 runoff forcing fields set to nit000'
             rnf_b    (:,:  ) = rnf    (:,:  )
@@ -176,5 +175,5 @@
             &                    'at it= ', kt,' date= ', ndastp
          IF(lwp) WRITE(numout,*) '~~~~'
-         CALL iom_rstput( kt, nitrst, numrow, 'rnf_b' , rnf )
+         CALL iom_rstput( kt, nitrst, numrow, 'rnf_b'   , rnf                 )
          CALL iom_rstput( kt, nitrst, numrow, 'rnf_hc_b', rnf_tsc(:,:,jp_tem) )
          CALL iom_rstput( kt, nitrst, numrow, 'rnf_sc_b', rnf_tsc(:,:,jp_sal) )
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traatf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traatf.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traatf.F90	(revision 14062)
@@ -117,6 +117,6 @@
       IF( l_trdtra )   THEN                    
          ALLOCATE( ztrdt(jpi,jpj,jpk) , ztrds(jpi,jpj,jpk) )
-         ztrdt(:,:,jpk) = 0._wp
-         ztrds(:,:,jpk) = 0._wp
+         ztrdt(:,:,:) = 0._wp
+         ztrds(:,:,:) = 0._wp
          IF( ln_traldf_iso ) THEN              ! diagnose the "pure" Kz diffusive trend 
             CALL trd_tra( kt, Kmm, Kaa, 'TRA', jp_tem, jptra_zdfp, ztrdt )
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traatf_qco.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traatf_qco.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traatf_qco.F90	(revision 14062)
@@ -1,5 +1,5 @@
-MODULE traatfqco
+MODULE traatf_qco
    !!======================================================================
-   !!                       ***  MODULE  traatfqco  ***
+   !!                       ***  MODULE  traatf_qco  ***
    !! Ocean active tracers:  Asselin time filtering for temperature and salinity
    !!======================================================================
@@ -45,7 +45,4 @@
    USE prtctl          ! Print control
    USE timing          ! Timing
-#if defined key_agrif
-   USE agrif_oce_interp
-#endif
 
    IMPLICIT NONE
@@ -149,6 +146,6 @@
          ENDIF
          !
-         CALL lbc_lnk_multi( 'traatfqco', pts(:,:,:,jp_tem,Kmm) , 'T', 1., pts(:,:,:,jp_sal,Kmm) , 'T', 1. )
-
+         CALL lbc_lnk_multi( 'traatfqco', pts(:,:,:,jp_tem,Kmm) , 'T', 1._wp, pts(:,:,:,jp_sal,Kmm) , 'T', 1._wp )
+         !
       ENDIF
       !
@@ -370,3 +367,3 @@
 
    !!======================================================================
-END MODULE traatfqco
+END MODULE traatf_qco
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/tramle.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/tramle.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/tramle.F90	(revision 14062)
@@ -20,4 +20,8 @@
    USE lib_mpp        ! MPP library
    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
@@ -99,94 +103,139 @@
       !!----------------------------------------------------------------------
       !
-      !                                      !==  MLD used for MLE  ==!
-      !                                                ! compute from the 10m density to deal with the diurnal cycle
-      DO_2D( 1, 1, 1, 1 )
-         inml_mle(ji,jj) = mbkt(ji,jj) + 1                    ! init. to number of ocean w-level (T-level + 1)
-      END_2D
-      IF ( nla10 > 0 ) THEN                            ! avoid case where first level is thicker than 10m
-         DO_3DS( 1, 1, 1, 1, jpkm1, nlb10, -1 )        ! from the bottom to nlb10 (10m)
-            IF( rhop(ji,jj,jk) > rhop(ji,jj,nla10) + rn_rho_c_mle )   inml_mle(ji,jj) = jk      ! Mixed layer
+      !
+      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_2D( 1, 0, 1, 0 )
+               zhu(ji,jj) = MIN( hmle(ji+1,jj), hmle(ji,jj) )
+               zhv(ji,jj) = MIN( hmle(ji,jj+1), hmle(ji,jj) )
+            END_2D
+         CASE ( 1 )                                               != average of the 2 neighbour MLDs
+            DO_2D( 1, 0, 1, 0 )
+               zhu(ji,jj) = MAX( hmle(ji+1,jj), hmle(ji,jj) )
+               zhv(ji,jj) = MAX( hmle(ji,jj+1), hmle(ji,jj) )
+            END_2D
+         CASE ( 2 )                                               != max of the 2 neighbour MLDs
+            DO_2D( 1, 0, 1, 0 )
+               zhu(ji,jj) = MAX( hmle(ji+1,jj), hmle(ji,jj) )
+               zhv(ji,jj) = MAX( hmle(ji,jj+1), hmle(ji,jj) )
+            END_2D
+         END SELECT
+         IF( nn_mle == 0 ) THEN           ! Fox-Kemper et al. 2010 formulation
+            DO_2D( 1, 0, 1, 0 )
+               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_2D
+            !
+         ELSEIF( nn_mle == 1 ) THEN       ! New formulation (Lf = 5km fo/ff with fo=Coriolis parameter at latitude rn_lat)
+            DO_2D( 1, 0, 1, 0 )
+               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_2D
+         ENDIF
+
+      ELSE !do not use osn_mle
+         !                                      !==  MLD used for MLE  ==!
+         !                                                ! compute from the 10m density to deal with the diurnal cycle
+         DO_2D( 1, 1, 1, 1 )
+            inml_mle(ji,jj) = mbkt(ji,jj) + 1                    ! init. to number of ocean w-level (T-level + 1)
+         END_2D
+         IF ( nla10 > 0 ) THEN                            ! avoid case where first level is thicker than 10m
+           DO_3DS( 1, 1, 1, 1, jpkm1, nlb10, -1 )        ! from the bottom to nlb10 (10m)
+              IF( rhop(ji,jj,jk) > rhop(ji,jj,nla10) + rn_rho_c_mle )   inml_mle(ji,jj) = jk      ! Mixed layer
+           END_3D
+         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_3D( 1, 1, 1, 1, 1, ikmax )                    ! MLD and mean buoyancy and N2 over the mixed layer
+            zc = e3t(ji,jj,jk,Kmm) * 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 * (rho0 - rhop(ji,jj,jk) ) * r1_rho0
+            zn2 (ji,jj) = zn2 (ji,jj) + zc * (rn2(ji,jj,jk)+rn2(ji,jj,jk+1))*0.5_wp
          END_3D
-      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_3D( 1, 1, 1, 1, 1, ikmax )                    ! MLD and mean buoyancy and N2 over the mixed layer
-         zc = e3t(ji,jj,jk,Kmm) * 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 * (rho0 - rhop(ji,jj,jk) ) * r1_rho0
-         zn2 (ji,jj) = zn2 (ji,jj) + zc * (rn2(ji,jj,jk)+rn2(ji,jj,jk+1))*0.5_wp
-      END_3D
-
-      SELECT CASE( nn_mld_uv )                         ! MLD at u- & v-pts
-      CASE ( 0 )                                               != min of the 2 neighbour MLDs
-         DO_2D( 1, 0, 1, 0 )
-            zhu(ji,jj) = MIN( zmld(ji+1,jj), zmld(ji,jj) )
-            zhv(ji,jj) = MIN( zmld(ji,jj+1), zmld(ji,jj) )
+   
+         SELECT CASE( nn_mld_uv )                         ! MLD at u- & v-pts
+         CASE ( 0 )                                               != min of the 2 neighbour MLDs
+            DO_2D( 1, 0, 1, 0 )
+               zhu(ji,jj) = MIN( zmld(ji+1,jj), zmld(ji,jj) )
+               zhv(ji,jj) = MIN( zmld(ji,jj+1), zmld(ji,jj) )
+            END_2D
+         CASE ( 1 )                                               != average of the 2 neighbour MLDs
+            DO_2D( 1, 0, 1, 0 )
+               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_2D
+         CASE ( 2 )                                               != max of the 2 neighbour MLDs
+            DO_2D( 1, 0, 1, 0 )
+               zhu(ji,jj) = MAX( zmld(ji+1,jj), zmld(ji,jj) )
+               zhv(ji,jj) = MAX( zmld(ji,jj+1), zmld(ji,jj) )
+            END_2D
+         END SELECT
+         !                                                ! convert density into buoyancy
+         DO_2D( 1, 1, 1, 1 )
+            zbm(ji,jj) = + grav * zbm(ji,jj) / MAX( e3t(ji,jj,1,Kmm), zmld(ji,jj) )
          END_2D
-      CASE ( 1 )                                               != average of the 2 neighbour MLDs
-         DO_2D( 1, 0, 1, 0 )
-            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_2D
-      CASE ( 2 )                                               != max of the 2 neighbour MLDs
-         DO_2D( 1, 0, 1, 0 )
-            zhu(ji,jj) = MAX( zmld(ji+1,jj), zmld(ji,jj) )
-            zhv(ji,jj) = MAX( zmld(ji,jj+1), zmld(ji,jj) )
-         END_2D
-      END SELECT
-      !                                                ! convert density into buoyancy
-      DO_2D( 1, 1, 1, 1 )
-         zbm(ji,jj) = + grav * zbm(ji,jj) / MAX( e3t(ji,jj,1,Kmm), zmld(ji,jj) )
-      END_2D
-      !
-      !
-      !                                      !==  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_2D( 1, 0, 1, 0 )
-            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) ) )   )
+         !
+         !
+         !                                      !==  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_2D( 1, 0, 1, 0 )
+               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_2D
-         !
-      ELSEIF( nn_mle == 1 ) THEN       ! New formulation (Lf = 5km fo/ff with fo=Coriolis parameter at latitude rn_lat)
-         DO_2D( 1, 0, 1, 0 )
-            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) = 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_2D
+            !
+         ELSEIF( nn_mle == 1 ) THEN       ! New formulation (Lf = 5km fo/ff with fo=Coriolis parameter at latitude rn_lat)
+            DO_2D( 1, 0, 1, 0 )
+               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_2D
-      ENDIF
-      !
-      IF( nn_conv == 1 ) THEN              ! No MLE in case of convection
-         DO_2D( 1, 0, 1, 0 )
-            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_2D
-      ENDIF
-      !
-      !                                      !==  structure function value at uw- and vw-points  ==!
-      DO_2D( 1, 0, 1, 0 )
-         zhu(ji,jj) = 1._wp / zhu(ji,jj)                   ! hu --> 1/hu
-         zhv(ji,jj) = 1._wp / zhv(ji,jj)
-      END_2D
-      !
-      zpsi_uw(:,:,:) = 0._wp
-      zpsi_vw(:,:,:) = 0._wp
-      !
+               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_2D
+         ENDIF
+         !
+         IF( nn_conv == 1 ) THEN              ! No MLE in case of convection
+            DO_2D( 1, 0, 1, 0 )
+               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_2D
+         ENDIF
+         !
+      ENDIF  ! end of ln_osm_mle conditional
+    !                                      !==  structure function value at uw- and vw-points  ==!
+    DO_2D( 1, 0, 1, 0 )
+       zhu(ji,jj) = 1._wp / MAX(zhu(ji,jj), rsmall)                   ! hu --> 1/hu
+       zhv(ji,jj) = 1._wp / MAX(zhv(ji,jj), rsmall) 
+    END_2D
+    !
+    zpsi_uw(:,:,:) = 0._wp
+    zpsi_vw(:,:,:) = 0._wp
+    !
       DO_3D( 1, 0, 1, 0, 2, ikmax )                ! start from 2 : surface value = 0
          zcuw = 1._wp - ( gdepw(ji+1,jj,jk,Kmm) + gdepw(ji,jj,jk,Kmm) ) * zhu(ji,jj)
@@ -220,7 +269,13 @@
          ENDIF
          !
-         DO_2D( 0, 0, 0, 0 )
-            zLf_NH(ji,jj) = SQRT( rb_c * zmld(ji,jj) ) * r1_ft(ji,jj)      ! Lf = N H / f
-         END_2D
+         IF (ln_osm_mle.and.ln_zdfosm) THEN
+            DO_2D( 0, 0, 0, 0 )
+               zLf_NH(ji,jj) = SQRT( rb_c * hmle(ji,jj) ) * r1_ft(ji,jj)      ! Lf = N H / f
+            END_2D
+         ELSE
+            DO_2D( 0, 0, 0, 0 )
+               zLf_NH(ji,jj) = SQRT( rb_c * zmld(ji,jj) ) * r1_ft(ji,jj)      ! Lf = N H / f
+            END_2D
+         ENDIF
          !
          ! divide by cross distance to give streamfunction with dimensions m^2/s
@@ -239,5 +294,4 @@
       !
    END SUBROUTINE tra_mle_trp
-
 
    SUBROUTINE tra_mle_init
@@ -301,5 +355,5 @@
             IF( ierr /= 0 )   CALL ctl_stop( 'tra_adv_mle_init: failed to allocate arrays' )
             z1_t2 = 1._wp / ( rn_time * rn_time )
-            DO_2D( nn_hls-1, nn_hls, nn_hls-1, nn_hls )                      ! "coriolis+ time^-1" at u- & v-points
+            DO_2D( 0, 1, 0, 1 )                      ! "coriolis+ time^-1" at u- & v-points
                zfu = ( ff_f(ji,jj) + ff_f(ji,jj-1) ) * 0.5_wp
                zfv = ( ff_f(ji,jj) + ff_f(ji-1,jj) ) * 0.5_wp
@@ -307,5 +361,5 @@
                rfv(ji,jj) = SQRT(  zfv * zfv + z1_t2 )
             END_2D
-            IF (nn_hls.EQ.1) CALL lbc_lnk_multi( 'tramle', rfu, 'U', 1.0_wp , rfv, 'V', 1.0_wp )
+            CALL lbc_lnk_multi( 'tramle', rfu, 'U', 1.0_wp , rfv, 'V', 1.0_wp )
             !
          ELSEIF( nn_mle == 1 ) THEN           ! MLE array allocation & initialisation
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traqsr.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traqsr.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/traqsr.F90	(revision 14062)
@@ -144,5 +144,5 @@
 
       IF( kt == nit000 ) THEN          !==  1st time step  ==!
-         IF( ln_rstart .AND. iom_varid( numror, 'qsr_hc_b', ldstop = .FALSE. ) > 0  .AND. .NOT.l_1st_euler ) THEN    ! read in restart
+         IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN    ! read in restart
             z1_2 = 0.5_wp
             IF( ntile == 0 .OR. ntile == 1 )  THEN                        ! Do only on the first tile
@@ -150,5 +150,5 @@
                CALL iom_get( numror, jpdom_auto, 'qsr_hc_b', qsr_hc_b )   ! before heat content trend due to Qsr flux
             ENDIF
-         ELSE                                           ! No restart or restart not found: Euler forward time stepping
+         ELSE                                           ! No restart or Euler forward at 1st time step
             z1_2 = 1._wp
             DO_3D( isj, iej, isi, iei, 1, jpk )
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/trasbc.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/trasbc.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRA/trasbc.F90	(revision 14062)
@@ -72,7 +72,7 @@
       !!              - send trends to trdtra module for further diagnostics(l_trdtra=T)
       !!----------------------------------------------------------------------
-      INTEGER,                                   INTENT(in   ) :: kt         ! ocean time-step index
-      INTEGER,                                   INTENT(in   ) :: Kmm, Krhs  ! time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts,jpt), INTENT(inout) :: pts        ! active tracers and RHS of tracer equation
+      INTEGER,                                   INTENT(in   ) ::   kt         ! ocean time-step index
+      INTEGER,                                   INTENT(in   ) ::   Kmm, Krhs  ! time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts,jpt), INTENT(inout) ::   pts        ! active tracers and RHS of tracer Eq.
       !
       INTEGER  ::   ji, jj, jk, jn               ! dummy loop indices
@@ -117,6 +117,5 @@
       !                             !==  Set before sbc tracer content fields  ==!
       IF( kt == nit000 ) THEN             !* 1st time-step
-         IF( ln_rstart .AND.    &               ! Restart: read in restart file
-              & iom_varid( numror, 'sbc_hc_b', ldstop = .FALSE. ) > 0 ) THEN
+         IF( ln_rstart .AND. .NOT.l_1st_euler ) THEN      ! Restart: read in restart file
             zfact = 0.5_wp
             IF( ntile == 0 .OR. ntile == 1 )  THEN                       ! Do only on the first tile
@@ -126,5 +125,5 @@
                CALL iom_get( numror, jpdom_auto, 'sbc_sc_b', sbc_tsc_b(:,:,jp_sal) )   ! before salt content sbc trend
             ENDIF
-         ELSE                                   ! No restart or restart not found: Euler forward time stepping
+         ELSE                                             ! No restart or restart not found: Euler forward time stepping
             zfact = 1._wp
             DO_2D( isj, iej, isi, iei )
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRD/trd_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRD/trd_oce.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/TRD/trd_oce.F90	(revision 14062)
@@ -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/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/USR/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/USR/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/USR/usrdef_istate.F90	(revision 14062)
@@ -7,5 +7,6 @@
    !! User defined : set the initial state of a user configuration
    !!======================================================================
-   !! History :  4.0 ! 2016-03  (S. Flavoni) Original code
+   !! History :  4.0  ! 2016-03  (S. Flavoni) Original code
+   !!                 ! 2020-11  (S. Techene, G. Madec) separate tsuv from ssh
    !!----------------------------------------------------------------------
 
@@ -22,5 +23,6 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called in istate.F90
+   PUBLIC   usr_def_istate       ! called in istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by domqco.F90
 
    !! * Substitutions
@@ -33,5 +35,5 @@
 CONTAINS
   
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -48,5 +50,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
       !
       INTEGER :: ji, jj, jk  ! dummy loop indices
@@ -59,5 +60,4 @@
       pu  (:,:,:) = 0._wp           ! ocean at rest
       pv  (:,:,:) = 0._wp
-      pssh(:,:)   = 0._wp
       !
       DO_3D( 1, 1, 1, 1, 1, jpk )   ! horizontally uniform T & S profiles
@@ -80,4 +80,26 @@
    END SUBROUTINE usr_def_istate
 
+   
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of ssh
+      !!
+      !! ** Method  :   Set ssh as null, ptmask is required for test cases
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask   [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height   [m]
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : GYRE configuration, analytical definition of initial state'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~~   Ocean at rest, ssh is zero'
+      !
+      ! Sea level:
+      pssh(:,:) = 0._wp
+      !
+   END SUBROUTINE usr_def_istate_ssh
+
    !!======================================================================
 END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfddm.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfddm.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfddm.F90	(revision 14062)
@@ -31,4 +31,5 @@
    !! * Substitutions
 #  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfosm.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfosm.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfosm.F90	(revision 14062)
@@ -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,14 +86,28 @@
    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
+   REAL(wp) ::   rn_zdfosm_adjust_sd = 1.0 ! factor to reduce Stokes drift by
+   REAL(wp) ::   rn_osm_hblfrac = 0.1! for nn_osm_wave = 3/4 specify fraction in top of hbl
+   LOGICAL  ::   ln_zdfosm_ice_shelter      ! flag to activate ice sheltering
    REAL(wp) ::   rn_osm_hbl0 = 10._wp       ! Initial value of hbl for 1D runs
    INTEGER  ::   nn_ave             ! = 0/1 flag for horizontal average on avt
    INTEGER  ::   nn_osm_wave = 0    ! = 0/1/2 flag for getting stokes drift from La# / PM wind-waves/Inputs into sbcwave
+   INTEGER  ::   nn_osm_SD_reduce   ! = 0/1/2 flag for getting effective stokes drift from surface value
    LOGICAL  ::   ln_dia_osm         ! Use namelist  rn_osm_la
 
@@ -96,6 +119,26 @@
    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
+   LOGICAL  ::   ln_osm_hmle_limit           ! If true arbitrarily restrict hmle to rn_osm_hmle_limit*zmld
+   REAL(wp) ::   rn_osm_hmle_limit           ! If ln_osm_hmle_limit true arbitrarily restrict hmle to rn_osm_hmle_limit*zmld
+   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 /rho0 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_bl_thresh          ! Threshold buoyancy for deepening of 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
@@ -118,9 +161,14 @@
       !!                 ***  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 )
+
+     CALL mpp_sum ( 'zdfosm', zdf_osm_alloc )
      IF( zdf_osm_alloc /= 0 )   CALL ctl_warn('zdf_osm_alloc: failed to allocate zdf_osm arrays')
-     CALL mpp_sum ( 'zdfosm', zdf_osm_alloc )
+
    END FUNCTION zdf_osm_alloc
 
@@ -166,4 +214,7 @@
       !!
       INTEGER ::   ji, jj, jk                   ! dummy loop indices
+
+      INTEGER ::   jl                   ! dummy loop indices
+
       INTEGER ::   ikbot, jkmax, jkm1, jkp2     !
 
@@ -196,4 +247,12 @@
       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_min
+
+
+      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
@@ -201,5 +260,9 @@
       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
+      LOGICAL, DIMENSION(jpi,jpj)  :: lshear    ! Shear layers
+      LOGICAL, DIMENSION(jpi,jpj)  :: lpyc      ! OSBL pycnocline present
+      LOGICAL, DIMENSION(jpi,jpj)  :: lflux     ! surface flux extends below OSBL into MLE layer.
+      LOGICAL, DIMENSION(jpi,jpj)  :: lmle      ! MLE layer increases in hickness.
 
       ! mixed-layer variables
@@ -207,4 +270,6 @@
       INTEGER, DIMENSION(jpi,jpj) :: ibld ! level of boundary layer base
       INTEGER, DIMENSION(jpi,jpj) :: imld ! level of mixed-layer depth (pycnocline top)
+      INTEGER, DIMENSION(jpi,jpj) :: jp_ext, jp_ext_mle ! offset for external level
+      INTEGER, DIMENSION(jpi, jpj) :: j_ddh ! Type of shear layer
 
       REAL(wp) :: ztgrad,zsgrad,zbgrad ! Temporary variables used to calculate pycnocline gradients
@@ -213,12 +278,24 @@
       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) :: 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
-      REAL(wp), DIMENSION(jpi,jpj) :: zdt_bl,zds_bl,zdu_bl,zdv_bl,zdrh_bl,zdb_bl ! difference between blayer average and parameter at base of blayer
-      REAL(wp), DIMENSION(jpi,jpj) :: zdt_ml,zds_ml,zdu_ml,zdv_ml,zdrh_ml,zdb_ml ! difference between mixed layer average and parameter at base of blayer
-      REAL(wp), DIMENSION(jpi,jpj) :: zwth_ent,zws_ent ! heat and salinity fluxes at the top of the pycnocline
-      REAL(wp), DIMENSION(jpi,jpj) :: zuw_bse,zvw_bse  ! momentum fluxes at the top of the pycnocline
+      REAL(wp), DIMENSION(jpi,jpj) :: zddhdt                                    ! correction to dhdt due to internal structure.
+      REAL(wp), DIMENSION(jpi,jpj) :: zdtdz_bl_ext,zdsdz_bl_ext,zdbdz_bl_ext              ! external temperature/salinity and buoyancy gradients
+      REAL(wp), DIMENSION(jpi,jpj) :: zdtdz_mle_ext,zdsdz_mle_ext,zdbdz_mle_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,zb_bl  ! averages over the depth of the blayer
+      REAL(wp), DIMENSION(jpi,jpj) :: zt_ml,zs_ml,zu_ml,zv_ml,zb_ml  ! averages over the depth of the mixed layer
+      REAL(wp), DIMENSION(jpi,jpj) :: zt_mle,zs_mle,zu_mle,zv_mle,zb_mle  ! averages over the depth of the MLE layer
+      REAL(wp), DIMENSION(jpi,jpj) :: zdt_bl,zds_bl,zdu_bl,zdv_bl,zdb_bl ! difference between blayer average and parameter at base of blayer
+      REAL(wp), DIMENSION(jpi,jpj) :: zdt_ml,zds_ml,zdu_ml,zdv_ml,zdb_ml ! difference between mixed layer average and parameter at base of blayer
+      REAL(wp), DIMENSION(jpi,jpj) :: zdt_mle,zds_mle,zdu_mle,zdv_mle,zdb_mle ! difference between MLE layer average and parameter at base of blayer
+!      REAL(wp), DIMENSION(jpi,jpj) :: zwth_ent,zws_ent ! heat and salinity fluxes at the top of the pycnocline
+      REAL(wp) :: zwth_ent,zws_ent ! heat and salinity fluxes at the top of the pycnocline
+      REAL(wp) :: zuw_bse,zvw_bse  ! momentum fluxes at the top of the pycnocline
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdtdz_pyc    ! parametrized gradient of temperature in pycnocline
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdsdz_pyc    ! parametrised gradient of salinity in pycnocline
@@ -226,11 +303,13 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdudz_pyc    ! u-shear across the pycnocline
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdvdz_pyc    ! v-shear across the pycnocline
-
+      REAL(wp), DIMENSION(jpi,jpj) :: zdbds_mle    ! Magnitude of horizontal buoyancy gradient.
       ! Flux-gradient relationship variables
+      REAL(wp), DIMENSION(jpi, jpj) :: zshear, zri_i ! Shear production and interfacial richardon number.
 
       REAL(wp) :: zl_c,zl_l,zl_eps  ! Used to calculate turbulence length scale.
 
-      REAL(wp), DIMENSION(jpi,jpj) :: zdifml_sc,zvisml_sc,zdifpyc_sc,zvispyc_sc,zbeta_d_sc,zbeta_v_sc ! Scales for eddy diffusivity/viscosity
+      REAL(wp) :: za_cubic, zb_cubic, zc_cubic, zd_cubic ! coefficients in cubic polynomial specifying diffusivity in pycnocline.  
       REAL(wp), DIMENSION(jpi,jpj) :: zsc_wth_1,zsc_ws_1 ! Temporary scales used to calculate scalar non-gradient terms.
+      REAL(wp), DIMENSION(jpi,jpj) :: zsc_wth_pyc, zsc_ws_pyc ! Scales for pycnocline transport term/
       REAL(wp), DIMENSION(jpi,jpj) :: zsc_uw_1,zsc_uw_2,zsc_vw_1,zsc_vw_2 ! Temporary scales for non-gradient momentum flux terms.
       REAL(wp), DIMENSION(jpi,jpj) :: zhbl_t ! holds boundary layer depth updated by full timestep
@@ -243,13 +322,23 @@
       ! 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
       REAL(wp) :: zthick, zz0, zz1 ! temporary variables
       REAL(wp) :: zvel_max, zhbl_s ! temporary variables
-      REAL(wp) :: zfac             ! temporary variable
+      REAL(wp) :: zfac, ztmp       ! temporary variable
       REAL(wp) :: zus_x, zus_y     ! temporary Stokes drift
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zviscos ! viscosity
       REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdiffut ! t-diffusivity
+      REAL(wp), DIMENSION(jpi,jpj) :: zalpha_pyc
+      REAL(wp), DIMENSION(jpi,jpj) :: ztau_sc_u ! dissipation timescale at baes of WML.
+      REAL(wp) :: zdelta_pyc, zwt_pyc_sc_1, zws_pyc_sc_1, zzeta_pyc
+      REAL(wp) :: zbuoy_pyc_sc, zomega, zvw_max
+      INTEGER :: ibld_ext=0                          ! does not have to be zero for modified scheme
+      REAL(wp) :: zgamma_b_nd, zgamma_b, zdhoh, ztau
+      REAL(wp) :: zzeta_s = 0._wp
+      REAL(wp) :: zzeta_v = 0.46
+      REAL(wp) :: zabsstke
+      REAL(wp) :: zsqrtpi, z_two_thirds, zproportion, ztransp, zthickness
+      REAL(wp) :: z2k_times_thickness, zsqrt_depth, zexp_depth, zdstokes0, zf, zexperfc
 
       ! For debugging
@@ -257,7 +346,4 @@
       !!--------------------------------------------------------------------
       !
-      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
@@ -267,22 +353,35 @@
       zustke(:,:) = 0._wp ; zla(:,:)   = 0._wp ; zcos_wind(:,:) = 0._wp ; zsin_wind(:,:) = 0._wp
       zhol(:,:)   = 0._wp
-      lconv(:,:)  = .FALSE.
+      lconv(:,:)  = .FALSE.; lpyc(:,:) = .FALSE. ; lflux(:,:) = .FALSE. ;  lmle(:,:) = .FALSE.
       ! mixed layer
       ! no initialization of zhbl or zhml (or zdh?)
       zhbl(:,:)    = 1._wp ; zhml(:,:)    = 1._wp ; zdh(:,:)      = 1._wp ; zdhdt(:,:)   = 0._wp
-      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
+      zt_bl(:,:)   = 0._wp ; zs_bl(:,:)   = 0._wp ; zu_bl(:,:)    = 0._wp
+      zv_bl(:,:)   = 0._wp ; zb_bl(:,:)  = 0._wp
+      zt_ml(:,:)   = 0._wp ; zs_ml(:,:)    = 0._wp ; zu_ml(:,:)   = 0._wp
+      zt_mle(:,:)   = 0._wp ; zs_mle(:,:)    = 0._wp ; zu_mle(:,:)   = 0._wp
+      zb_mle(:,:) = 0._wp
+      zv_ml(:,:)   = 0._wp ; zdt_bl(:,:)   = 0._wp ; zds_bl(:,:)  = 0._wp
+      zdu_bl(:,:)  = 0._wp ; zdv_bl(:,:)  = 0._wp ; zdb_bl(:,:)  = 0._wp
       zdt_ml(:,:)  = 0._wp ; zds_ml(:,:)  = 0._wp ; zdu_ml(:,:)   = 0._wp ; zdv_ml(:,:)  = 0._wp
-      zdrh_ml(:,:) = 0._wp ; zdb_ml(:,:)  = 0._wp ; zwth_ent(:,:) = 0._wp ; zws_ent(:,:) = 0._wp
-      zuw_bse(:,:) = 0._wp ; zvw_bse(:,:) = 0._wp
+      zdb_ml(:,:)  = 0._wp
+      zdt_mle(:,:)  = 0._wp ; zds_mle(:,:)  = 0._wp ; zdu_mle(:,:)   = 0._wp
+      zdv_mle(:,:)  = 0._wp ; zdb_mle(:,:)  = 0._wp
+      zwth_ent = 0._wp ; zws_ent = 0._wp
       !
       zdtdz_pyc(:,:,:) = 0._wp ; zdsdz_pyc(:,:,:) = 0._wp ; zdbdz_pyc(:,:,:) = 0._wp
       zdudz_pyc(:,:,:) = 0._wp ; zdvdz_pyc(:,:,:) = 0._wp
       !
+      zdtdz_bl_ext(:,:) = 0._wp ; zdsdz_bl_ext(:,:) = 0._wp ; zdbdz_bl_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
-      zvispyc_sc(:,:) = 0._wp ; zbeta_d_sc(:,:) = 0._wp ; zbeta_v_sc(:,:) = 0._wp
       zsc_wth_1(:,:)  = 0._wp ; zsc_ws_1(:,:)   = 0._wp ; zsc_uw_1(:,:)   = 0._wp
       zsc_uw_2(:,:)   = 0._wp ; zsc_vw_1(:,:)   = 0._wp ; zsc_vw_2(:,:)   = 0._wp
@@ -292,4 +391,5 @@
       ghams(:,:,:)   = 0._wp ; ghamu(:,:,:)   = 0._wp ; ghamv(:,:,:) = 0._wp
 
+      zddhdt(:,:) = 0._wp
       ! hbl = MAX(hbl,epsln)
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -326,6 +426,6 @@
         zwbav(ji,jj) = grav  * zthermal * zwthav(ji,jj) - grav  * zbeta * zwsav(ji,jj)
         ! Surface upward velocity fluxes
-        zuw0(ji,jj) = -utau(ji,jj) * r1_rho0 * tmask(ji,jj,1)
-        zvw0(ji,jj) = -vtau(ji,jj) * r1_rho0 * tmask(ji,jj,1)
+        zuw0(ji,jj) = - 0.5 * (utau(ji-1,jj) + utau(ji,jj)) * r1_rho0 * tmask(ji,jj,1)
+        zvw0(ji,jj) = - 0.5 * (vtau(ji,jj-1) + vtau(ji,jj)) * r1_rho0 * tmask(ji,jj,1)
         ! Friction velocity (zustar), at T-point : LMD94 eq. 2
         zustar(ji,jj) = MAX( SQRT( SQRT( zuw0(ji,jj) * zuw0(ji,jj) + zvw0(ji,jj) * zvw0(ji,jj) ) ), 1.0e-8 )
@@ -340,6 +440,7 @@
            zus_x = zcos_wind(ji,jj) * zustar(ji,jj) / 0.3**2
            zus_y = zsin_wind(ji,jj) * zustar(ji,jj) / 0.3**2
+           ! Linearly
            zustke(ji,jj) = MAX ( SQRT( zus_x*zus_x + zus_y*zus_y), 1.0e-8 )
-           ! dstokes(ji,jj) set to constant value rn_osm_dstokes from namelist in zdf_osm_init
+           dstokes(ji,jj) = rn_osm_dstokes
         END_2D
      ! Assume Pierson-Moskovitz wind-wave spectrum
@@ -347,18 +448,81 @@
         DO_2D( 0, 0, 0, 0 )
            ! 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
+           zustke(ji,jj) =  MAX ( 0.016 * wndm(ji,jj), 1.0e-8 )
+           dstokes(ji,jj) = MAX ( 0.12 * wndm(ji,jj)**2 / grav, 5.e-1)
         END_2D
      ! Use ECMWF wave fields as output from SBCWAVE
      CASE(2)
         zfac =  2.0_wp * rpi / 16.0_wp
+
         DO_2D( 0, 0, 0, 0 )
-           ! The Langmur number from the ECMWF model appears to give La<0.3 for wind-driven seas.
-           !    The coefficient 0.8 gives La=0.3  in this situation.
-           ! 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 !
+           IF (hsw(ji,jj) > 1.e-4) THEN
+              ! Use  wave fields
+              zabsstke = SQRT(ut0sd(ji,jj)**2 + vt0sd(ji,jj)**2)
+              zustke(ji,jj) = MAX ( ( 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)
+           ELSE
+              ! Assume masking issue (e.g. ice in ECMWF reanalysis but not in model run)
+              ! .. so default to Pierson-Moskowitz
+              zustke(ji,jj) = MAX ( 0.016 * wndm(ji,jj), 1.0e-8 )
+              dstokes(ji,jj) = MAX ( 0.12 * wndm(ji,jj)**2 / grav, 5.e-1)
+           END IF
+        END_2D
+     END SELECT
+
+     IF (ln_zdfosm_ice_shelter) THEN
+        ! Reduce both Stokes drift and its depth scale by ocean fraction to represent sheltering by ice
+        DO_2D( 0, 0, 0, 0 )
+           zustke(ji,jj) = zustke(ji,jj) * (1.0_wp - fr_i(ji,jj))
+           dstokes(ji,jj) = dstokes(ji,jj) * (1.0_wp - fr_i(ji,jj))
+        END_2D
+     END IF
+
+     SELECT CASE (nn_osm_SD_reduce)
+     ! Reduce surface Stokes drift by a constant factor or following Breivik (2016) + van  Roekel (2012) or Grant (2020).
+     CASE(0)
+        ! The Langmur number from the ECMWF model (or from PM)  appears to give La<0.3 for wind-driven seas.
+        !    The coefficient rn_zdfosm_adjust_sd = 0.8 gives La=0.3  in this situation.
+        ! It could represent the effects of the spread of wave directions
+        ! around the mean wind. The effect of this adjustment needs to be tested.
+        IF(nn_osm_wave > 0) THEN
+           zustke(2:jpim1,2:jpjm1) = rn_zdfosm_adjust_sd * zustke(2:jpim1,2:jpjm1)
+        END IF
+     CASE(1)
+        ! van  Roekel (2012): consider average SD over top 10% of boundary layer
+        ! assumes approximate depth profile of SD from Breivik (2016)
+        zsqrtpi = SQRT(rpi)
+        z_two_thirds = 2.0_wp / 3.0_wp
+
+        DO_2D( 0, 0, 0, 0 )
+           zthickness = rn_osm_hblfrac*hbl(ji,jj)
+           z2k_times_thickness =  zthickness * 2.0_wp / MAX( ABS( 5.97_wp * dstokes(ji,jj) ), 0.0000001_wp )
+           zsqrt_depth = SQRT(z2k_times_thickness)
+           zexp_depth  = EXP(-z2k_times_thickness)
+           zustke(ji,jj) = zustke(ji,jj) * (1.0_wp - zexp_depth  &
+                &              - z_two_thirds * ( zsqrtpi*zsqrt_depth*z2k_times_thickness * ERFC(zsqrt_depth) &
+                &              + 1.0_wp - (1.0_wp + z2k_times_thickness)*zexp_depth ) ) / z2k_times_thickness
+
+        END_2D
+     CASE(2)
+        ! Grant (2020): Match to exponential with same SD and d/dz(Sd) at depth 10% of boundary layer
+        ! assumes approximate depth profile of SD from Breivik (2016)
+        zsqrtpi = SQRT(rpi)
+
+        DO_2D( 0, 0, 0, 0 )
+           zthickness = rn_osm_hblfrac*hbl(ji,jj)
+           z2k_times_thickness =  zthickness * 2.0_wp / MAX( ABS( 5.97_wp * dstokes(ji,jj) ), 0.0000001_wp )
+
+           IF(z2k_times_thickness < 50._wp) THEN
+              zsqrt_depth = SQRT(z2k_times_thickness)
+              zexperfc = zsqrtpi * zsqrt_depth * ERFC(zsqrt_depth) * EXP(z2k_times_thickness)
+           ELSE
+              ! asymptotic expansion of sqrt(pi)*zsqrt_depth*EXP(z2k_times_thickness)*ERFC(zsqrt_depth) for large z2k_times_thickness
+              ! See Abramowitz and Stegun, Eq. 7.1.23
+              ! zexperfc = 1._wp - (1/2)/(z2k_times_thickness)  + (3/4)/(z2k_times_thickness**2) - (15/8)/(z2k_times_thickness**3)
+              zexperfc = ((- 1.875_wp/z2k_times_thickness + 0.75_wp)/z2k_times_thickness - 0.5_wp)/z2k_times_thickness + 1.0_wp
+           END IF
+           zf = z2k_times_thickness*(1.0_wp/zexperfc - 1.0_wp)
+           dstokes(ji,jj) = 5.97 * zf * dstokes(ji,jj)
+           zustke(ji,jj) = zustke(ji,jj) * EXP(z2k_times_thickness * ( 1.0_wp / (2. * zf) - 1.0_wp )) * ( 1.0_wp - zexperfc)
         END_2D
      END SELECT
@@ -369,12 +533,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  + &
@@ -383,5 +541,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
@@ -389,8 +546,6 @@
            zwstrc(ji,jj) = ( 2.0 * zwbav(ji,jj) * 0.9 * hbl(ji,jj) )**pthird
            zhol(ji,jj) = -0.9 * hbl(ji,jj) * 2.0 * zwbav(ji,jj) / (zvstr(ji,jj)**3 + epsln )
-           lconv(ji,jj) = .TRUE.
-        ELSE
+         ELSE
            zhol(ji,jj) = -hbl(ji,jj) *  2.0 * zwbav(ji,jj)/ (zvstr(ji,jj)**3  + epsln )
-           lconv(ji,jj) = .FALSE.
         ENDIF
      END_2D
@@ -399,86 +554,103 @@
      ! 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(:,:,3,Kmm) )
-      ibld(:,:) = 3
-      DO_3D( 0, 0, 0, 0, 4, jpkm1 )
+     ! 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.
+
+     ! agn 23/6/20: not clear all this is needed, as hbl checked after it is re-calculated anyway
+     ! ##########################################################################
+      hbl(:,:) = MAX(hbl(:,:), gdepw(:,:,4,Kmm) )
+      ibld(:,:) = 4
+      DO_3D( 1, 1, 1, 1, 5, jpkm1 )
          IF ( hbl(ji,jj) >= gdepw(ji,jj,jk,Kmm) ) THEN
             ibld(ji,jj) = MIN(mbkt(ji,jj), jk)
          ENDIF
       END_3D
+     ! ##########################################################################
 
       DO_2D( 0, 0, 0, 0 )
-            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(ji,jj,jm,Kmm)
-               zt   = zt  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_tem,Kmm)
-               zs   = zs  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_sal,Kmm)
-               zu   = zu  + e3t(ji,jj,jm,Kmm) &
-                  &            * ( uu(ji,jj,jm,Kbb) + uu(ji - 1,jj,jm,Kbb) ) &
-                  &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-               zv   = zv  + e3t(ji,jj,jm,Kmm) &
-                  &            * ( vv(ji,jj,jm,Kbb) + vv(ji,jj - 1,jm,Kbb) ) &
-                  &            / 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) - ts(ji,jj,ibld(ji,jj),jp_tem,Kmm)
-            zds_bl(ji,jj) = zs_bl(ji,jj) - ts(ji,jj,ibld(ji,jj),jp_sal,Kmm)
-            zdu_bl(ji,jj) = zu_bl(ji,jj) - ( uu(ji,jj,ibld(ji,jj),Kbb) + uu(ji-1,jj,ibld(ji,jj) ,Kbb) ) &
-                  &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-            zdv_bl(ji,jj) = zv_bl(ji,jj) - ( vv(ji,jj,ibld(ji,jj),Kbb) + vv(ji,jj-1,ibld(ji,jj) ,Kbb) ) &
-                  &   / 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_Dt / 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_Dt / 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_Dt / hbl(ji,jj) ) * zwstrl(ji,jj)**2 / hbl(ji,jj)
-                   ELSE
-                      zpert   = 2.0 * ( 1.0 + 2.0 * zwstrl(ji,jj) * rn_Dt / 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
+         zhbl(ji,jj) = gdepw(ji,jj,ibld(ji,jj),Kmm)
+         imld(ji,jj) = MAX(3,ibld(ji,jj) - MAX( INT( dh(ji,jj) / e3t(ji, jj, ibld(ji,jj), Kmm )) , 1 ))
+         zhml(ji,jj) = gdepw(ji,jj,imld(ji,jj),Kmm)
+         zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
       END_2D
-
-      ! Calculate averages over depth of boundary layer
-      imld = ibld           ! use imld to hold previous blayer index
-      ibld(:,:) = 3
-
-      zhbl_t(:,:) = hbl(:,:) + (zdhdt(:,:) - ww(ji,jj,ibld(ji,jj)))* rn_Dt ! certainly need wb here, so subtract it
-      zhbl_t(:,:) = MIN(zhbl_t(:,:), ht(:,:))
-      zdhdt(:,:) = MIN(zdhdt(:,:), (zhbl_t(:,:) - hbl(:,:))/rn_Dt + ww(ji,jj,ibld(ji,jj))) ! adjustment to represent limiting by ocean bottom
+      ! Averages over well-mixed and boundary layer
+      jp_ext(:,:) = 2
+      CALL zdf_osm_vertical_average(ibld, jp_ext, zt_bl, zs_bl, zb_bl, zu_bl, zv_bl, zdt_bl, zds_bl, zdb_bl, zdu_bl, zdv_bl)
+!      jp_ext(:,:) = ibld(:,:) - imld(:,:) + 1
+      CALL zdf_osm_vertical_average(ibld, ibld-imld+1, zt_ml, zs_ml, zb_ml, zu_ml, zv_ml, zdt_ml, zds_ml, zdb_ml, zdu_ml, zdv_ml)
+! Velocity components in frame aligned with surface stress.
+      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 )
+! Determine the state of the OSBL, stable/unstable, shear/no shear
+      CALL zdf_osm_osbl_state( lconv, lshear, j_ddh, zwb_ent, zwb_min, zshear, zri_i )
+
+      IF ( ln_osm_mle ) THEN
+! Fox-Kemper Scheme
+         mld_prof = 4
+         DO_3D( 0, 0, 0, 0, 5, jpkm1 )
+         IF ( hmle(ji,jj) >= gdepw(ji,jj,jk,Kmm) ) mld_prof(ji,jj) = MIN(mbkt(ji,jj), jk)
+         END_3D
+         jp_ext_mle(:,:) = 2
+        CALL zdf_osm_vertical_average(mld_prof, jp_ext_mle, zt_mle, zs_mle, zb_mle, zu_mle, zv_mle, zdt_mle, zds_mle, zdb_mle, zdu_mle, zdv_mle)
+
+         DO_2D( 0, 0, 0, 0 )
+           zhmle(ji,jj) = gdepw(ji,jj,mld_prof(ji,jj),Kmm)
+         END_2D
+
+!! External gradient
+         CALL zdf_osm_external_gradients( ibld+2, zdtdz_bl_ext, zdsdz_bl_ext, zdbdz_bl_ext )
+         CALL zdf_osm_zmld_horizontal_gradients( zmld, zdtdx, zdtdy, zdsdx, zdsdy, dbdx_mle, dbdy_mle, zdbds_mle )
+         CALL zdf_osm_external_gradients( mld_prof, zdtdz_mle_ext, zdsdz_mle_ext, zdbdz_mle_ext )
+         CALL zdf_osm_osbl_state_fk( lpyc, lflux, lmle, zwb_fk )
+         CALL zdf_osm_mle_parameters( mld_prof, hmle, zhmle, zvel_mle, zdiff_mle )
+      ELSE    ! ln_osm_mle
+! FK not selected, Boundary Layer only.
+         lpyc(:,:) = .TRUE.
+         lflux(:,:) = .FALSE.
+         lmle(:,:) = .FALSE.
+         DO_2D( 0, 0, 0, 0 )
+          IF ( lconv(ji,jj) .AND. zdb_bl(ji,jj) < rn_osm_bl_thresh ) lpyc(ji,jj) = .FALSE.
+         END_2D
+      ENDIF   ! ln_osm_mle
+
+! Test if pycnocline well resolved
+      DO_2D( 0, 0, 0, 0 )
+       IF (lconv(ji,jj) ) THEN
+          ztmp = 0.2 * zhbl(ji,jj) / e3w(ji,jj,ibld(ji,jj),Kmm)
+          IF ( ztmp > 6 ) THEN
+   ! pycnocline well resolved
+            jp_ext(ji,jj) = 1
+          ELSE
+   ! pycnocline poorly resolved
+            jp_ext(ji,jj) = 0
+          ENDIF
+       ELSE
+   ! Stable conditions
+         jp_ext(ji,jj) = 0
+       ENDIF
+      END_2D
+
+      CALL zdf_osm_vertical_average(ibld, jp_ext, zt_bl, zs_bl, zb_bl, zu_bl, zv_bl, zdt_bl, zds_bl, zdb_bl, zdu_bl, zdv_bl )
+!      jp_ext = ibld-imld+1
+      CALL zdf_osm_vertical_average(imld-1, ibld-imld+1, zt_ml, zs_ml, zb_ml, zu_ml, zv_ml, zdt_ml, zds_ml, zdb_ml, zdu_ml, zdv_ml)
+! Rate of change of hbl
+      CALL zdf_osm_calculate_dhdt( zdhdt, zddhdt )
+      DO_2D( 0, 0, 0, 0 )
+       zhbl_t(ji,jj) = hbl(ji,jj) + (zdhdt(ji,jj) - ww(ji,jj,ibld(ji,jj)))* rn_Dt ! certainly need ww here, so subtract it
+            ! adjustment to represent limiting by ocean bottom
+       IF ( zhbl_t(ji,jj) >= gdepw(ji, jj, mbkt(ji,jj) + 1, Kmm ) ) THEN
+          zhbl_t(ji,jj) = MIN(zhbl_t(ji,jj), gdepw(ji,jj, mbkt(ji,jj) + 1, Kmm) - depth_tol)! ht(:,:))
+          lpyc(ji,jj) = .FALSE.
+       ENDIF
+      END_2D
+
+      imld(:,:) = ibld(:,:)           ! use imld to hold previous blayer index
+      ibld(:,:) = 4
 
       DO_3D( 0, 0, 0, 0, 4, jpkm1 )
          IF ( zhbl_t(ji,jj) >= gdepw(ji,jj,jk,Kmm) ) THEN
-            ibld(ji,jj) =  MIN(mbkt(ji,jj), jk)
+            ibld(ji,jj) = jk
          ENDIF
       END_3D
@@ -487,397 +659,38 @@
 ! Step through model levels taking account of buoyancy change to determine the effect on dhdt
 !
+      CALL zdf_osm_timestep_hbl( zdhdt )
+! is external level in bounds?
+
+      CALL zdf_osm_vertical_average( ibld, jp_ext, zt_bl, zs_bl, zb_bl, zu_bl, zv_bl, zdt_bl, zds_bl, zdb_bl, zdu_bl, zdv_bl )
+!
+!
+! Check to see if lpyc needs to be changed 
+
+      CALL zdf_osm_pycnocline_thickness( dh, zdh )
+
       DO_2D( 0, 0, 0, 0 )
-         IF ( ibld(ji,jj) - imld(ji,jj) > 1 ) THEN
+       IF ( zdb_bl(ji,jj) < rn_osm_bl_thresh .or. ibld(ji,jj) + jp_ext(ji,jj) >= mbkt(ji,jj) .or. ibld(ji,jj)-imld(ji,jj) == 1 ) lpyc(ji,jj) = .FALSE. 
+      END_2D
+
+      dstokes(:,:) = MIN ( dstokes(:,:), hbl(:,:)/3. )  !  Limit delta for shallow boundary layers for calculating flux-gradient terms.
 !
-! 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_Dt / 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) - ts(ji,jj,jm,jp_tem,Kmm) ) &
-                       & - zbeta * ( zs_bl(ji,jj) - ts(ji,jj,jm,jp_sal,Kmm) ) ), 0.0 ) + zvel_max
-
-                  zhbl_s = zhbl_s + MIN( - zwb_ent(ji,jj) / zdb * rn_Dt / FLOAT(ibld(ji,jj)-imld(ji,jj) ),   &
-                     &                     e3w(ji,jj,jk,Kmm) )
-                  zhbl_s = MIN(zhbl_s, ht(ji,jj))
-
-                  IF ( zhbl_s >= gdepw(ji,jj,jm+1,Kmm) ) 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) - ts(ji,jj,jm,jp_tem,Kmm) )          &
-                       &               - zbeta * ( zs_bl(ji,jj) - ts(ji,jj,jm,jp_sal,Kmm) ) ), 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(ji,jj,jk,Kmm) / zdhdt(ji,jj)  ! ALMG to investigate whether need to include ww here
-
-                  zhbl_s = MIN(zhbl_s, ht(ji,jj))
-                  IF ( zhbl_s >= gdepw(ji,jj,jm,Kmm) ) jm = jm + 1
-               END DO
-               hbl(ji,jj) = MAX(zhbl_s, gdepw(ji,jj,3,Kmm) )
-               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(ji,jj,3,Kmm) )
-               IF ( hbl(ji,jj) > hbli(ji,jj) ) hbli(ji,jj) = hbl(ji,jj)
-            ENDIF
-         ENDIF
-         zhbl(ji,jj) = gdepw(ji,jj,ibld(ji,jj),Kmm)
-      END_2D
-      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_2D( 0, 0, 0, 0 )
-            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(ji,jj,jm,Kmm)
-               zt   = zt  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_tem,Kmm)
-               zs   = zs  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_sal,Kmm)
-               zu   = zu  + e3t(ji,jj,jm,Kmm) &
-                  &            * ( uu(ji,jj,jm,Kbb) + uu(ji - 1,jj,jm,Kbb) ) &
-                  &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-               zv   = zv  + e3t(ji,jj,jm,Kmm) &
-                  &            * ( vv(ji,jj,jm,Kbb) + vv(ji,jj - 1,jm,Kbb) ) &
-                  &            / 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) - ts(ji,jj,ibld(ji,jj),jp_tem,Kmm)
-            zds_bl(ji,jj) = zs_bl(ji,jj) - ts(ji,jj,ibld(ji,jj),jp_sal,Kmm)
-            zdu_bl(ji,jj) = zu_bl(ji,jj) - ( uu(ji,jj,ibld(ji,jj),Kbb) + uu(ji-1,jj,ibld(ji,jj) ,Kbb) ) &
-                   &   / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-            zdv_bl(ji,jj) = zv_bl(ji,jj) - ( vv(ji,jj,ibld(ji,jj),Kbb) + vv(ji,jj-1,ibld(ji,jj) ,Kbb) ) &
-                   &  / 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(ji,jj,ibld(ji,jj),Kmm)
-            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(ji,jj,ibld(ji,jj),Kmm) ), 1 )
-                  imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 1)
-                  zhml(ji,jj) = gdepw(ji,jj,imld(ji,jj),Kmm)
-                  zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
-               ELSE  ! IF (zdb_bl)
-                  imld(ji,jj) = ibld(ji,jj) - 1
-                  zhml(ji,jj) = gdepw(ji,jj,imld(ji,jj),Kmm)
-                  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(ji,jj,ibld(ji,jj),Kmm) ), 1 )
-                     imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 1)
-                     zhml(ji,jj) = gdepw(ji,jj,imld(ji,jj),Kmm)
-                     zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
-                  ELSE
-                     imld(ji,jj) = ibld(ji,jj) - 1
-                     zhml(ji,jj) = gdepw(ji,jj,imld(ji,jj),Kmm)
-                     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_2D
-
-      ! Average over the depth of the mixed layer in the convective boundary layer
-      ! Also calculate entrainment fluxes for temperature and salinity
-      DO_2D( 0, 0, 0, 0 )
-         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(ji,jj,jm,Kmm)
-               zt   = zt  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_tem,Kmm)
-               zs   = zs  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_sal,Kmm)
-               zu   = zu  + e3t(ji,jj,jm,Kmm) &
-                  &            * ( uu(ji,jj,jm,Kbb) + uu(ji - 1,jj,jm,Kbb) ) &
-                  &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-               zv   = zv  + e3t(ji,jj,jm,Kmm) &
-                  &            * ( vv(ji,jj,jm,Kbb) + vv(ji,jj - 1,jm,Kbb) ) &
-                  &            / 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) - ts(ji,jj,ibld(ji,jj),jp_tem,Kmm)
-            zds_ml(ji,jj) = zs_ml(ji,jj) - ts(ji,jj,ibld(ji,jj),jp_sal,Kmm)
-            zdu_ml(ji,jj) = zu_ml(ji,jj) - ( uu(ji,jj,ibld(ji,jj),Kbb) + uu(ji-1,jj,ibld(ji,jj) ,Kbb) ) &
-                  &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-            zdv_ml(ji,jj) = zv_ml(ji,jj) - ( vv(ji,jj,ibld(ji,jj),Kbb) + vv(ji,jj-1,ibld(ji,jj) ,Kbb) ) &
-                  &    / 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(ji,jj,jm,Kmm)
-                  zt   = zt  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_tem,Kmm)
-                  zs   = zs  + e3t(ji,jj,jm,Kmm) * ts(ji,jj,jm,jp_sal,Kmm)
-                  zu   = zu  + e3t(ji,jj,jm,Kmm) &
-                     &            * ( uu(ji,jj,jm,Kbb) + uu(ji - 1,jj,jm,Kbb) ) &
-                     &            / MAX( 1. , umask(ji,jj,jm) + umask(ji - 1,jj,jm) )
-                  zv   = zv  + e3t(ji,jj,jm,Kmm) &
-                     &            * ( vv(ji,jj,jm,Kbb) + vv(ji,jj - 1,jm,Kbb) ) &
-                     &            / 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) - ts(ji,jj,ibld(ji,jj),jp_tem,Kmm)
-               zds_ml(ji,jj) = zs_ml(ji,jj) - ts(ji,jj,ibld(ji,jj),jp_sal,Kmm)
-               zdu_ml(ji,jj) = zu_ml(ji,jj) - ( uu(ji,jj,ibld(ji,jj),Kbb) + uu(ji-1,jj,ibld(ji,jj) ,Kbb) ) &
-                     &    / MAX(1. , umask(ji,jj,ibld(ji,jj) ) + umask(ji-1,jj,ibld(ji,jj) ) )
-               zdv_ml(ji,jj) = zv_ml(ji,jj) - ( vv(ji,jj,ibld(ji,jj),Kbb) + vv(ji,jj-1,ibld(ji,jj) ,Kbb) ) &
-                     &    / 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_2D
-    !
+    ! Average over the depth of the mixed layer in the convective boundary layer
+!      jp_ext = ibld - imld +1
+      CALL zdf_osm_vertical_average( imld-1, ibld-imld+1, zt_ml, zs_ml, zb_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_2D( 0, 0, 0, 0 )
-         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_2D
-
-     zuw_bse = 0._wp
-     zvw_bse = 0._wp
-     DO_2D( 0, 0, 0, 0 )
-
-        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)
-           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_2D
-
+     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 )
       !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       !  Pycnocline gradients for scalars and velocity
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
-       DO_2D( 0, 0, 0, 0 )
-       !
-          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(ji,jj,jk,Kmm) - 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(ji,jj,jk,Kmm) / 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(ji,jj,jk,Kmm) - 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_2D
-!
-       DO_2D( 0, 0, 0, 0 )
-       !
-          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(ji,jj,jk,Kmm) - 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(ji,jj,jk,Kmm) / 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_2D
+      CALL zdf_osm_external_gradients( ibld+2, zdtdz_bl_ext, zdsdz_bl_ext, zdbdz_bl_ext )
+      CALL zdf_osm_pycnocline_scalar_profiles( zdtdz_pyc, zdsdz_pyc, zdbdz_pyc, zalpha_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_2D( 0, 0, 0, 0 )
-          IF ( lconv(ji,jj) ) THEN
-            zdifml_sc(ji,jj) = zhml(ji,jj) * ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
-            zvisml_sc(ji,jj) = zdifml_sc(ji,jj)
-            zdifpyc_sc(ji,jj) = 0.165 * ( zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3 )**pthird * zdh(ji,jj)
-            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)
-          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_2D
-!
-       DO_2D( 0, 0, 0, 0 )
-          IF ( lconv(ji,jj) ) THEN
-             DO jk = 2, imld(ji,jj)   ! mixed layer diffusivity
-                 zznd_ml = gdepw(ji,jj,jk,Kmm) / zhml(ji,jj)
-                 !
-                 zdiffut(ji,jj,jk) = 0.8   * zdifml_sc(ji,jj) * zznd_ml * ( 1.0 - zbeta_d_sc(ji,jj) * zznd_ml    )**1.5
-                 !
-                 zviscos(ji,jj,jk) = 0.375 * zvisml_sc(ji,jj) * zznd_ml * ( 1.0 - zbeta_v_sc(ji,jj) * zznd_ml    ) &
-                      &            *                                      ( 1.0 -               0.5 * zznd_ml**2 )
-             END DO
-             ! pycnocline - if present linear profile
-             IF ( zdh(ji,jj) > 0._wp ) THEN
-                DO jk = imld(ji,jj)+1 , ibld(ji,jj)
-                    zznd_pyc = -( gdepw(ji,jj,jk,Kmm) - zhml(ji,jj) ) / zdh(ji,jj)
-                    !
-                    zdiffut(ji,jj,jk) = zdifpyc_sc(ji,jj) * ( 1.0 + zznd_pyc )
-                    !
-                    zviscos(ji,jj,jk) = zvispyc_sc(ji,jj) * ( 1.0 + zznd_pyc )
-                END DO
-             ENDIF
-             ! Temporay fix to ensure zdiffut is +ve; won't be necessary with ww taken out
-             zdiffut(ji,jj,ibld(ji,jj)) = zdhdt(ji,jj)* e3t(ji,jj,ibld(ji,jj),Kmm)
-             ! could be taken out, take account of entrainment represents as a diffusivity
-             ! should remove w from here, represents entrainment
-          ELSE
-          ! stable conditions
-             DO jk = 2, ibld(ji,jj)
-                zznd_ml = gdepw(ji,jj,jk,Kmm) / zhbl(ji,jj)
-                zdiffut(ji,jj,jk) = 0.75 * zdifml_sc(ji,jj) * zznd_ml * ( 1.0 - zznd_ml )**1.5
-                zviscos(ji,jj,jk) = 0.375 * zvisml_sc(ji,jj) * zznd_ml * (1.0 - zznd_ml) * ( 1.0 - zznd_ml**2 )
-             END DO
-          ENDIF   ! end if ( lconv )
-!
-       END_2D
+       CALL zdf_osm_diffusivity_viscosity( zdiffut, zviscos )
 
        !
@@ -918,15 +731,17 @@
        END_2D
 
-
 ! 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_2D( 0, 0, 0, 0 )
           IF ( lconv(ji,jj) ) THEN
@@ -970,10 +785,41 @@
                 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 )
                 ghams(ji,jj,jk) = ghams(ji,jj,jk) + 0.3 * 0.5 *  zsc_ws_1(ji,jj) * zl_eps * zhml(ji,jj) / ( 0.15 + zznd_ml )
              END DO
-          ELSE
+             
+             IF ( lpyc(ji,jj) ) THEN
+               ztau_sc_u(ji,jj) = zhml(ji,jj) / ( zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 )**pthird
+               ztau_sc_u(ji,jj) = ztau_sc_u(ji,jj) * ( 1.4 -0.4 / ( 1.0 + EXP( -3.5 * LOG10( -zhol(ji,jj) ) ) )**1.5 )
+               zwth_ent =  -0.003 * ( 0.15 * zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 )**pthird * ( 1.0 - zdh(ji,jj) /zhbl(ji,jj) ) * zdt_ml(ji,jj)                  
+               zws_ent =  -0.003 * ( 0.15 * zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 )**pthird * ( 1.0 - zdh(ji,jj) /zhbl(ji,jj) ) * zds_ml(ji,jj)
+! Cubic profile used for buoyancy term
+               za_cubic = 0.755 * ztau_sc_u(ji,jj)
+               zb_cubic = 0.25 * ztau_sc_u(ji,jj)
+               DO jk = 2, ibld(ji,jj)
+                 zznd_pyc = -( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) / zdh(ji,jj)
+                 ghamt(ji,jj,jk) = ghamt(ji,jj,jk) - 0.045 * ( ( zwth_ent * zdbdz_pyc(ji,jj,jk) ) * ztau_sc_u(ji,jj)**2 ) * MAX( ( 1.75 * zznd_pyc -0.15 * zznd_pyc**2 - 0.2 * zznd_pyc**3 ), 0.0 )
+
+                 ghams(ji,jj,jk) = ghams(ji,jj,jk) - 0.045 * ( ( zws_ent * zdbdz_pyc(ji,jj,jk) ) * ztau_sc_u(ji,jj)**2 ) * MAX( ( 1.75 * zznd_pyc -0.15 * zznd_pyc**2 - 0.2 * zznd_pyc**3 ), 0.0 )
+               END DO
+!
+               zbuoy_pyc_sc = zalpha_pyc(ji,jj) * zdb_ml(ji,jj) / zdh(ji,jj) + zdbdz_bl_ext(ji,jj)
+               zdelta_pyc = ( zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 )**pthird / SQRT( MAX( zbuoy_pyc_sc, ( zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 )**p2third / zdh(ji,jj)**2 ) )
+!
+               zwt_pyc_sc_1 = 0.325 * ( zalpha_pyc(ji,jj) * zdt_ml(ji,jj) / zdh(ji,jj) + zdtdz_bl_ext(ji,jj) ) * zdelta_pyc**2 / zdh(ji,jj)
+!
+               zws_pyc_sc_1 = 0.325 * ( zalpha_pyc(ji,jj) * zds_ml(ji,jj) / zdh(ji,jj) + zdsdz_bl_ext(ji,jj) ) * zdelta_pyc**2 / zdh(ji,jj)
+!
+               zzeta_pyc = 0.15 - 0.175 / ( 1.0 + EXP( -3.5 * LOG10( -zhol(ji,jj) ) ) ) 
+               DO jk = 2, ibld(ji,jj)
+                 zznd_pyc = -( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) / zdh(ji,jj)
+                 ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 0.05 * zwt_pyc_sc_1 * EXP( -0.25 * ( zznd_pyc / zzeta_pyc )**2 ) * zdh(ji,jj) / ( zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 )**pthird
+!
+                 ghams(ji,jj,jk) = ghams(ji,jj,jk) + 0.05 * zws_pyc_sc_1 * EXP( -0.25 * ( zznd_pyc / zzeta_pyc )**2 ) * zdh(ji,jj) / ( zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 )**pthird
+               END DO
+            ENDIF ! End of pycnocline                  
+          ELSE ! lconv test - stable conditions
              DO jk = 2, ibld(ji,jj)
                 ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + zsc_wth_1(ji,jj)
@@ -982,5 +828,4 @@
           ENDIF
        END_2D
-
 
        WHERE ( lconv )
@@ -1011,13 +856,54 @@
        END_2D
 
+       DO_2D( 0, 0, 0, 0 )
+        IF ( lpyc(ji,jj) ) THEN
+          IF ( j_ddh(ji,jj) == 0 ) THEN
+! Place holding code. Parametrization needs checking for these conditions.
+            zomega = ( 0.15 * zwstrl(ji,jj)**3 + zwstrc(ji,jj)**3 + 4.75 * ( zshear(ji,jj)* zhbl(ji,jj) )**pthird )**pthird
+            zuw_bse = -0.0035 * zomega * ( 1.0 - zdh(ji,jj) / zhbl(ji,jj) ) * zdu_ml(ji,jj)
+            zvw_bse = -0.0075 * zomega * ( 1.0 - zdh(ji,jj) / zhbl(ji,jj) ) * zdv_ml(ji,jj)
+          ELSE
+            zomega = ( 0.15 * zwstrl(ji,jj)**3 + zwstrc(ji,jj)**3 + 4.75 * ( zshear(ji,jj)* zhbl(ji,jj) )**pthird )**pthird
+            zuw_bse = -0.0035 * zomega * ( 1.0 - zdh(ji,jj) / zhbl(ji,jj) ) * zdu_ml(ji,jj)
+            zvw_bse = -0.0075 * zomega * ( 1.0 - zdh(ji,jj) / zhbl(ji,jj) ) * zdv_ml(ji,jj)
+          ENDIF
+          zd_cubic = zdh(ji,jj) / zhbl(ji,jj) * zuw0(ji,jj) - ( 2.0 + zdh(ji,jj) /zhml(ji,jj) ) * zuw_bse
+          zc_cubic = zuw_bse - zd_cubic
+! need ztau_sc_u to be available. Change to array. 
+          DO jk = imld(ji,jj), ibld(ji,jj)
+             zznd_pyc = - ( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) / zdh(ji,jj)
+             ghamu(ji,jj,jk) = ghamu(ji,jj,jk) - 0.045 * ztau_sc_u(ji,jj)**2 * ( zc_cubic * zznd_pyc**2 + zd_cubic * zznd_pyc**3 ) * ( 0.75 + 0.25 * zznd_pyc )**2 * zdbdz_pyc(ji,jj,jk)
+          END DO
+          zvw_max = 0.7 * ff_t(ji,jj) * ( zustke(ji,jj) * dstokes(ji,jj) + 0.75 * zustar(ji,jj) * zhml(ji,jj) )
+          zd_cubic = zvw_max * zdh(ji,jj) / zhml(ji,jj) - ( 2.0 + zdh(ji,jj) /zhml(ji,jj) ) * zvw_bse
+          zc_cubic = zvw_bse - zd_cubic
+          DO jk = imld(ji,jj), ibld(ji,jj)
+            zznd_pyc = -( gdepw(ji,jj,jk,Kmm) -zhbl(ji,jj) ) / zdh(ji,jj)
+            ghamv(ji,jj,jk) = ghamv(ji,jj,jk) - 0.045 * ztau_sc_u(ji,jj)**2 * ( zc_cubic * zznd_pyc**2 + zd_cubic * zznd_pyc**3 ) * ( 0.75 + 0.25 * zznd_pyc )**2 * zdbdz_pyc(ji,jj,jk)
+          END DO
+        ENDIF  ! lpyc
+       END_2D
+
+       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) ]
 
-       WHERE ( lconv )
-          zsc_wth_1 = zwth0
-          zsc_ws_1 = zws0
-       ELSEWHERE
-          zsc_wth_1 = 2.0 * zwthav
-          zsc_ws_1 = zws0
-       ENDWHERE
+       DO_2D( 1, 0, 1, 0 )
+       
+         IF ( lconv(ji,jj) ) THEN
+           zsc_wth_1(ji,jj) = zwth0(ji,jj) / ( 1.0 - 0.56 * EXP( zhol(ji,jj) ) )
+           zsc_ws_1(ji,jj) = zws0(ji,jj) / (1.0 - 0.56 *EXP( zhol(ji,jj) ) )
+           IF ( lpyc(ji,jj) ) THEN
+! Pycnocline scales
+              zsc_wth_pyc(ji,jj) = -0.2 * zwb0(ji,jj) * zdt_bl(ji,jj) / zdb_bl(ji,jj)
+              zsc_ws_pyc(ji,jj) = -0.2 * zwb0(ji,jj) * zds_bl(ji,jj) / zdb_bl(ji,jj)
+            ENDIF
+         ELSE
+           zsc_wth_1(ji,jj) = 2.0 * zwthav(ji,jj)
+           zsc_ws_1(ji,jj) = zws0(ji,jj)
+         ENDIF
+       END_2D
 
        DO_2D( 0, 0, 0, 0 )
@@ -1035,16 +921,26 @@
                     &          * ( 1.0 - EXP ( -15.0 * (         1.0 - zznd_ml    ) ) )
             END DO
+!
+            IF ( lpyc(ji,jj) ) THEN
+! pycnocline
+              DO jk = imld(ji,jj), ibld(ji,jj)
+                zznd_pyc = - ( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) / zdh(ji,jj)
+                ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 4.0 * zsc_wth_pyc(ji,jj) * ( 0.48 - EXP( -1.5 * ( zznd_pyc -0.3)**2 ) ) 
+                ghams(ji,jj,jk) = ghams(ji,jj,jk) + 4.0 * zsc_ws_pyc(ji,jj) * ( 0.48 - EXP( -1.5 * ( zznd_pyc -0.3)**2 ) ) 
+              END DO
+           ENDIF
          ELSE
-            DO jk = 2, ibld(ji,jj)
-               zznd_d = gdepw(ji,jj,jk,Kmm) / dstokes(ji,jj)
-               znd = gdepw(ji,jj,jk,Kmm) / zhbl(ji,jj)
-               ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 0.3 * ( -4.06 * EXP( -2.0 * zznd_d ) * (1.0 - EXP( -4.0 * zznd_d ) ) + &
-            &  7.5 * EXP ( -10.0 * ( 0.95 - znd )**2 ) * ( 1.0 - znd ) ) * zsc_wth_1(ji,jj)
-               ghams(ji,jj,jk) = ghams(ji,jj,jk) + 0.3 * ( -4.06 * EXP( -2.0 * zznd_d ) * (1.0 - EXP( -4.0 * zznd_d ) ) + &
-            &  7.5 * EXP ( -10.0 * ( 0.95 - znd )**2 ) * ( 1.0 - znd ) ) * zsc_ws_1(ji,jj)
-            END DO
+            IF( zdhdt(ji,jj) > 0. ) THEN
+              DO jk = 2, ibld(ji,jj)
+                 zznd_d = gdepw(ji,jj,jk,Kmm) / dstokes(ji,jj)
+                 znd = gdepw(ji,jj,jk,Kmm) / zhbl(ji,jj)
+                 ghamt(ji,jj,jk) = ghamt(ji,jj,jk) + 0.3 * ( -4.06 * EXP( -2.0 * zznd_d ) * (1.0 - EXP( -4.0 * zznd_d ) ) + &
+              &  7.5 * EXP ( -10.0 * ( 0.95 - znd )**2 ) * ( 1.0 - znd ) ) * zsc_wth_1(ji,jj)
+                 ghams(ji,jj,jk) = ghams(ji,jj,jk) + 0.3 * ( -4.06 * EXP( -2.0 * zznd_d ) * (1.0 - EXP( -4.0 * zznd_d ) ) + &
+               &  7.5 * EXP ( -10.0 * ( 0.95 - znd )**2 ) * ( 1.0 - znd ) ) * zsc_ws_1(ji,jj)
+              END DO
+            ENDIF
          ENDIF
        END_2D
-
 
        WHERE ( lconv )
@@ -1090,22 +986,23 @@
           ENDIF
        END_2D
+
+       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.
 
+
+ ! Make surface forced velocity non-gradient terms go to zero at the base of the boundary layer.
+
       DO_2D( 0, 0, 0, 0 )
-         IF ( lconv(ji,jj) ) THEN
+         IF ( .not. lconv(ji,jj) ) THEN
             DO jk = 2, ibld(ji,jj)
-               znd = ( gdepw(ji,jj,jk,Kmm) - zhml(ji,jj) ) / zhml(ji,jj) !ALMG to think about
-               IF ( znd >= 0.0 ) THEN
-                  ghamu(ji,jj,jk) = ghamu(ji,jj,jk) * ( 1.0 - EXP( -30.0 * znd**2 ) )
-                  ghamv(ji,jj,jk) = ghamv(ji,jj,jk) * ( 1.0 - EXP( -30.0 * znd**2 ) )
-               ELSE
-                  ghamu(ji,jj,jk) = 0._wp
-                  ghamv(ji,jj,jk) = 0._wp
-               ENDIF
-            END DO
-         ELSE
-            DO jk = 2, ibld(ji,jj)
-               znd = ( gdepw(ji,jj,jk,Kmm) - zhml(ji,jj) ) / zhml(ji,jj) !ALMG to think about
+               znd = ( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) / zhbl(ji,jj) !ALMG to think about
                IF ( znd >= 0.0 ) THEN
                   ghamu(ji,jj,jk) = ghamu(ji,jj,jk) * ( 1.0 - EXP( -10.0 * znd**2 ) )
@@ -1120,43 +1017,36 @@
 
       ! pynocline contributions
-       ! Temporary fix to avoid instabilities when zdb_bl becomes very very small
-       zsc_uw_1 = 0._wp ! 50.0 * zla**(8.0/3.0) * zustar**2 * zhbl / ( zdb_bl + epsln )
        DO_2D( 0, 0, 0, 0 )
-          DO jk= 2, ibld(ji,jj)
-             znd = gdepw(ji,jj,jk,Kmm) / 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
+         IF ( .not. lconv(ji,jj) ) THEN
+          IF ( ibld(ji,jj) + jp_ext(ji,jj) < mbkt(ji,jj) ) THEN
+             DO jk= 2, ibld(ji,jj)
+                znd = gdepw(ji,jj,jk,Kmm) / 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)
+                ghamv(ji,jj,jk) = ghamv(ji,jj,jk) + zviscos(ji,jj,jk) * zdvdz_pyc(ji,jj,jk)
+             END DO
+          END IF
+         END IF
        END_2D
-
-! Entrainment contribution.
+      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
 
        DO_2D( 0, 0, 0, 0 )
-          IF ( lconv(ji,jj) ) THEN
-            DO jk = 1, imld(ji,jj) - 1
-               znd=gdepw(ji,jj,jk,Kmm) / 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
-               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
-            END DO
-            DO jk = imld(ji,jj), ibld(ji,jj)
-               znd = -( gdepw(ji,jj,jk,Kmm) - 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 )
-               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_2D
 
-
+       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("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
@@ -1180,4 +1070,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
 
@@ -1222,6 +1114,45 @@
        END IF ! ln_convmix = .true.
 
+
+
+       IF ( ln_osm_mle ) THEN  ! set up diffusivity and non-gradient mixing
+          DO_2D( 0, 0, 0, 0 )
+              IF ( lflux(ji,jj) ) THEN ! MLE mixing extends below boundary layer
+             ! Calculate MLE flux contribution from surface fluxes
+                DO jk = 1, ibld(ji,jj)
+                  znd = gdepw(ji,jj,jk,Kmm) / 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(ji,jj,jk,Kmm) / 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 = 1, mld_prof(ji,jj)
+                   znd = -gdepw(ji,jj,jk,Kmm) / MAX(zhmle(ji,jj),epsln)
+                   zdiffut(ji,jj,jk) = zdiffut(ji,jj,jk) + zdiff_mle(ji,jj) * ( 1.0 - ( 2.0 * znd + 1.0 )**2 ) * ( 1.0 + 5.0 / 21.0 * ( 2.0 * znd + 1.0 )** 2 )
+                 END DO
+              ELSE
+! Surface transports limited to OSBL.                 
+         ! Viscosity for MLEs
+                 DO jk = 1, mld_prof(ji,jj)
+                   znd = -gdepw(ji,jj,jk,Kmm) / MAX(zhmle(ji,jj),epsln)
+                   zdiffut(ji,jj,jk) = zdiffut(ji,jj,jk) + zdiff_mle(ji,jj) * ( 1.0 - ( 2.0 * znd + 1.0 )**2 ) * ( 1.0 + 5.0 / 21.0 * ( 2.0 * znd + 1.0 )** 2 )
+                 END DO
+              ENDIF
+          END_2D
+       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.0_wp )
+       !CALL lbc_lnk( 'zdfosm', zviscos(:,:,:), 'W', 1.0_wp )
 
        ! GN 25/8: need to change tmask --> wmask
@@ -1244,10 +1175,12 @@
             ghams(ji,jj,jk) =  ghams(ji,jj,jk) * tmask(ji,jj,jk)
        END_3D
+        ! 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.0_wp , ghams, 'W', 1.0_wp,   &
-         &                  ghamu, 'U', 1.0_wp , ghamv, 'V', 1.0_wp )
-
-       IF(ln_dia_osm) THEN
+        ! Lateral boundary conditions on final outputs for gham[uv],  on [UV]-grid  (sign changed)
+        CALL lbc_lnk_multi( 'zdfosm', ghamt, 'W',  1.0_wp , ghams, 'W',  1.0_wp,   &
+         &                            ghamu, 'U', -1.0_wp , ghamv, 'V', -1.0_wp )
+
+      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).
@@ -1257,7 +1190,12 @@
             IF ( iom_use("wind_wave_abs_power") ) CALL iom_put( "wind_wave_abs_power", 1000.*rho0*tmask(:,:,1)*zustar**2*zustke )
          ! 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
+         CASE(2:3)
+            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.*rho0*tmask(:,:,1)*zustar**2* &
                  & SQRT(ut0sd**2 + vt0sd**2 ) )
@@ -1270,5 +1208,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
@@ -1276,21 +1221,1228 @@
          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.*rho0*tmask(:,:,1)*zustar**3 ) ! BL depth internal to zdf_osm routine
          IF ( iom_use("wind_wave_power") ) CALL iom_put( "wind_wave_power", 1000.*rho0*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.0_wp )
+
+CONTAINS
+! subroutine code changed, needs syntax checking.
+  SUBROUTINE zdf_osm_diffusivity_viscosity( zdiffut, zviscos )
+
+!!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_osm_diffusivity_viscosity  ***
+     !!
+     !! ** Purpose : Determines the eddy diffusivity and eddy viscosity profiles in the mixed layer and the pycnocline.
+     !!
+     !! ** Method  : 
+     !!
+     !! !!----------------------------------------------------------------------
+     REAL(wp), DIMENSION(:,:,:) :: zdiffut
+     REAL(wp), DIMENSION(:,:,:) :: zviscos
+! local
+
+! Scales used to calculate eddy diffusivity and viscosity profiles
+      REAL(wp), DIMENSION(jpi,jpj) :: zdifml_sc, zvisml_sc
+      REAL(wp), DIMENSION(jpi,jpj) :: zdifpyc_n_sc, zdifpyc_s_sc, zdifpyc_shr
+      REAL(wp), DIMENSION(jpi,jpj) :: zvispyc_n_sc, zvispyc_s_sc,zvispyc_shr
+      REAL(wp), DIMENSION(jpi,jpj) :: zbeta_d_sc, zbeta_v_sc
+!
+      REAL(wp) :: zvel_sc_pyc, zvel_sc_ml, zstab_fac
+      
+      REAL(wp), PARAMETER :: rn_dif_ml = 0.8, rn_vis_ml = 0.375
+      REAL(wp), PARAMETER :: rn_dif_pyc = 0.15, rn_vis_pyc = 0.142
+      REAL(wp), PARAMETER :: rn_vispyc_shr = 0.15
+      
+      DO_2D( 0, 0, 0, 0 )
+          IF ( lconv(ji,jj) ) THEN
+          
+            zvel_sc_pyc = ( 0.15 * zvstr(ji,jj)**3 + zwstrc(ji,jj)**3 + 4.25 * zshear(ji,jj) * zhbl(ji,jj) )**pthird
+            zvel_sc_ml = ( zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird
+            zstab_fac = ( zhml(ji,jj) / zvel_sc_ml * ( 1.4 - 0.4 / ( 1.0 + EXP(-3.5 * LOG10(-zhol(ji,jj) ) ) )**1.25 ) )**2
+
+            zdifml_sc(ji,jj) = rn_dif_ml * zhml(ji,jj) * zvel_sc_ml
+            zvisml_sc(ji,jj) = rn_vis_ml * zdifml_sc(ji,jj)
+
+            IF ( lpyc(ji,jj) ) THEN
+              zdifpyc_n_sc(ji,jj) =  rn_dif_pyc * zvel_sc_ml * zdh(ji,jj)
+
+              IF ( lshear(ji,jj) .and. j_ddh(ji,jj) == 1 ) THEN
+                zdifpyc_n_sc(ji,jj) = zdifpyc_n_sc(ji,jj) + rn_vispyc_shr * ( zshear(ji,jj) * zhbl(ji,jj) )**pthird * zhbl(ji,jj)
+              ENDIF
+            
+              zdifpyc_s_sc(ji,jj) = zwb_ent(ji,jj) + 0.0025 * zvel_sc_pyc * ( zhbl(ji,jj) / zdh(ji,jj) - 1.0 ) * ( zb_ml(ji,jj) - zb_bl(ji,jj) )
+              zdifpyc_s_sc(ji,jj) = 0.09 * zdifpyc_s_sc(ji,jj) * zstab_fac
+              zdifpyc_s_sc(ji,jj) = MAX( zdifpyc_s_sc(ji,jj), -0.5 * zdifpyc_n_sc(ji,jj) )
+              
+              zvispyc_n_sc(ji,jj) = 0.09 * zvel_sc_pyc * ( 1.0 - zhbl(ji,jj) / zdh(ji,jj) )**2 * ( 0.005 * ( zu_ml(ji,jj)-zu_bl(ji,jj) )**2 + 0.0075 * ( zv_ml(ji,jj)-zv_bl(ji,jj) )**2 ) / zdh(ji,jj)
+              zvispyc_n_sc(ji,jj) = rn_vis_pyc * zvel_sc_ml * zdh(ji,jj) + zvispyc_n_sc(ji,jj) * zstab_fac
+              IF ( lshear(ji,jj) .and. j_ddh(ji,jj) == 1 ) THEN
+                zvispyc_n_sc(ji,jj) = zvispyc_n_sc(ji,jj) + rn_vispyc_shr * ( zshear(ji,jj) * zhbl(ji,jj ) )**pthird * zhbl(ji,jj)
+              ENDIF
+             
+              zvispyc_s_sc(ji,jj) = 0.09 * ( zwb_min(ji,jj) + 0.0025 * zvel_sc_pyc * ( zhbl(ji,jj) / zdh(ji,jj) - 1.0 ) * ( zb_ml(ji,jj) - zb_bl(ji,jj) ) )
+              zvispyc_s_sc(ji,jj) = zvispyc_s_sc(ji,jj) * zstab_fac
+              zvispyc_s_sc(ji,jj) = MAX( zvispyc_s_sc(ji,jj), -0.5 * zvispyc_s_sc(ji,jj) )
+
+              zbeta_d_sc(ji,jj) = 1.0 - ( ( zdifpyc_n_sc(ji,jj) + 1.4 * zdifpyc_s_sc(ji,jj) ) / ( zdifml_sc(ji,jj) + epsln ) )**p2third
+              zbeta_v_sc(ji,jj) = 1.0 -  2.0 * ( zvispyc_n_sc(ji,jj) + zvispyc_s_sc(ji,jj) ) / ( zvisml_sc(ji,jj) + epsln )
+            ELSE
+              zbeta_d_sc(ji,jj) = 1.0
+              zbeta_v_sc(ji,jj) = 1.0
+            ENDIF
+          ELSE
+            zdifml_sc(ji,jj) = zvstr(ji,jj) * zhbl(ji,jj) * MAX( EXP ( -( zhol(ji,jj) / 0.6_wp )**2 ), 0.2_wp)
+            zvisml_sc(ji,jj) = zvstr(ji,jj) * zhbl(ji,jj) * MAX( EXP ( -( zhol(ji,jj) / 0.6_wp )**2 ), 0.2_wp)
+          END IF
+      END_2D
+!
+       DO_2D( 0, 0, 0, 0 )
+          IF ( lconv(ji,jj) ) THEN
+             DO jk = 2, imld(ji,jj)   ! mixed layer diffusivity
+                 zznd_ml = gdepw(ji,jj,jk,Kmm) / zhml(ji,jj)
+                 !
+                 zdiffut(ji,jj,jk) = zdifml_sc(ji,jj) * zznd_ml * ( 1.0 - zbeta_d_sc(ji,jj) * zznd_ml )**1.5
+                 !
+                 zviscos(ji,jj,jk) = zvisml_sc(ji,jj) * zznd_ml * ( 1.0 - zbeta_v_sc(ji,jj) * zznd_ml ) &
+   &            *                                      ( 1.0 - 0.5 * zznd_ml**2 )
+             END DO
+! pycnocline
+             IF ( lpyc(ji,jj) ) THEN
+! Diffusivity profile in the pycnocline given by cubic polynomial.
+                za_cubic = 0.5
+                zb_cubic = -1.75 * zdifpyc_s_sc(ji,jj) / zdifpyc_n_sc(ji,jj)
+                zd_cubic = ( zdh(ji,jj) * zdifml_sc(ji,jj) / zhml(ji,jj) * SQRT( 1.0 - zbeta_d_sc(ji,jj) ) * ( 2.5 * zbeta_d_sc(ji,jj) - 1.0 ) &
+                     & - 0.85 * zdifpyc_s_sc(ji,jj) ) / MAX(zdifpyc_n_sc(ji,jj), 1.e-8)
+                zd_cubic = zd_cubic - zb_cubic - 2.0 * ( 1.0 - za_cubic  - zb_cubic )
+                zc_cubic = 1.0 - za_cubic - zb_cubic - zd_cubic
+                DO jk = imld(ji,jj) , ibld(ji,jj)
+                  zznd_pyc = -( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) / MAX(zdh(ji,jj), 1.e-6)
+                      !
+                  zdiffut(ji,jj,jk) = zdifpyc_n_sc(ji,jj) * ( za_cubic + zb_cubic * zznd_pyc + zc_cubic * zznd_pyc**2 +   zd_cubic * zznd_pyc**3 )
+
+                  zdiffut(ji,jj,jk) = zdiffut(ji,jj,jk) + zdifpyc_s_sc(ji,jj) * ( 1.75 * zznd_pyc - 0.15 * zznd_pyc**2 - 0.2 * zznd_pyc**3 )
+                END DO
+ ! viscosity profiles.
+                za_cubic = 0.5
+                zb_cubic = -1.75 * zvispyc_s_sc(ji,jj) / zvispyc_n_sc(ji,jj)
+                zd_cubic = ( 0.5 * zvisml_sc(ji,jj) * zdh(ji,jj) / zhml(ji,jj) - 0.85 * zvispyc_s_sc(ji,jj)  )  / MAX(zvispyc_n_sc(ji,jj), 1.e-8)
+                zd_cubic = zd_cubic - zb_cubic - 2.0 * ( 1.0 - za_cubic - zd_cubic )
+                zc_cubic = 1.0 - za_cubic - zb_cubic - zd_cubic
+                DO jk = imld(ji,jj) , ibld(ji,jj)
+                   zznd_pyc = -( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) / MAX(zdh(ji,jj), 1.e-6)
+                    zviscos(ji,jj,jk) = zvispyc_n_sc(ji,jj) * ( za_cubic + zb_cubic * zznd_pyc + zc_cubic * zznd_pyc**2 + zd_cubic * zznd_pyc**3 )
+                    zviscos(ji,jj,jk) = zviscos(ji,jj,jk) + zvispyc_s_sc(ji,jj) * ( 1.75 * zznd_pyc - 0.15 * zznd_pyc**2 -0.2 * zznd_pyc**3 )
+                END DO
+                IF ( zdhdt(ji,jj) > 0._wp ) THEN
+                 zdiffut(ji,jj,ibld(ji,jj)+1) = MAX( 0.5 * zdhdt(ji,jj) * e3w(ji,jj,ibld(ji,jj)+1,Kmm), 1.0e-6 )
+                 zviscos(ji,jj,ibld(ji,jj)+1) = MAX( 0.5 * zdhdt(ji,jj) * e3w(ji,jj,ibld(ji,jj)+1,Kmm), 1.0e-6 )
+                ELSE
+                  zdiffut(ji,jj,ibld(ji,jj)) = 0._wp
+                  zviscos(ji,jj,ibld(ji,jj)) = 0._wp
+                ENDIF
+             ENDIF
+          ELSE
+          ! stable conditions
+             DO jk = 2, ibld(ji,jj)
+                zznd_ml = gdepw(ji,jj,jk,Kmm) / zhbl(ji,jj)
+                zdiffut(ji,jj,jk) = 0.75 * zdifml_sc(ji,jj) * zznd_ml * ( 1.0 - zznd_ml )**1.5
+                zviscos(ji,jj,jk) = 0.375 * zvisml_sc(ji,jj) * zznd_ml * (1.0 - zznd_ml) * ( 1.0 - zznd_ml**2 )
+             END DO
+
+             IF ( zdhdt(ji,jj) > 0._wp ) THEN
+                zdiffut(ji,jj,ibld(ji,jj)) = MAX(zdhdt(ji,jj), 1.0e-6) * e3w(ji, jj, ibld(ji,jj), Kmm)
+                zviscos(ji,jj,ibld(ji,jj)) = MAX(zdhdt(ji,jj), 1.0e-6) * e3w(ji, jj, ibld(ji,jj), Kmm)
+             ENDIF
+          ENDIF   ! end if ( lconv )
+          !
+       END_2D
+       
+  END SUBROUTINE zdf_osm_diffusivity_viscosity
+  
+  SUBROUTINE zdf_osm_osbl_state( lconv, lshear, j_ddh, zwb_ent, zwb_min, zshear, zri_i )
+
+!!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_osm_osbl_state  ***
+     !!
+     !! ** Purpose : Determines the state of the OSBL, stable/unstable, shear/ noshear. Also determines shear production, entrainment buoyancy flux and interfacial Richardson number
+     !!
+     !! ** Method  : 
+     !!
+     !! !!----------------------------------------------------------------------
+
+     INTEGER, DIMENSION(jpi,jpj) :: j_ddh  ! j_ddh = 0, active shear layer; j_ddh=1, shear layer not active; j_ddh=2 shear production low.
+     
+     LOGICAL, DIMENSION(jpi,jpj) :: lconv, lshear
+
+     REAL(wp), DIMENSION(jpi,jpj) :: zwb_ent, zwb_min ! Buoyancy fluxes at base of well-mixed layer.
+     REAL(wp), DIMENSION(jpi,jpj) :: zshear  ! production of TKE due to shear across the pycnocline
+     REAL(wp), DIMENSION(jpi,jpj) :: zri_i  ! Interfacial Richardson Number
+
+! Local Variables
+
+     INTEGER :: jj, ji
+     
+     REAL(wp), DIMENSION(jpi,jpj) :: zekman
+     REAL(wp) :: zri_p, zri_b   ! Richardson numbers
+     REAL(wp) :: zshear_u, zshear_v, zwb_shr
+     REAL(wp) :: zwcor, zrf_conv, zrf_shear, zrf_langmuir, zr_stokes
+
+     REAL, PARAMETER :: za_shr = 0.4, zb_shr = 6.5, za_wb_s = 0.1
+     REAL, PARAMETER :: rn_ri_thres_a = 0.5, rn_ri_thresh_b = 0.59
+     REAL, PARAMETER :: zalpha_c = 0.2, zalpha_lc = 0.04     
+     REAL, PARAMETER :: zalpha_ls = 0.06, zalpha_s = 0.15
+     REAL, PARAMETER :: rn_ri_p_thresh = 27.0
+     REAL, PARAMETER :: zrot=0._wp  ! dummy rotation rate of surface stress.
+     
+! Determins stability and set flag lconv
+     DO_2D( 0, 0, 0, 0 )
+      IF ( zhol(ji,jj) < 0._wp ) THEN
+         lconv(ji,jj) = .TRUE.
+       ELSE
+          lconv(ji,jj) = .FALSE.
+       ENDIF
+     END_2D
+ 
+     zekman(:,:) = EXP( - 4.0 * ABS( ff_t(:,:) ) * zhbl(:,:) / MAX(zustar(:,:), 1.e-8 ) )
+     
+     WHERE ( lconv )
+       zri_i = zdb_ml * zhml**2 / MAX( ( zvstr**3 + 0.5 * zwstrc**3 )**p2third * zdh, 1.e-12 )
+     END WHERE
+
+     zshear(:,:) = 0._wp
+     j_ddh(:,:) = 1     
+ 
+     DO_2D( 0, 0, 0, 0 )
+      IF ( lconv(ji,jj) ) THEN
+         IF ( zdb_bl(ji,jj) > 0._wp ) THEN
+           zri_p = MAX (  SQRT( zdb_bl(ji,jj) * zdh(ji,jj) / MAX( zdu_bl(ji,jj)**2 + zdv_bl(ji,jj)**2, 1.e-8) )  *  ( zhbl(ji,jj) / zdh(ji,jj) ) * ( zvstr(ji,jj) / MAX( zustar(ji,jj), 1.e-6 ) )**2 &
+                & / MAX( zekman(ji,jj), 1.e-6 )  , 5._wp )
+         
+           zri_b = zdb_ml(ji,jj) * zdh(ji,jj) / MAX( zdu_ml(ji,jj)**2 + zdv_ml(ji,jj)**2, 1.e-8 )
+                     
+           zshear(ji,jj) = za_shr * zekman(ji,jj) * ( MAX( zustar(ji,jj)**2 * zdu_ml(ji,jj) / zhbl(ji,jj), 0._wp ) + zb_shr * MAX( -ff_t(ji,jj) * zustke(ji,jj) * dstokes(ji,jj) * zdv_ml(ji,jj) / zhbl(ji,jj), 0._wp ) )
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Test ensures j_ddh=0 is not selected. Change to zri_p<27 when  !
+! full code available                                          !
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+           IF ( zri_p < -rn_ri_p_thresh .and. zshear(ji,jj) > 0._wp ) THEN
+! Growing shear layer
+             j_ddh(ji,jj) = 0
+             lshear(ji,jj) = .TRUE.
+           ELSE
+             j_ddh(ji,jj) = 1
+             IF ( zri_b <= 1.5 .and. zshear(ji,jj) > 0._wp ) THEN
+! shear production large enough to determine layer charcteristics, but can't maintain a shear layer.
+               lshear(ji,jj) = .TRUE.
+             ELSE
+! Shear production may not be zero, but is small and doesn't determine characteristics of pycnocline.
+               zshear(ji,jj) = 0.5 * zshear(ji,jj)
+               lshear(ji,jj) = .FALSE.
+             ENDIF 
+           ENDIF                
+         ELSE                ! zdb_bl test, note zshear set to zero
+           j_ddh(ji,jj) = 2
+           lshear(ji,jj) = .FALSE.
+         ENDIF
+       ENDIF
+     END_2D
+ 
+! Calculate entrainment buoyancy flux due to surface fluxes.
+
+     DO_2D( 0, 0, 0, 0 )
+      IF ( lconv(ji,jj) ) THEN
+        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 )
+        IF (nn_osm_SD_reduce > 0 ) THEN
+        ! Effective Stokes drift already reduced from surface value
+           zr_stokes = 1.0_wp
+        ELSE
+         ! Effective Stokes drift only reduced by factor rn_zdfodm_adjust_sd,
+          ! requires further reduction where BL is deep
+           zr_stokes = 1.0 - EXP( -25.0 * dstokes(ji,jj) / hbl(ji,jj) &
+         &                  * ( 1.0 + 4.0 * dstokes(ji,jj) / hbl(ji,jj) ) )
+        END IF
+        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)
+          !
+      ENDIF
+     END_2D
+
+     zwb_min(:,:) = 0._wp
+
+     DO_2D( 0, 0, 0, 0 )
+      IF ( lshear(ji,jj) ) THEN
+        IF ( lconv(ji,jj) ) THEN
+! Unstable OSBL
+           zwb_shr = -za_wb_s * zshear(ji,jj)
+           IF ( j_ddh(ji,jj) == 0 ) THEN
+
+! Developing shear layer, additional shear production possible.
+
+             zshear_u = MAX( zustar(ji,jj)**2 * zdu_ml(ji,jj) /  zhbl(ji,jj), 0._wp )
+             zshear(ji,jj) = zshear(ji,jj) + zshear_u * ( 1.0 - MIN( zri_p / rn_ri_p_thresh, 1.d0 ) )
+             zshear(ji,jj) = MIN( zshear(ji,jj), zshear_u )
+             
+             zwb_shr = -za_wb_s * zshear(ji,jj)
+             
+           ENDIF                
+           zwb_ent(ji,jj) = zwb_ent(ji,jj) + zwb_shr
+           zwb_min(ji,jj) = zwb_ent(ji,jj) + zdh(ji,jj) / zhbl(ji,jj) * zwb0(ji,jj)
+        ELSE    ! IF ( lconv ) THEN - ENDIF
+! Stable OSBL  - shear production not coded for first attempt.           
+        ENDIF  ! lconv
+      ELSE  ! lshear
+        IF ( lconv(ji,jj) ) THEN
+! Unstable OSBL
+           zwb_shr = -za_wb_s * zshear(ji,jj)
+           zwb_ent(ji,jj) = zwb_ent(ji,jj) + zwb_shr
+           zwb_min(ji,jj) = zwb_ent(ji,jj) + zdh(ji,jj) / zhbl(ji,jj) * zwb0(ji,jj)
+        ENDIF  ! lconv
+      ENDIF    ! lshear
+     END_2D
+   END SUBROUTINE zdf_osm_osbl_state
+     
+     
+   SUBROUTINE zdf_osm_vertical_average( jnlev_av, jp_ext, zt, zs, zb, 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.
+        INTEGER, DIMENSION(jpi,jpj) :: jp_ext
+
+        ! Alan: do we need zb?
+        REAL(wp), DIMENSION(jpi,jpj) :: zt, zs, zb        ! 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, ibld_ext
+        REAL(wp) :: zthick, zthermal, zbeta
+
+
+        zt   = 0._wp
+        zs   = 0._wp
+        zu   = 0._wp
+        zv   = 0._wp
+        DO_2D( 0, 0, 0, 0 )
+         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(ji,jj,jk,Kmm)
+            zt(ji,jj)   = zt(ji,jj)  + e3t(ji,jj,jk,Kmm) * ts(ji,jj,jk,jp_tem,Kmm)
+            zs(ji,jj)   = zs(ji,jj)  + e3t(ji,jj,jk,Kmm) * ts(ji,jj,jk,jp_sal,Kmm)
+            zu(ji,jj)   = zu(ji,jj)  + e3t(ji,jj,jk,Kmm) &
+                  &            * ( uu(ji,jj,jk,Kbb) + uu(ji - 1,jj,jk,Kbb) ) &
+                  &            / MAX( 1. , umask(ji,jj,jk) + umask(ji - 1,jj,jk) )
+            zv(ji,jj)   = zv(ji,jj)  + e3t(ji,jj,jk,Kmm) &
+                  &            * ( vv(ji,jj,jk,Kbb) + vv(ji,jj - 1,jk,Kbb) ) &
+                  &            / 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
+         zb(ji,jj) = grav * zthermal * zt(ji,jj) - grav * zbeta * zs(ji,jj)
+         ibld_ext = jnlev_av(ji,jj) + jp_ext(ji,jj)
+         IF ( ibld_ext < mbkt(ji,jj) ) THEN
+           zdt(ji,jj) = zt(ji,jj) - ts(ji,jj,ibld_ext,jp_tem,Kmm)
+           zds(ji,jj) = zs(ji,jj) - ts(ji,jj,ibld_ext,jp_sal,Kmm)
+           zdu(ji,jj) = zu(ji,jj) - ( uu(ji,jj,ibld_ext,Kbb) + uu(ji-1,jj,ibld_ext,Kbb ) ) &
+                  &    / MAX(1. , umask(ji,jj,ibld_ext ) + umask(ji-1,jj,ibld_ext ) )
+           zdv(ji,jj) = zv(ji,jj) - ( vv(ji,jj,ibld_ext,Kbb) + vv(ji,jj-1,ibld_ext,Kbb ) ) &
+                  &   / MAX(1. , vmask(ji,jj,ibld_ext ) + vmask(ji,jj-1,ibld_ext ) )
+           zdb(ji,jj) = grav * zthermal * zdt(ji,jj) - grav * zbeta * zds(ji,jj)
+         ELSE
+           zdt(ji,jj) = 0._wp
+           zds(ji,jj) = 0._wp
+           zdu(ji,jj) = 0._wp
+           zdv(ji,jj) = 0._wp
+           zdb(ji,jj) = 0._wp
+         ENDIF
+        END_2D
+   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_2D( 0, 0, 0, 0 )
+           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_2D
+    END SUBROUTINE zdf_osm_velocity_rotation
+
+    SUBROUTINE zdf_osm_osbl_state_fk( lpyc, lflux, lmle, zwb_fk )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_osm_osbl_state_fk  ***
+     !!
+     !! ** Purpose : Determines the state of the OSBL and MLE layer. Info is returned in the logicals lpyc,lflux and lmle. Used with Fox-Kemper scheme.
+     !!  lpyc :: determines whether pycnocline flux-grad relationship needs to be determined
+     !!  lflux :: determines whether effects of surface flux extend below the base of the OSBL
+     !!  lmle  :: determines whether the layer with MLE is increasing with time or if base is relaxing towards hbl. 
+     !!
+     !! ** Method  : 
+     !!
+     !! 
+     !!----------------------------------------------------------------------
+      
+! Outputs
+      LOGICAL,  DIMENSION(jpi,jpj)  :: lpyc, lflux, lmle
+      REAL(wp), DIMENSION(jpi,jpj)  :: zwb_fk
+!
+      REAL(wp), DIMENSION(jpi,jpj)  :: znd_param
+      REAL(wp)                      :: zbuoy, ztmp, zpe_mle_layer
+      REAL(wp)                      :: zpe_mle_ref, zwb_ent, zdbdz_mle_int
+      
+      znd_param(:,:) = 0._wp
+
+        DO_2D( 0, 0, 0, 0 )
+          ztmp =  r1_ft(ji,jj) *  MIN( 111.e3_wp , e1u(ji,jj) ) / rn_osm_mle_lf
+          zwb_fk(ji,jj) = rn_osm_mle_ce * hmle(ji,jj) * hmle(ji,jj) * ztmp * zdbds_mle(ji,jj) * zdbds_mle(ji,jj)
+        END_2D
+        DO_2D( 0, 0, 0, 0 )
+                 !
+         IF ( lconv(ji,jj) ) THEN
+           IF ( zhmle(ji,jj) > 1.2 * zhbl(ji,jj) ) THEN
+             zt_mle(ji,jj) = ( zt_mle(ji,jj) * zhmle(ji,jj) - zt_bl(ji,jj) * zhbl(ji,jj) ) / ( zhmle(ji,jj) - zhbl(ji,jj) )
+             zs_mle(ji,jj) = ( zs_mle(ji,jj) * zhmle(ji,jj) - zs_bl(ji,jj) * zhbl(ji,jj) ) / ( zhmle(ji,jj) - zhbl(ji,jj) )
+             zb_mle(ji,jj) = ( zb_mle(ji,jj) * zhmle(ji,jj) - zb_bl(ji,jj) * zhbl(ji,jj) ) / ( zhmle(ji,jj) - zhbl(ji,jj) )
+             zdbdz_mle_int = ( zb_bl(ji,jj) - ( 2.0 * zb_mle(ji,jj) -zb_bl(ji,jj) ) ) / ( zhmle(ji,jj) - zhbl(ji,jj) )
+! Calculate potential energies of actual profile and reference profile.
+             zpe_mle_layer = 0._wp
+             zpe_mle_ref = 0._wp
+             DO jk = ibld(ji,jj), mld_prof(ji,jj)
+               zbuoy = grav * ( zthermal * ts(ji,jj,jk,jp_tem,Kmm) - zbeta * ts(ji,jj,jk,jp_sal,Kmm) )
+               zpe_mle_layer = zpe_mle_layer + zbuoy * gdepw(ji,jj,jk,Kmm) * e3w(ji,jj,jk,Kmm)
+               zpe_mle_ref = zpe_mle_ref + ( zb_bl(ji,jj) - zdbdz_mle_int * ( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) ) * gdepw(ji,jj,jk,Kmm) * e3w(ji,jj,jk,Kmm)
+             END DO
+! Non-dimensional parameter to diagnose the presence of thermocline
+                
+             znd_param(ji,jj) = ( zpe_mle_layer - zpe_mle_ref ) * ABS( ff_t(ji,jj) ) / ( MAX( zwb_fk(ji,jj), 1.0e-10 ) * zhmle(ji,jj) )
+           ENDIF
+         ENDIF
+        END_2D
+
+! Diagnosis
+        DO_2D( 0, 0, 0, 0 )
+          IF ( lconv(ji,jj) ) THEN
+            zwb_ent = - 2.0 * 0.2 * zwbav(ji,jj) &
+               &                  - 0.15 * zustar(ji,jj)**3 /zhml(ji,jj) &
+               &         + ( 0.15 * EXP( -1.5 * zla(ji,jj) ) * zustar(ji,jj)**3 &
+               &         - 0.03 * zwstrl(ji,jj)**3 ) / zhml(ji,jj)
+            IF ( -2.0 * zwb_fk(ji,jj) / zwb_ent > 0.5 ) THEN
+              IF ( zhmle(ji,jj) > 1.2 * zhbl(ji,jj) ) THEN
+! MLE layer growing
+                IF ( znd_param (ji,jj) > 100. ) THEN
+! Thermocline present
+                  lflux(ji,jj) = .FALSE.
+                  lmle(ji,jj) =.FALSE.
+                ELSE
+! Thermocline not present
+                  lflux(ji,jj) = .TRUE.
+                  lmle(ji,jj) = .TRUE.
+                ENDIF  ! znd_param > 100
+!
+                IF ( zdb_bl(ji,jj) < rn_osm_bl_thresh ) THEN
+                  lpyc(ji,jj) = .FALSE.
+                ELSE
+                   lpyc = .TRUE.
+                ENDIF
+              ELSE
+! MLE layer restricted to OSBL or just below.
+                IF ( zdb_bl(ji,jj) < rn_osm_bl_thresh ) THEN
+! Weak stratification MLE layer can grow.
+                  lpyc(ji,jj) = .FALSE.
+                  lflux(ji,jj) = .TRUE.
+                  lmle(ji,jj) = .TRUE.
+                ELSE
+! Strong stratification
+                  lpyc(ji,jj) = .TRUE.
+                  lflux(ji,jj) = .FALSE.
+                  lmle(ji,jj) = .FALSE.
+                ENDIF ! zdb_bl < rn_mle_thresh_bl and 
+              ENDIF  ! zhmle > 1.2 zhbl
+            ELSE
+              lpyc(ji,jj) = .TRUE.
+              lflux(ji,jj) = .FALSE.
+              lmle(ji,jj) = .FALSE.
+              IF ( zdb_bl(ji,jj) < rn_osm_bl_thresh ) lpyc(ji,jj) = .FALSE.
+            ENDIF !  -2.0 * zwb_fk(ji,jj) / zwb_ent > 0.5 
+          ELSE
+! Stable Boundary Layer
+            lpyc(ji,jj) = .FALSE.
+            lflux(ji,jj) = .FALSE.
+            lmle(ji,jj) = .FALSE.
+          ENDIF  ! lconv
+        END_2D
+    END SUBROUTINE zdf_osm_osbl_state_fk
+
+    SUBROUTINE zdf_osm_external_gradients(jbase, 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.
+     !!
+     !!----------------------------------------------------------------------
+
+     INTEGER, DIMENSION(jpi,jpj)  :: jbase
+     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_2D( 0, 0, 0, 0 )
+        IF ( jbase(ji,jj)+1 < 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 = jbase(ji,jj)
+           jkb1 = MIN(jkb + 1, mbkt(ji,jj))
+           zdtdz(ji,jj) = - ( ts(ji,jj,jkb1,jp_tem,Kmm) - ts(ji,jj,jkb,jp_tem,Kmm ) ) &
+                &   / e3t(ji,jj,ibld(ji,jj),Kmm)
+           zdsdz(ji,jj) = - ( ts(ji,jj,jkb1,jp_sal,Kmm) - ts(ji,jj,jkb,jp_sal,Kmm ) ) &
+                &   / e3t(ji,jj,ibld(ji,jj),Kmm)
+           zdbdz(ji,jj) = grav * zthermal * zdtdz(ji,jj) - grav * zbeta * zdsdz(ji,jj)
+        ELSE
+           zdtdz(ji,jj) = 0._wp
+           zdsdz(ji,jj) = 0._wp
+           zdbdz(ji,jj) = 0._wp
+        END IF
+     END_2D
+    END SUBROUTINE zdf_osm_external_gradients
+
+    SUBROUTINE zdf_osm_pycnocline_scalar_profiles( zdtdz, zdsdz, zdbdz, zalpha )
+
+     REAL(wp), DIMENSION(jpi,jpj,jpk) :: zdtdz, zdsdz, zdbdz      ! gradients in the pycnocline
+     REAL(wp), DIMENSION(jpi,jpj) :: zalpha
+
+     INTEGER :: jk, jj, ji
+     REAL(wp) :: ztgrad, zsgrad, zbgrad
+     REAL(wp) :: zgamma_b_nd, znd
+     REAL(wp) :: zzeta_m, zzeta_en, zbuoy_pyc_sc
+     REAL(wp), PARAMETER :: zgamma_b = 2.25, zzeta_sh = 0.15
+
+     DO_2D( 0, 0, 0, 0 )
+        IF ( ibld(ji,jj) + jp_ext(ji,jj) < mbkt(ji,jj) ) THEN
+           IF ( lconv(ji,jj) ) THEN  ! convective conditions
+             IF ( lpyc(ji,jj) ) THEN
+                zzeta_m = 0.1 + 0.3 / ( 1.0 + EXP( -3.5 * LOG10( -zhol(ji,jj) ) ) )
+                zalpha(ji,jj) = 2.0 * ( 1.0 - ( 0.80 * zzeta_m + 0.5 * SQRT( 3.14159 / zgamma_b ) ) * zdbdz_bl_ext(ji,jj) * zdh(ji,jj) / zdb_ml(ji,jj) ) / ( 0.723 + SQRT( 3.14159 / zgamma_b ) )
+                zalpha(ji,jj) = MAX( zalpha(ji,jj), 0._wp )
+
+                ztmp = 1._wp/MAX(zdh(ji,jj), epsln)
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! Commented lines in this section are not needed in new code, once tested !
+! can be removed                                                          !
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!                   ztgrad = zalpha * zdt_ml(ji,jj) * ztmp + zdtdz_bl_ext(ji,jj)
+!                   zsgrad = zalpha * zds_ml(ji,jj) * ztmp + zdsdz_bl_ext(ji,jj)
+                zbgrad = zalpha(ji,jj) * zdb_ml(ji,jj) * ztmp + zdbdz_bl_ext(ji,jj)
+                zgamma_b_nd = zdbdz_bl_ext(ji,jj) * zdh(ji,jj) / MAX(zdb_ml(ji,jj), epsln)
+                DO jk = 2, ibld(ji,jj)+ibld_ext
+                  znd = -( gdepw(ji,jj,jk,Kmm) - zhbl(ji,jj) ) * ztmp
+                  IF ( znd <= zzeta_m ) THEN
+!                        zdtdz(ji,jj,jk) = zdtdz_bl_ext(ji,jj) + zalpha * zdt_ml(ji,jj) * ztmp * &
+!                &        EXP( -6.0 * ( znd -zzeta_m )**2 )
+!                        zdsdz(ji,jj,jk) = zdsdz_bl_ext(ji,jj) + zalpha * zds_ml(ji,jj) * ztmp * &
+!                                  & EXP( -6.0 * ( znd -zzeta_m )**2 )
+                     zdbdz(ji,jj,jk) = zdbdz_bl_ext(ji,jj) + zalpha(ji,jj) * zdb_ml(ji,jj) * ztmp * &
+                               & EXP( -6.0 * ( znd -zzeta_m )**2 )
+                  ELSE
+!                         zdtdz(ji,jj,jk) =  ztgrad * EXP( -zgamma_b * ( znd - zzeta_m )**2 )
+!                         zdsdz(ji,jj,jk) =  zsgrad * EXP( -zgamma_b * ( znd - zzeta_m )**2 )
+                      zdbdz(ji,jj,jk) =  zbgrad * EXP( -zgamma_b * ( znd - zzeta_m )**2 )
+                  ENDIF
+               END DO
+            ENDIF ! if no pycnocline pycnocline gradients set to zero
+           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(ji,jj,jk,Kmm) * 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(ji,jj,jk,Kmm) - 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)
+        ENDIF      ! IF ( ibld(ji,jj) < mbkt(ji,jj) )
+     END_2D
+
+    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
-
-
-   SUBROUTINE zdf_osm_init( Kmm ) 
+      DO_2D( 0, 0, 0, 0 )
+         !
+         IF ( ibld(ji,jj) + jp_ext(ji,jj) < mbkt(ji,jj) ) THEN
+            IF ( lconv (ji,jj) ) THEN
+               ! Unstable conditions. Shouldn;t be needed with no pycnocline code.
+!                  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(ji,jj,jk,Kmm) - 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(ji,jj,jk,Kmm) / 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_2D
+    END SUBROUTINE zdf_osm_pycnocline_shear_profiles
+
+   SUBROUTINE zdf_osm_calculate_dhdt( zdhdt, zddhdt )
+     !!---------------------------------------------------------------------
+     !!                   ***  ROUTINE zdf_osm_calculate_dhdt  ***
+     !!
+     !! ** Purpose : Calculates the rate at which hbl changes.
+     !!
+     !! ** Method  :
+     !!
+     !!----------------------------------------------------------------------
+
+    REAL(wp), DIMENSION(jpi,jpj) :: zdhdt, zddhdt        ! Rate of change of hbl
+
+    INTEGER :: jj, ji
+    REAL(wp) :: zgamma_b_nd, zgamma_dh_nd, zpert, zpsi
+    REAL(wp) :: zvel_max!, zwb_min
+    REAL(wp) :: zzeta_m = 0.3
+    REAL(wp) :: zgamma_c = 2.0
+    REAL(wp) :: zdhoh = 0.1
+    REAL(wp) :: alpha_bc = 0.5
+    REAL, PARAMETER :: a_ddh = 2.5, a_ddh_2 = 3.5 ! also in pycnocline_depth
+ 
+  DO_2D( 0, 0, 0, 0 )
+    
+    IF ( lshear(ji,jj) ) THEN
+       IF ( lconv(ji,jj) ) THEN    ! Convective
+
+          IF ( ln_osm_mle ) THEN
+
+             IF ( hmle(ji,jj) > hbl(ji,jj) ) THEN
+       ! Fox-Kemper buoyancy flux average over OSBL
+                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_bl_ext(ji,jj) > 0.0 ) THEN
+! *** Used for shear Needs to be changed to work stabily
+!                zgamma_b_nd = zdbdz_bl_ext * dh / zdb_ml
+!                zalpha_b = 6.7 * zgamma_b_nd / ( 1.0 + zgamma_b_nd )
+!                zgamma_b = zgamma_b_nd / ( 0.12 * ( 1.25 + zgamma_b_nd ) )
+!                za_1 = 1.0 / zgamma_b**2 - 0.017
+!                za_2 = 1.0 / zgamma_b**3 - 0.0025
+!                zpsi = zalpha_b * ( 1.0 + zgamma_b_nd ) * ( za_1 - 2.0 * za_2 * dh / hbl )
+                   zpsi = 0._wp
+                   zdhdt(ji,jj) = -( zwb_ent(ji,jj) + 2.0 * zwb_fk_b(ji,jj) ) / ( zvel_max + MAX(zdb_bl(ji,jj), 1.0e-15) )
+                   zdhdt(ji,jj) = zdhdt(ji,jj)! - zpsi * ( -1.0 / zhml(ji,jj) + 2.4 * zdbdz_bl_ext(ji,jj) / zdb_ml(ji,jj) ) * zwb_min(ji,jj) * zdh(ji,jj) / zdb_bl(ji,jj)
+                   IF ( j_ddh(ji,jj) == 1 ) THEN
+                     IF ( ( zwstrc(ji,jj) / zvstr(ji,jj) )**3 <= 0.5 ) THEN
+                        zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zvstr(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+                     ELSE
+                        zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zwstrc(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+                     ENDIF
+! Relaxation to dh_ref = zari * hbl
+                     zddhdt(ji,jj) = -a_ddh_2 * ( 1.0 - zdh(ji,jj) / ( zari * zhbl(ji,jj) ) ) * zwb_ent(ji,jj) / zdb_bl(ji,jj)
+                     
+                   ELSE  ! j_ddh == 0
+! Growing shear layer
+                     zddhdt(ji,jj) = -a_ddh * ( 1.0 - zdh(ji,jj) / zhbl(ji,jj) ) * zwb_ent(ji,jj) / zdb_bl(ji,jj)
+                   ENDIF ! j_ddh
+                     zdhdt(ji,jj) = zdhdt(ji,jj) ! + zpsi * zddhdt(ji,jj)
+                ELSE    ! zdb_bl >0
+                   zdhdt(ji,jj) = -( zwb_ent(ji,jj) + 2.0 * zwb_fk_b(ji,jj) ) /  MAX( zvel_max, 1.0e-15)
+                ENDIF
+             ELSE   ! zwb_min + 2*zwb_fk_b < 0
+                ! 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_Dt / hbl(ji,jj) ) * zwb_ent(ji,jj) / &
+               &        MAX((zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird, epsln)
+               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  ! ln_osm_mle
+
+         ELSE    ! lconv - Stable
+             zdhdt(ji,jj) = ( 0.06 + 0.52 * zhol(ji,jj) / 2.0 ) * zvstr(ji,jj)**3 / hbl(ji,jj) + zwbav(ji,jj)
+             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_Dt / hbl(ji,jj) ) * zvstr(ji,jj)**2 / hbl(ji,jj)
+             ELSE
+                 zpert = MAX( 2.0 * zvstr(ji,jj)**2 / hbl(ji,jj), zdb_bl(ji,jj) )
+             ENDIF
+             zdhdt(ji,jj) = 2.0 * zdhdt(ji,jj) / MAX(zpert, epsln)
+         ENDIF  ! lconv
+    ELSE ! lshear
+      IF ( lconv(ji,jj) ) THEN    ! Convective
+
+          IF ( ln_osm_mle ) THEN
+
+             IF ( hmle(ji,jj) > hbl(ji,jj) ) THEN
+       ! Fox-Kemper buoyancy flux average over OSBL
+                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_bl_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 = -zwb_ent(ji,jj) / &
+               &        MAX((zvstr(ji,jj)**3 + 0.5 * zwstrc(ji,jj)**3 )**pthird, epsln)
+               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  ! ln_osm_mle
+
+         ELSE                        ! Stable
+             zdhdt(ji,jj) = ( 0.06 + 0.52 * zhol(ji,jj) / 2.0 ) * zvstr(ji,jj)**3 / hbl(ji,jj) + zwbav(ji,jj)
+             IF ( zdhdt(ji,jj) < 0._wp ) THEN
+                ! For long timsteps factor in brackets slows the rapid collapse of the OSBL
+                 zpert = 2.0 * zvstr(ji,jj)**2 / hbl(ji,jj)
+             ELSE
+                 zpert = MAX( 2.0 * zvstr(ji,jj)**2 / hbl(ji,jj), zdb_bl(ji,jj) )
+             ENDIF
+             zdhdt(ji,jj) = 2.0 * zdhdt(ji,jj) / MAX(zpert, epsln)
+         ENDIF  ! lconv
+      ENDIF ! lshear
+  END_2D
+    END SUBROUTINE zdf_osm_calculate_dhdt
+
+    SUBROUTINE zdf_osm_timestep_hbl( zdhdt )
+     !!---------------------------------------------------------------------
+     !!                   ***  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   ! rates of change of hbl.
+
+    INTEGER :: jk, jj, ji, jm
+    REAL(wp) :: zhbl_s, zvel_max, zdb
+    REAL(wp) :: zthermal, zbeta
+
+     DO_2D( 0, 0, 0, 0 )
+        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_Dt / 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) - ts(ji,jj,jm,jp_tem,Kmm) ) &
+                      & - zbeta * ( zs_bl(ji,jj) - ts(ji,jj,jm,jp_sal,Kmm) ) ), &
+                      &  0.0 ) + zvel_max
+
+
+                 IF ( ln_osm_mle ) THEN
+                    zhbl_s = zhbl_s + MIN( &
+                     & rn_Dt * ( ( -zwb_ent(ji,jj) - 2.0 * zwb_fk_b(ji,jj) )/ zdb ) / FLOAT(ibld(ji,jj) - imld(ji,jj) ), &
+                     & e3w(ji,jj,jm,Kmm) )
+                 ELSE
+                   zhbl_s = zhbl_s + MIN( &
+                     & rn_Dt * (  -zwb_ent(ji,jj) / zdb ) / FLOAT(ibld(ji,jj) - imld(ji,jj) ), &
+                     & e3w(ji,jj,jm,Kmm) )
+                 ENDIF
+
+!                    zhbl_s = MIN(zhbl_s,  gdepw(ji,jj, mbkt(ji,jj) + 1,Kmm) - depth_tol)
+                 IF ( zhbl_s >= gdepw(ji,jj,mbkt(ji,jj) + 1,Kmm) ) THEN
+                   zhbl_s = MIN(zhbl_s,  gdepw(ji,jj, mbkt(ji,jj) + 1,Kmm) - depth_tol)
+                   lpyc(ji,jj) = .FALSE.
+                 ENDIF
+                 IF ( zhbl_s >= gdepw(ji,jj,jm+1,Kmm) ) 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) - ts(ji,jj,jm,jp_tem,Kmm) )&
+                      &           - zbeta * ( zs_bl(ji,jj) - ts(ji,jj,jm,jp_sal,Kmm) ) ),&
+                      & 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_Dt / FLOAT( ibld(ji,jj) - imld(ji,jj) ), e3w(ji,jj,jm,Kmm) )
+
+!                    zhbl_s = MIN(zhbl_s, gdepw(ji,jj, mbkt(ji,jj) + 1,Kmm) - depth_tol)
+                 IF ( zhbl_s >= mbkt(ji,jj) + 1 ) THEN
+                   zhbl_s = MIN(zhbl_s,  gdepw(ji,jj, mbkt(ji,jj) + 1,Kmm) - depth_tol)
+                   lpyc(ji,jj) = .FALSE.
+                 ENDIF
+                 IF ( zhbl_s >= gdepw(ji,jj,jm,Kmm) ) jm = jm + 1
+              END DO
+          ENDIF   ! IF ( lconv )
+          hbl(ji,jj) = MAX(zhbl_s, gdepw(ji,jj,4,Kmm) )
+          ibld(ji,jj) = MAX(jm, 4 )
+        ELSE
+! change zero or one model level.
+          hbl(ji,jj) = MAX(zhbl_t(ji,jj), gdepw(ji,jj,4,Kmm) )
+        ENDIF
+        zhbl(ji,jj) = gdepw(ji,jj,ibld(ji,jj),Kmm)
+     END_2D
+
+    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, zdh_ref
+      REAL, PARAMETER :: a_ddh_2 = 3.5 ! also in pycnocline_depth
+
+    DO_2D( 0, 0, 0, 0 )
+
+      IF ( lshear(ji,jj) ) THEN
+         IF ( lconv(ji,jj) ) THEN
+           IF ( j_ddh(ji,jj) == 0 ) THEN
+! ddhdt for pycnocline determined in osm_calculate_dhdt
+             dh(ji,jj) = dh(ji,jj) + zddhdt(ji,jj) * rn_Dt
+           ELSE
+! Temporary (probably) Recalculate dh_ref to ensure dh doesn't go negative. Can't do this using zddhdt from calculate_dhdt 
+             IF ( ( zwstrc(ji,jj) / zvstr(ji,jj) )**3 <= 0.5 ) THEN
+               zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zvstr(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+             ELSE
+               zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zwstrc(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+             ENDIF
+             ztau = MAX( zdb_bl(ji,jj) * ( zari * hbl(ji,jj) ) / ( a_ddh_2 * MAX(-zwb_ent(ji,jj), 1.e-12) ), 2.0 * rn_Dt )
+             dh(ji,jj) = dh(ji,jj) * EXP( -rn_Dt / ztau ) + zari * zhbl(ji,jj) * ( 1.0 - EXP( -rn_Dt / ztau ) )
+             IF ( dh(ji,jj) >= hbl(ji,jj) ) dh(ji,jj) = zari * zhbl(ji,jj)
+           ENDIF
+            
+         ELSE ! lconv
+! Initially shear only for entraining OSBL. Stable code will be needed if extended to stable OSBL 
+
+            ztau = hbl(ji,jj) / MAX(zvstr(ji,jj), epsln)
+            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 ) &
+                       & /  MAX(zdb_bl(ji,jj) * zhbl(ji,jj), epsln ) + 0.01  , 0.2 )
+                  zdh_ref = MIN( zari, 0.2 ) * hbl(ji,jj)
+               ELSE
+                  zdh_ref = 0.2 * hbl(ji,jj)
+               ENDIF
+            ELSE     ! IF(dhdt < 0)
+               zdh_ref = 0.2 * hbl(ji,jj)
+            ENDIF    ! IF (dhdt >= 0)
+            dh(ji,jj) = dh(ji,jj) * EXP( -rn_Dt / ztau )+ zdh_ref * ( 1.0 - EXP( -rn_Dt / ztau ) )
+            IF ( zdhdt(ji,jj) < 0._wp .and. dh(ji,jj) >= hbl(ji,jj) ) dh(ji,jj) = zdh_ref       ! can be a problem with dh>hbl for rapid collapse
+            ! Alan: this hml is never defined or used -- do we need it?
+         ENDIF
+          
+      ELSE   ! lshear  
+! for lshear = .FALSE. calculate ddhdt here
+
+          IF ( lconv(ji,jj) ) THEN
+
+            IF( ln_osm_mle ) THEN
+               IF ( ( zwb_ent(ji,jj) + 2.0 * 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_bl_ext(ji,jj) > 0._wp)THEN
+                     IF ( ( zwstrc(ji,jj) / MAX(zvstr(ji,jj), epsln) )**3 <= 0.5 ) THEN  ! near neutral stability
+                        zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zvstr(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+                     ELSE                                                     ! unstable
+                        zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zwstrc(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+                     ENDIF
+                     ztau = 0.2 * hbl(ji,jj) / MAX(epsln, (zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3)**pthird)
+                     zdh_ref = zari * hbl(ji,jj)
+                  ELSE
+                     ztau = 0.2 * hbl(ji,jj) / MAX(epsln, (zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3)**pthird)
+                     zdh_ref = 0.2 * hbl(ji,jj)
+                  ENDIF
+               ELSE
+                  ztau = 0.2 * hbl(ji,jj) /  MAX(epsln, (zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3)**pthird)
+                  zdh_ref = 0.2 * hbl(ji,jj)
+               ENDIF
+            ELSE ! ln_osm_mle
+               IF ( zdb_bl(ji,jj) > 0._wp .and. zdbdz_bl_ext(ji,jj) > 0._wp)THEN
+                  IF ( ( zwstrc(ji,jj) / MAX(zvstr(ji,jj), epsln) )**3 <= 0.5 ) THEN  ! near neutral stability
+                     zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zvstr(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+                  ELSE                                                     ! unstable
+                     zari = MIN( 1.5 * zdb_bl(ji,jj) / ( zhbl(ji,jj) * ( MAX(zdbdz_bl_ext(ji,jj),0._wp) + zdb_bl(ji,jj)**2 / MAX(4.5 * zwstrc(ji,jj)**2 , 1.e-12 )) ), 0.2d0 )
+                  ENDIF
+                  ztau = hbl(ji,jj) / MAX(epsln, (zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3)**pthird)
+                  zdh_ref = zari * hbl(ji,jj)
+               ELSE
+                  ztau = hbl(ji,jj) / MAX(epsln, (zvstr(ji,jj)**3 + 0.5 *zwstrc(ji,jj)**3)**pthird)
+                  zdh_ref = 0.2 * hbl(ji,jj)
+               ENDIF
+
+            END IF  ! ln_osm_mle
+
+            dh(ji,jj) = dh(ji,jj) * EXP( -rn_Dt / ztau ) + zdh_ref * ( 1.0 - EXP( -rn_Dt / ztau ) )
+!               IF ( zdhdt(ji,jj) < 0._wp .and. dh(ji,jj) >= hbl(ji,jj) ) dh(ji,jj) = zdh_ref
+            IF ( dh(ji,jj) >= hbl(ji,jj) ) dh(ji,jj) = zdh_ref
+            ! Alan: this hml is never defined or used
+         ELSE   ! IF (lconv)
+            ztau = hbl(ji,jj) / MAX(zvstr(ji,jj), epsln)
+            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 ) &
+                       & /  MAX(zdb_bl(ji,jj) * zhbl(ji,jj), epsln ) + 0.01  , 0.2 )
+                  zdh_ref = MIN( zari, 0.2 ) * hbl(ji,jj)
+               ELSE
+                  zdh_ref = 0.2 * hbl(ji,jj)
+               ENDIF
+            ELSE     ! IF(dhdt < 0)
+               zdh_ref = 0.2 * hbl(ji,jj)
+            ENDIF    ! IF (dhdt >= 0)
+            dh(ji,jj) = dh(ji,jj) * EXP( -rn_Dt / ztau )+ zdh_ref * ( 1.0 - EXP( -rn_Dt / ztau ) )
+            IF ( zdhdt(ji,jj) < 0._wp .and. dh(ji,jj) >= hbl(ji,jj) ) dh(ji,jj) = zdh_ref       ! can be a problem with dh>hbl for rapid collapse
+         ENDIF       ! IF (lconv)
+      ENDIF  ! lshear
+ 
+      hml(ji,jj) = hbl(ji,jj) - dh(ji,jj)
+      inhml = MAX( INT( dh(ji,jj) / MAX(e3t(ji,jj,ibld(ji,jj),Kmm), 1.e-3) ) , 1 )
+      imld(ji,jj) = MAX( ibld(ji,jj) - inhml, 3)
+      zhml(ji,jj) = gdepw(ji,jj,imld(ji,jj),Kmm)
+      zdh(ji,jj) = zhbl(ji,jj) - zhml(ji,jj)
+    END_2D
+
+    END SUBROUTINE zdf_osm_pycnocline_thickness
+
+
+   SUBROUTINE zdf_osm_zmld_horizontal_gradients( zmld, zdtdx, zdtdy, zdsdx, zdsdy, dbdx_mle, dbdy_mle, zdbds_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)     :: zdbds_mle ! Magnitude of horizontal buoyancy gradient.
+      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_rho0   ! convert density criteria into N^2 criteria
+      DO_3D( 1, 1, 1, 1, nlb10, jpkm1 )
+         ikt = mbkt(ji,jj)
+         zmld(ji,jj) = zmld(ji,jj) + MAX( rn2b(ji,jj,jk) , 0._wp ) * e3w(ji,jj,jk,Kmm)
+         IF( zmld(ji,jj) < zN2_c )   mld_prof(ji,jj) = MIN( jk , ikt ) + 1   ! Mixed layer level
+      END_3D
+      DO_2D( 1, 1, 1, 1 )
+         mld_prof(ji,jj) = MAX(mld_prof(ji,jj),ibld(ji,jj))
+         zmld(ji,jj) = gdepw(ji,jj,mld_prof(ji,jj),Kmm)
+      END_2D
+      ! ensure mld_prof .ge. ibld
+      !
+      ikmax = MIN( MAXVAL( mld_prof(:,:) ), jpkm1 )                  ! max level of the computation
+      !
+      ztm(:,:) = 0._wp
+      zsm(:,:) = 0._wp
+      DO_3D( 1, 1, 1, 1, 1, ikmax )
+         zc = e3t(ji,jj,jk,Kmm) * 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 * ts(ji,jj,jk,jp_tem,Kmm)
+         zsm(ji,jj) = zsm(ji,jj) + zc * ts(ji,jj,jk,jp_sal,Kmm)
+      END_3D
+      ! average temperature and salinity.
+      ztm(:,:) = ztm(:,:) / MAX( e3t(:,:,1,Kmm), zmld(:,:) )
+      zsm(:,:) = zsm(:,:) / MAX( e3t(:,:,1,Kmm), zmld(:,:) )
+      ! calculate horizontal gradients at u & v points
+
+      DO_2D( 0, 0, 1, 0 )
+         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_2D
+
+      DO_2D( 1, 0, 0, 0 )
+         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_2D
+
+      CALL eos_rab(ztsm_midu, zmld_midu, zabu, Kmm)
+      CALL eos_rab(ztsm_midv, zmld_midv, zabv, Kmm)
+
+      DO_2D( 0, 0, 1, 0 )
+         dbdx_mle(ji,jj) = grav*(zdtdx(ji,jj)*zabu(ji,jj,jp_tem) - zdsdx(ji,jj)*zabu(ji,jj,jp_sal))
+      END_2D
+      DO_2D( 1, 0, 0, 0 )
+         dbdy_mle(ji,jj) = grav*(zdtdy(ji,jj)*zabv(ji,jj,jp_tem) - zdsdy(ji,jj)*zabv(ji,jj,jp_sal))
+      END_2D
+
+      DO_2D( 0, 0, 0, 0 )
+        ztmp =  r1_ft(ji,jj) *  MIN( 111.e3_wp , e1u(ji,jj) ) / rn_osm_mle_lf
+        zdbds_mle(ji,jj) = 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) ) )
+      END_2D
+      
+ END SUBROUTINE zdf_osm_zmld_horizontal_gradients
+  SUBROUTINE zdf_osm_mle_parameters( mld_prof, hmle, zhmle, 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
+
+      INTEGER, DIMENSION(jpi,jpj)      :: mld_prof
+      REAL(wp), DIMENSION(jpi,jpj)     :: hmle, zhmle, zwb_fk, zvel_mle, zdiff_mle
+      INTEGER  ::   ji, jj, jk          ! dummy loop indices
+      INTEGER  ::   ii, ij, ik, jkb, jkb1  ! local integers
+      INTEGER , DIMENSION(jpi,jpj)     :: inml_mle
+      REAL(wp) ::  ztmp, zdbdz, zdtdz, zdsdz, zthermal,zbeta, zbuoy, zdb_mle
+
+   ! Calculate vertical buoyancy, heat and salinity fluxes due to MLE.
+
+      DO_2D( 0, 0, 0, 0 )
+       IF ( lconv(ji,jj) ) THEN
+          ztmp =  r1_ft(ji,jj) *  MIN( 111.e3_wp , e1u(ji,jj) ) / rn_osm_mle_lf
+   ! This velocity scale, defined in Fox-Kemper et al (2008), is needed for calculating dhdt.
+          zvel_mle(ji,jj) = zdbds_mle(ji,jj) * ztmp * hmle(ji,jj) * tmask(ji,jj,1)
+          zdiff_mle(ji,jj) = 5.e-4_wp * rn_osm_mle_ce * ztmp * zdbds_mle(ji,jj) * zhmle(ji,jj)**2
+       ENDIF
+      END_2D
+   ! Timestep mixed layer eddy depth.
+      DO_2D( 0, 0, 0, 0 )
+        IF ( lmle(ji,jj) ) THEN  ! MLE layer growing.
+! Buoyancy gradient at base of MLE layer.
+           zthermal = rab_n(ji,jj,1,jp_tem)
+           zbeta    = rab_n(ji,jj,1,jp_sal)
+           jkb = mld_prof(ji,jj)
+           jkb1 = MIN(jkb + 1, mbkt(ji,jj))
+!              
+           zbuoy = grav * ( zthermal * ts(ji,jj,mld_prof(ji,jj)+2,jp_tem,Kmm) - zbeta * ts(ji,jj,mld_prof(ji,jj)+2,jp_sal,Kmm) )
+           zdb_mle = zb_bl(ji,jj) - zbuoy 
+! Timestep hmle. 
+           hmle(ji,jj) = hmle(ji,jj) + zwb0(ji,jj) * rn_Dt / zdb_mle
+        ELSE
+           IF ( zhmle(ji,jj) > zhbl(ji,jj) ) THEN
+              hmle(ji,jj) = hmle(ji,jj) - ( hmle(ji,jj) - hbl(ji,jj) ) * rn_Dt / rn_osm_mle_tau
+           ELSE
+              hmle(ji,jj) = hmle(ji,jj) - 10.0 * ( hmle(ji,jj) - hbl(ji,jj) ) * rn_Dt /rn_osm_mle_tau
+           ENDIF
+        ENDIF
+        hmle(ji,jj) = MIN(hmle(ji,jj), ht(ji,jj))
+       IF(ln_osm_hmle_limit) hmle(ji,jj) = MIN(hmle(ji,jj), MAX(rn_osm_hmle_limit,1.2*hbl(ji,jj)) )
+      END_2D
+
+      mld_prof = 4
+      DO_3D( 0, 0, 0, 0, 5, jpkm1 )
+      IF ( hmle(ji,jj) >= gdepw(ji,jj,jk,Kmm) ) mld_prof(ji,jj) = MIN(mbkt(ji,jj), jk)
+      END_3D
+      DO_2D( 0, 0, 0, 0 )
+         zhmle(ji,jj) = gdepw(ji,jj, mld_prof(ji,jj),Kmm)
+      END_2D
+END SUBROUTINE zdf_osm_mle_parameters
+
+END SUBROUTINE zdf_osm
+
+
+   SUBROUTINE zdf_osm_init( Kmm )
      !!----------------------------------------------------------------------
      !!                  ***  ROUTINE zdf_osm_init  ***
@@ -1304,12 +2456,17 @@
      !! ** input   :   Namlist namosm
      !!----------------------------------------------------------------------
-     INTEGER, INTENT(in)    :: Kmm ! time level index (middle)
-     !
+     INTEGER, INTENT(in)   ::   Kmm       ! time level
      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
+          & ,nn_osm_wave, ln_dia_osm, rn_osm_hbl0, rn_zdfosm_adjust_sd &
+          & ,ln_kpprimix, rn_riinfty, rn_difri, ln_convmix, rn_difconv, nn_osm_wave &
+          & ,nn_osm_SD_reduce, ln_osm_mle, rn_osm_hblfrac, rn_osm_bl_thresh, ln_zdfosm_ice_shelter
+! 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, ln_osm_hmle_limit, rn_osm_hmle_limit
+
      !!----------------------------------------------------------------------
      !
@@ -1325,9 +2482,11 @@
         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,*) '     Stokes drift reduction factor                 rn_zdfosm_adjust_sd   = ', rn_zdfosm_adjust_sd
         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
@@ -1339,6 +2498,19 @@
         CASE(2)
            WRITE(numout,*) '     calculated from ECMWF wave fields'
+         END SELECT
+        WRITE(numout,*) '     Stokes drift reduction                        nn_osm_SD_reduce', nn_osm_SD_reduce
+        WRITE(numout,*) '     fraction of hbl to average SD over/fit'
+        WRITE(numout,*) '     exponential with nn_osm_SD_reduce = 1 or 2    rn_osm_hblfrac =  ', rn_osm_hblfrac
+        SELECT CASE (nn_osm_SD_reduce)
+        CASE(0)
+           WRITE(numout,*) '     No reduction'
+        CASE(1)
+           WRITE(numout,*) '     Average SD over upper rn_osm_hblfrac of BL'
+        CASE(2)
+           WRITE(numout,*) '     Fit exponential to slope rn_osm_hblfrac of BL'
         END SELECT
+        WRITE(numout,*) '     reduce surface SD and depth scale under ice   ln_zdfosm_ice_shelter=', ln_zdfosm_ice_shelter
         WRITE(numout,*) '     Output osm diagnostics                       ln_dia_osm  = ',  ln_dia_osm
+        WRITE(numout,*) '         Threshold used to define BL              rn_osm_bl_thresh  = ', rn_osm_bl_thresh, 'm^2/s'
         WRITE(numout,*) '     Use KPP-style shear instability mixing       ln_kpprimix = ', ln_kpprimix
         WRITE(numout,*) '     local Richardson Number limit for shear instability rn_riinfty = ', rn_riinfty
@@ -1359,5 +2531,68 @@
      IF( zdf_osm_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_osm_init : unable to allocate arrays' )
 
-     call osm_rst( nit000, Kmm, 'READ' ) !* read or initialize hbl
+
+     IF( ln_osm_mle ) THEN
+! Initialise Fox-Kemper parametrization
+         READ  ( numnam_ref, namosm_mle, IOSTAT = ios, ERR = 903)
+903      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namosm_mle in reference namelist')
+
+         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 MLE 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'
+            WRITE(numout,*) '         switch to limit hmle                                      ln_osm_hmle_limit  = ', ln_osm_hmle_limit
+            WRITE(numout,*) '         fraction of zmld to limit hmle to if ln_osm_hmle_limit =.T.  rn_osm_hmle_limit = ', rn_osm_hmle_limit
+         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 /rho0        ! 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_2D( 1, 1, 1, 1 )
+            r1_ft(ji,jj) = MIN(1./( ABS(ff_t(ji,jj)) + epsln ), ABS(ff_t(ji,jj))/z1_t2**2)
+         END_2D
+         ! 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, Kmm,  'READ' ) !* read or initialize hbl, dh, hmle
+
 
      IF( ln_zdfddm) THEN
@@ -1454,5 +2689,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
@@ -1460,5 +2695,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)
      !!----------------------------------------------------------------------
      !
@@ -1470,17 +2705,28 @@
         IF( id1 > 0 ) THEN                       ! 'wn' exists; read
            CALL iom_get( numror, jpdom_auto, 'wn', ww )
-           WRITE(numout,*) ' ===>>>> :  ww read from restart file'
+           WRITE(numout,*) ' ===>>>> :  wn read from restart file'
         ELSE
            ww(:,:,:) = 0._wp
-           WRITE(numout,*) ' ===>>>> :  ww not in restart file, set to zero initially'
+           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_auto, 'hbl' , hbl  )
-           CALL iom_get( numror, jpdom_auto, 'hbli', hbli  )
-           WRITE(numout,*) ' ===>>>> :  hbl & hbli read from restart file'
+           CALL iom_get( numror, jpdom_auto, 'dh', dh )
+           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_auto, 'hmle' , hmle )
+                 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
@@ -1490,11 +2736,12 @@
      ! If READ/WRITE Flag is 'WRITE', write hbl into the restart file, then return
      !!-----------------------------------------------------------------------------
-     IF( TRIM(cdrw) == 'WRITE') THEN     !* Write hbli into the restart file, then return
-        IF( ntile /= 0 .AND. ntile /= nijtile ) RETURN        ! Do only on the last tile
-
+     IF( TRIM(cdrw) == 'WRITE') THEN     !* Write hbl into the restart file, then return
         IF(lwp) WRITE(numout,*) '---- osm-rst ----'
-         CALL iom_rstput( kt, nitrst, numrow, 'wn'     , ww   )
-         CALL iom_rstput( kt, nitrst, numrow, 'hbl'    , hbl  )
-         CALL iom_rstput( kt, nitrst, numrow, 'hbli'   , hbli )
+         CALL iom_rstput( kt, nitrst, numrow, 'wn'     , ww  )
+         CALL iom_rstput( kt, nitrst, numrow, 'hbl'    , hbl )
+         CALL iom_rstput( kt, nitrst, numrow, 'dh'     , dh  )
+         IF( ln_osm_mle ) THEN
+            CALL iom_rstput( kt, nitrst, numrow, 'hmle', hmle )
+         END IF
         RETURN
      END IF
@@ -1504,5 +2751,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( ts(:,:,:,:,Kmm), rab_n, Kmm )
@@ -1513,5 +2759,5 @@
      !
      hbl(:,:)  = 0._wp              ! here hbl used as a dummy variable, integrating vertically N^2
-     DO_3D( 1, 1, 1, 1, 1, jpkm1 )  ! Mixed layer level: w-level
+     DO_3D( 1, 1, 1, 1, 1, jpkm1 )
         ikt = mbkt(ji,jj)
         hbl(ji,jj) = hbl(ji,jj) + MAX( rn2(ji,jj,jk) , 0._wp ) * e3w(ji,jj,jk,Kmm)
@@ -1520,11 +2766,18 @@
      !
      DO_2D( 1, 1, 1, 1 )
-        iiki = imld_rst(ji,jj)
-        hbl (ji,jj) = gdepw(ji,jj,iiki  ,Kmm) * ssmask(ji,jj)    ! Turbocline depth
+        iiki = MAX(4,imld_rst(ji,jj))
+        hbl (ji,jj) = gdepw(ji,jj,iiki,Kmm  )    ! Turbocline depth
+        dh (ji,jj) = e3t(ji,jj,iiki-1,Kmm  )     ! Turbocline depth
      END_2D
-     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
+
+     ww(:,:,:) = 0._wp
+     WRITE(numout,*) ' ===>>>> :  wn not in restart file, set to zero initially'
    END SUBROUTINE osm_rst
 
@@ -1559,5 +2812,4 @@
       ENDIF
 
-      ! add non-local temperature and salinity flux
       DO_3D( 0, 0, 0, 0, 1, jpkm1 )
          pts(ji,jj,jk,jp_tem,Krhs) =  pts(ji,jj,jk,jp_tem,Krhs)                      &
@@ -1569,12 +2821,11 @@
       END_3D
 
-
-      ! save the non-local tracer flux trends for diagnostic
+      ! save the non-local tracer flux trends for diagnostics
       IF( l_trdtra )   THEN
          ztrdt(:,:,:) = pts(:,:,:,jp_tem,Krhs) - ztrdt(:,:,:)
          ztrds(:,:,:) = pts(:,:,:,jp_sal,Krhs) - ztrds(:,:,:)
-!!bug gm jpttdzdf ==> jpttosm
-         CALL trd_tra( kt, Kmm, Krhs, 'TRA', jp_tem, jptra_zdf, ztrdt )
-         CALL trd_tra( kt, Kmm, Krhs, 'TRA', jp_sal, jptra_zdf, ztrds )
+
+         CALL trd_tra( kt, Kmm, Krhs, 'TRA', jp_tem, jptra_osm, ztrdt )
+         CALL trd_tra( kt, Kmm, Krhs, 'TRA', jp_sal, jptra_osm, ztrds )
          DEALLOCATE( ztrdt )      ;     DEALLOCATE( ztrds )
       ENDIF
@@ -1642,3 +2893,4 @@
 
    !!======================================================================
+
 END MODULE zdfosm
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfphy.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfphy.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdfphy.F90	(revision 14062)
@@ -179,5 +179,5 @@
       IF( ln_zdfmfc .AND. ln_zdfosm )   CALL ctl_stop( 'zdf_phy_init: chose between ln_zdfmfc and ln_zdfosm' )
       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( lk_top    .AND. ln_zdfmfc )   CALL ctl_stop( 'zdf_phy_init: Mass Flux scheme is not working with key_top' )
       IF(lwp) THEN
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdftke.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdftke.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/ZDF/zdftke.F90	(revision 14062)
@@ -242,5 +242,5 @@
       !
       DO_2D( 0, 0, 0, 0 )
-         en(ji,jj,1) = MAX( rn_emin0, zbbrau * taum(ji,jj) ) * tmask(ji,jj,1)
+         en(ji,jj,1) = MAX( rn_emin0, zbbrau * taum(ji,jj) )
          zdiag(ji,jj,1) = 1._wp/en(ji,jj,1)
          zd_lw(ji,jj,1) = 1._wp  
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/module_example
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/module_example	(revision 14059)
+++ 	(revision )
@@ -1,197 +1,0 @@
-MODULE exampl
-   !!======================================================================
-   !!                       ***  MODULE  exampl  ***
-   !! Ocean physics:  brief description of the purpose of the module
-   !!                 (please no more than 2 lines)
-   !!======================================================================
-   !! History : 3.0  !  2008-06  (Author Names)  Original code
-   !!            -   !  2008-08  (Author names)  brief description of modifications
-   !!           3.3  !  2010-11  (Author names)        -              -
-   !!----------------------------------------------------------------------
-#if defined key_example
-   !!----------------------------------------------------------------------
-   !!   'key_example'  :                brief description of the key option
-   !!----------------------------------------------------------------------
-   !!   exa_mpl       : list of module subroutine (caution, never use the
-   !!   exa_mpl_init  : name of the module for a routine)
-   !!   exa_mpl_stp   : Please try to use 3 letter block for routine names
-   !!----------------------------------------------------------------------
-   USE module_name1   ! brief description of the used module
-   USE module_name2   ! ....
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   exa_mpl        ! routine called in xxx.F90 module
-   PUBLIC   exa_mpl_init   ! routine called in nemogcm.F90 module
-
-   TYPE ::   FLD_E                !: Structure type definition
-      CHARACTER(lc) ::   clname      ! clname description (default length, lc, is 256, see par_kind.F90)
-      INTEGER       ::   nfreqh      ! nfreqh description 
-   END TYPE FLD_E 
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   var1         !: var1 description. CAUTION always use !: to describe
-   !                                                          !  a PUBLIC variable: simplify its search : 
-   !                                                          !  grep var1 *90 | grep '!:'
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   var2, var2   !: several variable on a same line OK, but 
-   !                                                          !  DO NOT use continuation lines in declaration
-
-   !                               !!* namelist nam_xxx *
-   LOGICAL   ::   ln_opt = .TRUE.   ! give the default value of each namelist parameter
-   CHARACTER ::   cn_tex = 'T'      ! short description  of the variable
-   INTEGER   ::   nn_opt = 1        ! please respect the DOCTOR norm for namelist variable
-   REAL(wp)  ::   rn_var = 2._wp    ! (it becomes easy to identify them in the code)
-   TYPE(FLD) ::   sn_ex             ! structure
-
-   INTEGER                          ::   nint    ! nint  description (local permanent variable)
-   REAL(wp)                         ::   var     ! var         -                -
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   array   ! array       -                -
-
-   !! * Substitutions
-   ! for DO macro
-#  include "do_loop_substitute.h90"
-   !for other substitutions
-#  include "exampl_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id$ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION exa_mpl_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION exa_mpl_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( array(jpi,jpj,jpk) , STAT= exa_mpl_alloc )   ! Module array                                                                
-      !
-      CALL mpp_sum ( 'module_example', exa_mpl_alloc )
-      IF( exa_mpl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'exa_mpl_alloc: failed to allocate arrays' )
-      !
-   END FUNCTION exa_mpl_alloc
-   
-
-   SUBROUTINE exa_mpl( kt, pvar1, pvar2, ptab )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE exa_mpl  ***
-      !!
-      !! ** Purpose :   Brief description of the routine
-      !!
-      !! ** Method  :   description of the methodoloy used to achieve the
-      !!                objectives of the routine. Be as clear as possible!
-      !!
-      !! ** Action  : - first action (share memory array/varible modified
-      !!                in this routine
-      !!              - second action .....
-      !!              - .....
-      !!
-      !! References :   Author et al., Short_name_review, Year
-      !!                Give references if exist otherwise suppress these lines
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                     ::   kt      ! short description 
-      INTEGER , INTENT(inout)                     ::   pvar1   !   -         -
-      REAL(wp), INTENT(  out)                     ::   pvar2   !   -         -
-      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   pvar2   !   -         -
-      !!
-      INTEGER  ::   ji, jj, jk       ! dummy loop arguments  (DOCTOR : start with j, but not jp)
-      INTEGER  ::   itoto, itata     ! temporary integers    (DOCTOR : start with i
-      REAL(wp) ::   zmlmin, zbbrho   ! temporary scalars     (DOCTOR : start with z)
-      REAL(wp) ::   zfact1, zfact2   ! do not use continuation lines in declaration
-      REAL(wp), DIMENSION(A2D(nn_hls))     ::   zwrk_2d   ! 2D workspace
-      REAL(wp), DIMENSION(A2D(nn_hls),jpk) ::   zwrk_3d   ! 3D workspace
-      !!--------------------------------------------------------------------
-      !
-      IF( ntile == 0 .OR. ntile == 1 )  THEN                       ! Do only on the first tile
-         IF( kt == nit000  )   CALL exa_mpl_init    ! Initialization (first time-step only)
-
-         zmlmin = 1.e-8                             ! Local constant initialization
-         zbbrho =  .5 * ebb / rho0
-         zfact1 = -.5 * rdt * efave
-         zfact2 = 1.5 * rdt * ediss
-      ENDIF
-	  
-      SELECT CASE ( npdl )                       ! short description of the action
-      !
-      CASE ( 0 )                                      ! describe case 1
-         DO_3D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1, 1, jpkm1 )
-            avm(ji,jj,jk) = ....
-         END_3D
-         !
-      CASE ( 1 )                                      ! describe case 2
-         DO_3D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1, 1, jpkm1 )
-            avm(ji,jj,jk) = ....
-         END_3D
-         !
-      END SELECT
-      !
-      ! WARNING! the lbc_lnk call could not be compatible with the tiling approach
-      ! please refer to the manual for how to adapt your code
-      CALL lbc_lnk( 'module_example', avm, 'T', 1., ncsten=true )     ! Lateral boundary conditions (unchanged sign)
-      !                                                                ! ncsten=false for 5-points stencil communication
-      !                                                                ! ncsten=true (default)  for 9-points stencil communication
-      !
-   END SUBROUTINE exa_mpl
-
-
-   SUBROUTINE exa_mpl_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE exa_mpl_init  ***
-      !!                   
-      !! ** Purpose :   initialization of ....
-      !!
-      !! ** Method  :   blah blah blah ...
-      !!
-      !! ** input   :   Namlist namexa
-      !!
-      !! ** Action  :   ...  
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk, jit   ! dummy loop indices
-      INTEGER  ::   ios              ! Local integer output status for namelist read
-      !!
-      NAMELIST/namexa/ exa_v1, exa_v2, nexa_0, sn_ex     
-      !!----------------------------------------------------------------------
-      !
-      REWIND( numnam_ref )              ! Namelist namexa in reference namelist : Example
-      READ  ( numnam_ref, namexa, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namexa in reference namelist' )
-      !
-      REWIND( numnam_cfg )              ! Namelist namexa in configuration namelist : Example
-      READ  ( numnam_cfg, namexa, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namexa in configuration namelist' )
-   ! Output namelist for control
-      WRITE ( numond, namexa )
-      !
-      IF(lwp) THEN                              ! Control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'exa_mpl_init : example '
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namexa : set example parameters'
-         WRITE(numout,*) '      brief desciption               exa_v1  = ', exa_v1
-         WRITE(numout,*) '      brief desciption               exa_v2  = ', exa_v2
-         WRITE(numout,*) '      brief desciption               nexa_0  = ', nexa_0
-         WRITE(numout,*) '      brief desciption          sn_ex%clname = ', sn_ex%clname
-         WRITE(numout,*) '      brief desciption          sn_ex%nfreqh = ', sn_ex%nfreqh
-      ENDIF
-      !
-      !                              ! allocate exa_mpl arrays      
-      IF( exa_mpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'exa_mpl_init : unable to allocate arrays' )
-      !                              ! Parameter control
-      IF( ln_tile .AND. ntile > 0 ) CALL ctl_stop( 'exa_mpl_init: tiling is not supported in this module by default, see manual for how to adapt your code' )
-      IF( ln_opt      )   CALL ctl_stop( 'exa_mpl_init: this work and option xxx are incompatible'   )
-      IF( nn_opt == 2 )   CALL ctl_stop( 'STOP',  'exa_mpl_init: this work and option yyy may cause problems'  )
-      !
-   END SUBROUTINE exa_mpl_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                         NO example
-   !!----------------------------------------------------------------------
-CONTAINS
-   SUBROUTINE exa_mpl( kt, pvar1, pvar2, ptab )              ! Empty routine
-      REAL::   ptab(:,:)
-      WRITE(*,*) 'exa_mpl: You should not have seen this print! error?', kt, pvar1, pvar2, ptab(1,1)
-   END SUBROUTINE exa_mpl
-#endif
-
-   !!======================================================================
-END MODULE exampl
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/module_example.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/module_example.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/module_example.F90	(revision 14062)
@@ -0,0 +1,197 @@
+MODULE exampl
+   !!======================================================================
+   !!                       ***  MODULE  exampl  ***
+   !! Ocean physics:  brief description of the purpose of the module
+   !!                 (please no more than 2 lines)
+   !!======================================================================
+   !! History : 3.0  !  2008-06  (Author Names)  Original code
+   !!            -   !  2008-08  (Author names)  brief description of modifications
+   !!           3.3  !  2010-11  (Author names)        -              -
+   !!----------------------------------------------------------------------
+#if defined key_example
+   !!----------------------------------------------------------------------
+   !!   'key_example'  :                brief description of the key option
+   !!----------------------------------------------------------------------
+   !!   exa_mpl       : list of module subroutine (caution, never use the
+   !!   exa_mpl_init  : name of the module for a routine)
+   !!   exa_mpl_stp   : Please try to use 3 letter block for routine names
+   !!----------------------------------------------------------------------
+   USE module_name1   ! brief description of the used module
+   USE module_name2   ! ....
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   exa_mpl        ! routine called in xxx.F90 module
+   PUBLIC   exa_mpl_init   ! routine called in nemogcm.F90 module
+
+   TYPE ::   FLD_E                !: Structure type definition
+      CHARACTER(lc) ::   clname      ! clname description (default length, lc, is 256, see par_kind.F90)
+      INTEGER       ::   nfreqh      ! nfreqh description 
+   END TYPE FLD_E 
+
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   var1         !: var1 description. CAUTION always use !: to describe
+   !                                                          !  a PUBLIC variable: simplify its search : 
+   !                                                          !  grep var1 *90 | grep '!:'
+   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   var2, var2   !: several variable on a same line OK, but 
+   !                                                          !  DO NOT use continuation lines in declaration
+
+   !                               !!* namelist nam_xxx *
+   LOGICAL   ::   ln_opt = .TRUE.   ! give the default value of each namelist parameter
+   CHARACTER ::   cn_tex = 'T'      ! short description  of the variable
+   INTEGER   ::   nn_opt = 1        ! please respect the DOCTOR norm for namelist variable
+   REAL(wp)  ::   rn_var = 2._wp    ! (it becomes easy to identify them in the code)
+   TYPE(FLD) ::   sn_ex             ! structure
+
+   INTEGER                          ::   nint    ! nint  description (local permanent variable)
+   REAL(wp)                         ::   var     ! var         -                -
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   array   ! array       -                -
+
+   !! * Substitutions
+   ! for DO macro
+#  include "do_loop_substitute.h90"
+   !for other substitutions
+#  include "exampl_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id$ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION exa_mpl_alloc()
+      !!----------------------------------------------------------------------
+      !!                ***  FUNCTION exa_mpl_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE( array(jpi,jpj,jpk) , STAT= exa_mpl_alloc )   ! Module array                                                                
+      !
+      CALL mpp_sum ( 'module_example', exa_mpl_alloc )
+      IF( exa_mpl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'exa_mpl_alloc: failed to allocate arrays' )
+      !
+   END FUNCTION exa_mpl_alloc
+   
+
+   SUBROUTINE exa_mpl( kt, pvar1, pvar2, ptab )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE exa_mpl  ***
+      !!
+      !! ** Purpose :   Brief description of the routine
+      !!
+      !! ** Method  :   description of the methodoloy used to achieve the
+      !!                objectives of the routine. Be as clear as possible!
+      !!
+      !! ** Action  : - first action (share memory array/varible modified
+      !!                in this routine
+      !!              - second action .....
+      !!              - .....
+      !!
+      !! References :   Author et al., Short_name_review, Year
+      !!                Give references if exist otherwise suppress these lines
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                     ::   kt      ! short description 
+      INTEGER , INTENT(inout)                     ::   pvar1   !   -         -
+      REAL(wp), INTENT(  out)                     ::   pvar2   !   -         -
+      REAL(wp), INTENT(  out), DIMENSION(jpi,jpj) ::   pvar2   !   -         -
+      !!
+      INTEGER  ::   ji, jj, jk       ! dummy loop arguments  (DOCTOR : start with j, but not jp)
+      INTEGER  ::   itoto, itata     ! temporary integers    (DOCTOR : start with i
+      REAL(wp) ::   zmlmin, zbbrho   ! temporary scalars     (DOCTOR : start with z)
+      REAL(wp) ::   zfact1, zfact2   ! do not use continuation lines in declaration
+      REAL(wp), DIMENSION(A2D(nn_hls))     ::   zwrk_2d   ! 2D workspace
+      REAL(wp), DIMENSION(A2D(nn_hls),jpk) ::   zwrk_3d   ! 3D workspace
+      !!--------------------------------------------------------------------
+      !
+      IF( ntile == 0 .OR. ntile == 1 )  THEN                       ! Do only on the first tile
+         IF( kt == nit000  )   CALL exa_mpl_init    ! Initialization (first time-step only)
+
+         zmlmin = 1.e-8                             ! Local constant initialization
+         zbbrho =  .5 * ebb / rho0
+         zfact1 = -.5 * rdt * efave
+         zfact2 = 1.5 * rdt * ediss
+      ENDIF
+	  
+      SELECT CASE ( npdl )                       ! short description of the action
+      !
+      CASE ( 0 )                                      ! describe case 1
+         DO_3D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1, 1, jpkm1 )
+            avm(ji,jj,jk) = ....
+         END_3D
+         !
+      CASE ( 1 )                                      ! describe case 2
+         DO_3D( nn_hls-1, nn_hls-1, nn_hls-1, nn_hls-1, 1, jpkm1 )
+            avm(ji,jj,jk) = ....
+         END_3D
+         !
+      END SELECT
+      !
+      ! WARNING! the lbc_lnk call could not be compatible with the tiling approach
+      ! please refer to the manual for how to adapt your code
+      CALL lbc_lnk( 'module_example', avm, 'T', 1., ncsten=true )     ! Lateral boundary conditions (unchanged sign)
+      !                                                                ! ncsten=false for 5-points stencil communication
+      !                                                                ! ncsten=true (default)  for 9-points stencil communication
+      !
+   END SUBROUTINE exa_mpl
+
+
+   SUBROUTINE exa_mpl_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE exa_mpl_init  ***
+      !!                   
+      !! ** Purpose :   initialization of ....
+      !!
+      !! ** Method  :   blah blah blah ...
+      !!
+      !! ** input   :   Namlist namexa
+      !!
+      !! ** Action  :   ...  
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj, jk, jit   ! dummy loop indices
+      INTEGER  ::   ios              ! Local integer output status for namelist read
+      !!
+      NAMELIST/namexa/ exa_v1, exa_v2, nexa_0, sn_ex     
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist namexa in reference namelist : Example
+      READ  ( numnam_ref, namexa, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namexa in reference namelist' )
+      !
+      REWIND( numnam_cfg )              ! Namelist namexa in configuration namelist : Example
+      READ  ( numnam_cfg, namexa, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 ) CALL ctl_nam ( ios , 'namexa in configuration namelist' )
+   ! Output namelist for control
+      WRITE ( numond, namexa )
+      !
+      IF(lwp) THEN                              ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'exa_mpl_init : example '
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namexa : set example parameters'
+         WRITE(numout,*) '      brief desciption               exa_v1  = ', exa_v1
+         WRITE(numout,*) '      brief desciption               exa_v2  = ', exa_v2
+         WRITE(numout,*) '      brief desciption               nexa_0  = ', nexa_0
+         WRITE(numout,*) '      brief desciption          sn_ex%clname = ', sn_ex%clname
+         WRITE(numout,*) '      brief desciption          sn_ex%nfreqh = ', sn_ex%nfreqh
+      ENDIF
+      !
+      !                              ! allocate exa_mpl arrays      
+      IF( exa_mpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'exa_mpl_init : unable to allocate arrays' )
+      !                              ! Parameter control
+      IF( ln_tile .AND. ntile > 0 ) CALL ctl_stop( 'exa_mpl_init: tiling is not supported in this module by default, see manual for how to adapt your code' )
+      IF( ln_opt      )   CALL ctl_stop( 'exa_mpl_init: this work and option xxx are incompatible'   )
+      IF( nn_opt == 2 )   CALL ctl_stop( 'STOP',  'exa_mpl_init: this work and option yyy may cause problems'  )
+      !
+   END SUBROUTINE exa_mpl_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                         NO example
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE exa_mpl( kt, pvar1, pvar2, ptab )              ! Empty routine
+      REAL::   ptab(:,:)
+      WRITE(*,*) 'exa_mpl: You should not have seen this print! error?', kt, pvar1, pvar2, ptab(1,1)
+   END SUBROUTINE exa_mpl
+#endif
+
+   !!======================================================================
+END MODULE exampl
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/nemogcm.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/nemogcm.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/nemogcm.F90	(revision 14062)
@@ -42,61 +42,39 @@
    !!----------------------------------------------------------------------
    USE step_oce       ! module used in the ocean time stepping module (step.F90)
+   !
    USE phycst         ! physical constant                  (par_cst routine)
    USE domain         ! domain initialization   (dom_init & dom_cfg routines)
-   USE closea         ! treatment of closed seas (for ln_closea)
-   USE usrdef_nam     ! user defined configuration
-   USE tide_mod, ONLY : tide_init ! tidal components initialization   (tide_init routine)
-   USE bdyini         ! open boundary cond. setting       (bdy_init routine)
+   USE wet_dry        ! Wetting and drying setting   (wad_init routine)
+   USE usrdef_nam     ! user defined configuration namelist
+   USE tide_mod, ONLY : tide_init   ! tidal components initialization   (tide_init routine)
+   USE bdyini  , ONLY : bdy_init    ! open boundary cond. setting       (bdy_init routine)
    USE istate         ! initial state setting          (istate_init routine)
-   USE ldfdyn         ! lateral viscosity setting      (ldfdyn_init routine)
-   USE ldftra         ! lateral diffusivity setting    (ldftra_init routine)
    USE trdini         ! dyn/tra trends initialization     (trd_init routine)
-   USE asminc         ! assimilation increments     
-   USE asmbkg         ! writing out state trajectory
-   USE diadct         ! sections transports           (dia_dct_init routine)
-   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
-   USE diacfl         ! CFL diagnostics               (dia_cfl_init routine)
-   USE diamlr         ! IOM context management for multiple-linear-regression analysis
+   USE icbini         ! handle bergs, initialisation
+   USE icbstp  , ONLY : icb_end     ! handle bergs, close iceberg files
+   USE cpl_oasis3     ! OASIS3 coupling
+   USE dyndmp         ! Momentum damping (C1D only)
+   USE step_diu       ! diurnal bulk SST timestepping (called from here if run offline)
+   USE crsini         ! initialise grid coarsening utility
+   USE dia25h  , ONLY : dia_25h_init   ! 25h mean output (initialisation)
+   USE c1d            ! 1D configuration
+   USE step_c1d       ! Time stepping loop for the 1D configuration
+#if defined key_top
+   USE trcini         ! passive tracer initialisation
+#endif
+#if defined key_nemocice_decomp
+   USE ice_domain_size, only: nx_global, ny_global
+#endif
 #if defined key_qco
-   USE stepMLF        ! NEMO time-stepping               (stp_MLF   routine)
+   USE stpmlf         ! NEMO time-stepping               (stp_MLF   routine)
 #else
    USE step           ! NEMO time-stepping                 (stp     routine)
 #endif
-   USE isfstp         ! ice shelf                     (isf_stp_init routine)
-   USE icbini         ! handle bergs, initialisation
-   USE icbstp         ! handle bergs, calving, themodynamics and transport
-   USE cpl_oasis3     ! OASIS3 coupling
-   USE c1d            ! 1D configuration
-   USE step_c1d       ! Time stepping loop for the 1D configuration
-   USE dyndmp         ! Momentum damping
-   USE stopar         ! Stochastic param.: ???
-   USE stopts         ! Stochastic param.: ???
-   USE diu_layers     ! diurnal bulk SST and coolskin
-   USE step_diu       ! diurnal bulk SST timestepping (called from here if run offline)
-   USE crsini         ! initialise grid coarsening utility
-   USE dia25h         ! 25h mean output
-   USE diadetide      ! Weights computation for daily detiding of model diagnostics
-   USE sbc_oce , ONLY : lk_oasis
-   USE wet_dry        ! Wetting and drying setting   (wad_init routine)
-#if defined key_top
-   USE trcini         ! passive tracer initialisation
-#endif
-#if defined key_nemocice_decomp
-   USE ice_domain_size, only: nx_global, ny_global
-#endif
    !
-   USE prtctl         ! Print control
-   USE in_out_manager ! I/O manager
    USE lib_mpp        ! distributed memory computing
    USE mppini         ! shared/distributed memory setting (mpp_init routine)
    USE lbcnfd  , ONLY : isendto, nsndto  ! Setup of north fold exchanges 
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-#if defined key_iomput
-   USE xios           ! xIOserver
-#endif
-#if defined key_agrif
-   USE agrif_all_update   ! Master Agrif update
-#endif
-   USE halo_mng
+   USE halo_mng       ! Halo manager
 
    IMPLICIT NONE
@@ -182,9 +160,9 @@
       !
       DO WHILE( istp <= nitend .AND. nstop == 0 )
-#if defined key_qco
+#  if defined key_qco
          CALL stp_MLF
-#else
+#  else
          CALL stp
-#endif
+#  endif
          istp = istp + 1
       END DO
@@ -195,5 +173,5 @@
          !
          DO WHILE( istp <= nitend .AND. nstop == 0 )
-
+            !
             ncom_stp = istp
             IF( ln_timing ) THEN
@@ -202,14 +180,14 @@
                IF ( istp ==         nitend ) elapsed_time = zstptiming - elapsed_time
             ENDIF
-            
-#if defined key_qco
+            !
+#  if defined key_qco
             CALL stp_MLF      ( istp )
-#else
+#  else
             CALL stp        ( istp ) 
-#endif
+#  endif
             istp = istp + 1
-
+            !
             IF( lwp .AND. ln_timing )   WRITE(numtime,*) 'timing step ', istp-1, ' : ', MPI_Wtime() - zstptiming
-
+            !
          END DO
          !
@@ -279,6 +257,6 @@
       INTEGER ::   ios, ilocal_comm   ! local integers
       !!
-      NAMELIST/namctl/ sn_cfctl, ln_timing, ln_diacfl,                                &
-         &             nn_isplt,  nn_jsplt,  nn_ictls, nn_ictle, nn_jctls, nn_jctle            
+      NAMELIST/namctl/ sn_cfctl, ln_timing, ln_diacfl, nn_isplt, nn_jsplt , nn_ictls,   &
+         &                                             nn_ictle, nn_jctls , nn_jctle
       NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
       !!----------------------------------------------------------------------
@@ -350,5 +328,5 @@
       IF(lwp) THEN                      ! open listing units
          !
-         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
+         IF( .NOT.lwm )   &            ! alreay opened for narea == 1
             &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
          !
@@ -357,5 +335,5 @@
          WRITE(numout,*) '                       NEMO team'
          WRITE(numout,*) '            Ocean General Circulation Model'
-         WRITE(numout,*) '                NEMO version 4.0  (2019) '
+         WRITE(numout,*) '                NEMO version 4.0  (2020) '
          WRITE(numout,*)
          WRITE(numout,*) "           ._      ._      ._      ._      ._    "
@@ -373,14 +351,14 @@
          WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
          WRITE(numout,*)
-         
-         ! Print the working precision to ocean.output
-         IF (wp == dp) THEN
-            WRITE(numout,*) "Working precision = double-precision"
-         ELSE
-            WRITE(numout,*) "Working precision = single-precision"
+         !
+         WRITE(numout,cform_aaa)    ! Flag AAAAAAA
+         !
+         !                          ! Control print of the working precision
+         WRITE(numout,*)
+         IF( wp == dp ) THEN   ;   WRITE(numout,*) "par_kind : wp = Working precision = dp = double-precision"
+         ELSE                  ;   WRITE(numout,*) "par_kind : wp = Working precision = sp = single-precision"
          ENDIF
-         WRITE(numout,*)
-         !
-         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
+                                   WRITE(numout,*) "~~~~~~~~                                 ****************"
+                                   WRITE(numout,*)
          !
       ENDIF
@@ -415,7 +393,7 @@
 
       ! Initialise time level indices
-      Nbb = 1; Nnn = 2; Naa = 3; Nrhs = Naa
+      Nbb = 1   ;   Nnn = 2   ;   Naa = 3   ;   Nrhs = Naa
 #if defined key_agrif
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+      Kbb_a = Nbb   ;   Kmm_a = Nnn   ;   Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
 #endif 
       !                             !-------------------------------!
@@ -423,5 +401,5 @@
       !                             !-------------------------------!
 
-      CALL nemo_ctl                          ! Control prints
+      CALL nemo_ctl                          ! Control prints of namctl and namcfg
       !
       !                                      ! General initialization
@@ -437,6 +415,6 @@
      CALL Agrif_Declare_Var_ini   !  "      "   "   "      "  DOM
 #endif
-                           CALL     dom_init( Nbb, Nnn, Naa ) ! Domain
-      IF( ln_crs       )   CALL     crs_init(      Nnn )       ! coarsened grid: domain initialization 
+                           CALL     dom_init( Nbb, Nnn, Naa )   ! Domain
+      IF( ln_crs       )   CALL     crs_init(      Nnn      )   ! coarsened grid: domain initialization 
       IF( sn_cfctl%l_prtctl )   &
          &                 CALL prt_ctl_init        ! Print control
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/oce.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/oce.F90	(revision 14062)
@@ -16,5 +16,6 @@
    PRIVATE
 
-   PUBLIC oce_alloc ! routine called by nemo_init in nemogcm.F90
+   PUBLIC oce_alloc       ! routine called by nemo_init in     nemogcm.F90
+   PUBLIC oce_SWE_alloc   ! routine called by nemo_init in SWE/nemogcm.F90 (Shallow Water Eq. case)
 
    !! dynamics and tracer fields
@@ -66,4 +67,11 @@
    INTEGER, PUBLIC, DIMENSION(2) :: noce_array                             !: unused array but seems to be needed to prevent agrif from creating an empty module
 
+   !! Shallow Water Eq. case (SWE)
+   LOGICAL, PUBLIC ::   lk_SWE = .FALSE.                                   !: shallow water flag =T in SWE configurations only
+
+   !! Stand-Alone Surface module (SAS)
+   LOGICAL, PUBLIC ::   l_SAS = .FALSE.                                    !: SAS flag =T in SAS configurations only
+   
+   
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -112,4 +120,26 @@
    END FUNCTION oce_alloc
 
+
+   INTEGER FUNCTION oce_SWE_alloc()
+      !!----------------------------------------------------------------------
+      !!                   ***  FUNCTION oce_SWE_alloc  ***
+      !!----------------------------------------------------------------------
+      INTEGER :: ierr(2)
+      !!----------------------------------------------------------------------
+      !
+      lk_SWE  = .TRUE.                   ! =T SWE case 
+      !
+      ierr(:) = 0 
+      ALLOCATE( uu(jpi,jpj,jpk,jpt) , vv  (jpi,jpj,jpk,jpt) ,     &          
+         &      ww(jpi,jpj,jpk)     , hdiv(jpi,jpj,jpk)     , ssh(jpi,jpj,jpt) , STAT=ierr(1) )
+         !
+      ALLOCATE(   ts(jpi,jpj,jpk,jpts,jpt) , fraqsr_1lev(jpi,jpj) ,  &
+         &      uu_b(jpi,jpj,jpt) , vv_b(jpi,jpj,jpt)       , rn2(jpi,jpj,jpk) , STAT=ierr(2) )
+         !
+      oce_SWE_alloc = MAXVAL( ierr )
+      IF( oce_SWE_alloc /= 0 )   CALL ctl_stop( 'STOP', 'oce_SWE_alloc: failed to allocate arrays' )
+      !
+   END FUNCTION oce_SWE_alloc
+
    !!======================================================================
 END MODULE oce
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/step.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/step.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/step.F90	(revision 14062)
@@ -42,6 +42,4 @@
    !!----------------------------------------------------------------------
    USE step_oce         ! time stepping definition modules
-   !
-   USE iom              ! xIOs server
 
    IMPLICIT NONE
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/step_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/step_oce.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/step_oce.F90	(revision 14062)
@@ -3,4 +3,5 @@
    !!                       ***  MODULE step_oce  ***
    !! Ocean time-stepping : module used in both initialisation phase and time stepping
+   !!                                     (i.e. nemo_init and stp or stp_MLF routines)
    !!======================================================================
    !! History :   3.3  !  2010-08  (C. Ethe)  Original code - reorganisation of the initial phase
@@ -9,7 +10,5 @@
    USE oce             ! ocean dynamics and tracers variables
    USE dom_oce         ! ocean space and time domain variables
-   USE domain, ONLY : dom_tile
-   USE zdf_oce         ! ocean vertical physics variables
-   USE zdfdrg  ,  ONLY : ln_drgimp   ! implicit top/bottom friction
+   USE domain  ,  ONLY : dom_tile
 
    USE daymod          ! calendar                         (day     routine)
@@ -20,9 +19,29 @@
    USE sbccpl          ! surface boundary condition: coupled formulation (call send at end of step)
    USE sbcapr          ! surface boundary condition: atmospheric pressure
-   USE tide_mod, ONLY : ln_tide, tide_update
    USE sbcwave         ! Wave intialisation
+   USE tide_mod        ! tides
+
+   USE bdy_oce  , ONLY : ln_bdy
+   USE bdydta          ! open boundary condition data     (bdy_dta routine)
+   USE bdytra          ! bdy cond. for tracers            (bdy_tra routine)
+   USE bdydyn3d        ! bdy cond. for baroclinic vel.  (bdy_dyn3d routine)
 
    USE isf_oce         ! ice shelf boundary condition
    USE isfstp          ! ice shelf boundary condition     (isf_stp routine)
+
+   USE sshwzv          ! vertical velocity and ssh        (ssh_nxt routine)
+   !                                                      (ssh_swp routine)
+   !                                                      (wzv     routine)
+   USE domvvl          ! variable vertical scale factors  (dom_vvl_sf_nxt routine)
+   !                                                      (dom_vvl_sf_swp routine)
+   
+   USE divhor          ! horizontal divergence            (div_hor routine)
+   USE dynadv          ! advection                        (dyn_adv routine)
+   USE dynvor          ! vorticity term                   (dyn_vor routine)
+   USE dynhpg          ! hydrostatic pressure grad.       (dyn_hpg routine)
+   USE dynldf          ! lateral momentum diffusion       (dyn_ldf routine)
+   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
+   USE dynspg          ! surface pressure gradient        (dyn_spg routine)
+   USE dynatf          ! time-filtering                   (dyn_atf routine)
 
    USE traqsr          ! solar radiation penetration      (tra_qsr routine)
@@ -40,27 +59,6 @@
    USE eosbn2          ! equation of state                (eos_bn2 routine)
 
-   USE divhor          ! horizontal divergence            (div_hor routine)
-   USE dynadv          ! advection                        (dyn_adv routine)
-   USE dynvor          ! vorticity term                   (dyn_vor routine)
-   USE dynhpg          ! hydrostatic pressure grad.       (dyn_hpg routine)
-   USE dynldf          ! lateral momentum diffusion       (dyn_ldf routine)
-   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
-   USE dynspg          ! surface pressure gradient        (dyn_spg routine)
-
-   USE dynatf          ! time-filtering                   (dyn_atf routine)
-
    USE stopar          ! Stochastic parametrization       (sto_par routine)
    USE stopts 
-
-   USE bdy_oce  , ONLY : ln_bdy
-   USE bdydta          ! open boundary condition data     (bdy_dta routine)
-   USE bdytra          ! bdy cond. for tracers            (bdy_tra routine)
-   USE bdydyn3d        ! bdy cond. for baroclinic vel.  (bdy_dyn3d routine)
-
-   USE sshwzv          ! vertical velocity and ssh        (ssh_nxt routine)
-   !                                                       (ssh_swp routine)
-   !                                                       (wzv     routine)
-   USE domvvl          ! variable vertical scale factors  (dom_vvl_sf_nxt routine)
-   !                                                       (dom_vvl_sf_swp routine)
 
    USE ldfslp          ! iso-neutral slopes               (ldf_slp routine)
@@ -68,6 +66,8 @@
    USE ldftra          ! lateral eddy diffusive coef.     (ldf_tra routine)
 
+   USE zdf_oce         ! ocean vertical physics variables
    USE zdfphy          ! vertical physics manager      (zdf_phy_init routine)
-   USE zdfosm  , ONLY : osm_rst, dyn_osm, tra_osm      ! OSMOSIS routines used in step.F90
+   USE zdfdrg   , ONLY : ln_drgimp   ! implicit top/bottom friction
+   USE zdfosm   , ONLY : osm_rst, dyn_osm, tra_osm      ! OSMOSIS routines used in step.F90
    USE zdfmfc          ! Mass FLux Convection routine used in step.F90
 
@@ -83,6 +83,6 @@
    USE diahth          ! thermocline depth                (dia_hth routine)
    USE diahsb          ! heat, salt and volume budgets    (dia_hsb routine)
-   USE diacfl
-   USE diaobs          ! Observation operator
+   USE diacfl          ! CFL diagnostics                  (dia_cfl routine)
+   USE diaobs          ! Observation operator             (dia_obs routine)
    USE diadetide       ! Weights computation for daily detiding of model diagnostics
    USE diamlr          ! IOM context management for multiple-linear-regression analysis
@@ -94,5 +94,5 @@
    USE asminc          ! assimilation increments      (tra_asm_inc routine)
    !                                                   (dyn_asm_inc routine)
-   USE asmbkg
+   USE asmbkg          ! writing out state trajectory
    USE stpctl          ! time stepping control            (stp_ctl routine)
    USE restart         ! ocean restart                    (rst_wri routine)
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpMLF.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpMLF.F90	(revision 14059)
+++ 	(revision )
@@ -1,473 +1,0 @@
-MODULE stepMLF
-   !!======================================================================
-   !!                       ***  MODULE step  ***
-   !! Time-stepping   : manager of the ocean, tracer and ice time stepping
-   !!======================================================================
-   !! History :  OPA  !  1991-03  (G. Madec)  Original code
-   !!             -   !  1991-11  (G. Madec)
-   !!             -   !  1992-06  (M. Imbard)  add a first output record
-   !!             -   !  1996-04  (G. Madec)  introduction of dynspg
-   !!             -   !  1996-04  (M.A. Foujols)  introduction of passive tracer
-   !!            8.0  !  1997-06  (G. Madec)  new architecture of call
-   !!            8.2  !  1997-06  (G. Madec, M. Imbard, G. Roullet)  free surface
-   !!             -   !  1999-02  (G. Madec, N. Grima)  hpg implicit
-   !!             -   !  2000-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
-   !!   NEMO     1.0  !  2002-06  (G. Madec)  free form, suppress macro-tasking
-   !!             -   !  2004-08  (C. Talandier) New trends organization
-   !!             -   !  2005-01  (C. Ethe) Add the KPP closure scheme
-   !!             -   !  2005-11  (G. Madec)  Reorganisation of tra and dyn calls
-   !!             -   !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
-   !!             -   !  2006-07  (S. Masson)  restart using iom
-   !!            3.2  !  2009-02  (G. Madec, R. Benshila)  reintroduicing z*-coordinate
-   !!             -   !  2009-06  (S. Masson, G. Madec)  TKE restart compatible with key_cpl
-   !!            3.3  !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
-   !!             -   !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
-   !!            3.4  !  2011-04  (G. Madec, C. Ethe) Merge of dtatem and dtasal
-   !!            3.6  !  2012-07  (J. Simeon, G. Madec. C. Ethe)  Online coarsening of outputs
-   !!            3.6  !  2014-04  (F. Roquet, G. Madec) New equations of state
-   !!            3.6  !  2014-10  (E. Clementi, P. Oddo) Add Qiao vertical mixing in case of waves
-   !!            3.7  !  2014-10  (G. Madec)  LDF simplication
-   !!             -   !  2014-12  (G. Madec) remove KPP scheme
-   !!             -   !  2015-11  (J. Chanut) free surface simplification (remove filtered free surface)
-   !!            4.0  !  2017-05  (G. Madec)  introduction of the vertical physics manager (zdfphy)
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rewrite in preparation for new timestepping scheme
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   stp_MLF       : OPA system time-stepping
-   !!----------------------------------------------------------------------
-   USE step_oce       ! time stepping definition modules
-   !
-   USE iom            ! xIOs server
-   USE domqco
-   USE traatfqco      ! time filtering                   (tra_atf_qco routine)
-   USE dynatfqco      ! time filtering                   (dyn_atf_qco routine)
-   USE dynspg_ts      ! surface pressure gradient: split-explicit scheme (define un_adv)
-   USE bdydyn         ! ocean open boundary conditions (define bdy_dyn)
-
-   IMPLICIT NONE
-   PRIVATE
-   
-#if ! defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-#else
-   PUBLIC   stp_MLF   ! called by nemogcm.F90
-
-   !!----------------------------------------------------------------------
-   !! time level indices
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC :: Nbb, Nnn, Naa, Nrhs          !! used by nemo_init
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: step.F90 12377 2020-02-12 14:39:06Z acc $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_agrif
-   RECURSIVE SUBROUTINE stp_MLF( )
-      INTEGER             ::   kstp   ! ocean time-step index
-#else
-   SUBROUTINE stp_MLF( kstp )
-      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
-#endif
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE stp_MLF  ***
-      !!
-      !! ** Purpose : - Time stepping of OPA  (momentum and active tracer eqs.)
-      !!              - Time stepping of SI3 (dynamic and thermodynamic eqs.)
-      !!              - Time stepping of TRC  (passive tracer eqs.)
-      !!
-      !! ** Method  : -1- Update forcings and data
-      !!              -2- Update ocean physics
-      !!              -3- Compute the t and s trends
-      !!              -4- Update t and s
-      !!              -5- Compute the momentum trends
-      !!              -6- Update the horizontal velocity
-      !!              -7- Compute the diagnostics variables (rd,N2, hdiv,w)
-      !!              -8- Outputs and diagnostics
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indice
-      INTEGER ::   indic        ! error indicator if < 0
-!!gm kcall can be removed, I guess
-      INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
-!!st patch
-      REAL(wp),              DIMENSION(jpi,jpj,jpk) ::   zgdept
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:)         ::   zssh_f
-      !! ---------------------------------------------------------------------
-#if defined key_agrif
-      kstp = nit000 + Agrif_Nb_Step()
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      IF( lk_agrif_debug ) THEN
-         IF( Agrif_Root() .and. lwp)   WRITE(*,*) '---'
-         IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
-      ENDIF
-      IF( kstp == nit000 + 1 )   lk_agrif_fstep = .FALSE.
-# if defined key_iomput
-      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
-# endif
-#endif
-      !
-      IF( ln_timing )   CALL timing_start('stp_MLF')
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! model timestep
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !
-      IF( l_1st_euler ) THEN  
-         ! start or restart with Euler 1st time-step
-         rDt =  rn_Dt   
-         r1_Dt = 1._wp / rDt
-      ENDIF
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
-      ! update I/O and calendar
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             indic = 0                ! reset to no error condition
-
-      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
-                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
-         IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
-                             CALL iom_init_closedef
-         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
-      ENDIF
-      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
-                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
-      IF( ln_crs         )   CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" )   ! tell IOM we are at time step kstp
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update external forcing (tides, open boundaries, ice shelf interaction and surface boundary condition (including sea-ice)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_tide    )   CALL tide_update( kstp )                     ! update tide potential
-      IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                        ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib)
-      IF( ln_bdy     )   CALL bdy_dta ( kstp, Nnn )                   ! update dynamic & tracer data at open boundaries
-      IF( ln_isf     )   CALL isf_stp ( kstp, Nnn )
-                         CALL sbc     ( kstp, Nbb, Nnn )              ! Sea Boundary Condition (including sea-ice)
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update stochastic parameters and random T/S fluctuations
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      IF( ln_sto_eos ) CALL sto_par( kstp )          ! Stochastic parameters
-      IF( ln_sto_eos ) CALL sto_pts( ts(:,:,:,:,Nnn)  )          ! Random T/S fluctuations
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !  THERMODYNAMICS
-                         CALL eos_rab( ts(:,:,:,:,Nbb), rab_b, Nnn )       ! before local thermal/haline expension ratio at T-points
-                         CALL eos_rab( ts(:,:,:,:,Nnn), rab_n, Nnn )       ! now    local thermal/haline expension ratio at T-points
-                         CALL bn2    ( ts(:,:,:,:,Nbb), rab_b, rn2b, Nnn ) ! before Brunt-Vaisala frequency
-                         CALL bn2    ( ts(:,:,:,:,Nnn), rab_n, rn2, Nnn  ) ! now    Brunt-Vaisala frequency
-
-      !  VERTICAL PHYSICS
-                         CALL zdf_phy( kstp, Nbb, Nnn, Nrhs )   ! vertical physics update (top/bot drag, avt, avs, avm + MLD)
-
-      !  LATERAL  PHYSICS
-      !
-      IF( l_ldfslp ) THEN                             ! slope of lateral mixing
-                         CALL eos( ts(:,:,:,:,Nbb), rhd, gdept_0(:,:,:) )               ! before in situ density
-
-         IF( ln_zps .AND. .NOT. ln_isfcav)                                    &
-            &            CALL zps_hde    ( kstp, Nnn, jpts, ts(:,:,:,:,Nbb), gtsu, gtsv,  &  ! Partial steps: before horizontal gradient
-            &                                          rhd, gru , grv    )       ! of t, s, rd at the last ocean level
-
-         IF( ln_zps .AND.       ln_isfcav)                                                &
-            &            CALL zps_hde_isf( kstp, Nnn, jpts, ts(:,:,:,:,Nbb), gtsu, gtsv, gtui, gtvi,  &  ! Partial steps for top cell (ISF)
-            &                                          rhd, gru , grv , grui, grvi   )       ! of t, s, rd at the first ocean level
-         IF( ln_traldf_triad ) THEN
-                         CALL ldf_slp_triad( kstp, Nbb, Nnn )             ! before slope for triad operator
-         ELSE
-                         CALL ldf_slp     ( kstp, rhd, rn2b, Nbb, Nnn )   ! before slope for standard operator
-         ENDIF
-      ENDIF
-      !                                                                        ! eddy diffusivity coeff.
-      IF( l_ldftra_time .OR. l_ldfeiv_time )   CALL ldf_tra( kstp, Nbb, Nnn )  !       and/or eiv coeff.
-      IF( l_ldfdyn_time                    )   CALL ldf_dyn( kstp, Nbb )       ! eddy viscosity coeff.
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  Ocean dynamics : hdiv, ssh, e3, u, v, w
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      DO jk = 1, jpk
-         zgdept(:,:,jk) = gdept(:,:,jk,Nnn)
-      END DO
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh,  Naa )   ! after ssh (includes call to div_hor)
-      IF( .NOT.ln_linssh )  CALL dom_qco_r3c    ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa) )   ! "after" ssh./h._0 ratio
-                            CALL wzv           ( kstp, Nbb, Nnn, Naa, ww  )    ! Nnn cross-level velocity
-      IF( ln_zad_Aimp )     CALL wAimp         ( kstp,      Nnn           )    ! Adaptive-implicit vertical advection partitioning
-                            CALL eos    ( ts(:,:,:,:,Nnn), rhd, rhop, zgdept ) ! now in situ density for hpg computation
-
-
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-      IF(  lk_asminc .AND. ln_asmiau .AND. ln_dyninc )   &
-               &         CALL dyn_asm_inc   ( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! apply dynamics assimilation increment
-      IF( ln_bdy     )   CALL bdy_dyn3d_dmp ( kstp, Nbb,      uu, vv, Nrhs )  ! bdy damping trends
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())  &
-               &         CALL Agrif_Sponge_dyn        ! momentum sponge
-#endif
-                         CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
-                         CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
-                         CALL dyn_ldf( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! lateral mixing
-      IF( ln_zdfosm  )   CALL dyn_osm( kstp,      Nnn      , uu, vv, Nrhs )  ! OSMOSIS non-local velocity fluxes ==> RHS
-                         CALL dyn_hpg( kstp,      Nnn      , uu, vv, Nrhs )  ! horizontal gradient of Hydrostatic pressure
-                         CALL dyn_spg( kstp, Nbb, Nnn, Nrhs, uu, vv, ssh, uu_b, vv_b, Naa )  ! surface pressure gradient
-
-                                                      ! With split-explicit free surface, since now transports have been updated and ssh(:,:,Nrhs) as well
-      IF( ln_dynspg_ts ) THEN                         ! vertical scale factors and vertical velocity need to be updated
-                            CALL div_hor    ( kstp, Nbb, Nnn )                ! Horizontal divergence  (2nd call in time-split case)
-         IF(.NOT.ln_linssh) CALL dom_qco_r3c ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio
-      ENDIF
-                            CALL dyn_zdf    ( kstp, Nbb, Nnn, Nrhs, uu, vv, Naa  )  ! vertical diffusion
-      IF( ln_dynspg_ts ) THEN                                                       ! vertical scale factors and vertical velocity need to be updated
-                            CALL wzv        ( kstp, Nbb, Nnn, Naa, ww )             ! Nnn cross-level velocity
-         IF( ln_zad_Aimp )  CALL wAimp      ( kstp,      Nnn )                      ! Adaptive-implicit vertical advection partitioning
-      ENDIF
-
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! cool skin
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF ( ln_diurnal )  CALL diurnal_layers( kstp )
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_floats  )   CALL flo_stp   ( kstp, Nbb, Nnn )      ! drifting Floats
-      IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
-                         CALL dia_hth   ( kstp,      Nnn )      ! Thermocline depth (20 degres isotherm depth)
-      IF( ln_diadct  )   CALL dia_dct   ( kstp,      Nnn )      ! Transports
-                         CALL dia_ar5   ( kstp,      Nnn )      ! ar5 diag
-                         CALL dia_ptr   ( kstp,      Nnn )      ! Poleward adv/ldf TRansports diagnostics
-                         CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
-      IF( ln_crs     )   CALL crs_fld   ( kstp,      Nnn )      ! ocean model: online field coarsening & output
-      IF( lk_diadetide ) CALL dia_detide( kstp )                ! Weights computation for daily detiding of model diagnostics
-      IF( lk_diamlr  )   CALL dia_mlr                           ! Update time used in multiple-linear-regression analysis
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Now ssh filtering
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL ssh_atf    ( kstp, Nbb, Nnn, Naa, ssh )            ! time filtering of "now" sea surface height
-                         CALL dom_qco_r3c( ssh(:,:,Nnn), r3t_f, r3u_f, r3v_f )   ! "now" ssh/h_0 ratio from filtrered ssh
-#if defined key_top
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Passive Tracer Model
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL trc_stp    ( kstp, Nbb, Nnn, Nrhs, Naa )           ! time-stepping
-#endif
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Active tracers
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         ts(:,:,:,:,Nrhs) = 0._wp         ! set tracer trends to zero
-
-      IF(  lk_asminc .AND. ln_asmiau .AND. &
-         & ln_trainc )   CALL tra_asm_inc( kstp, Nbb, Nnn, ts, Nrhs )  ! apply tracer assimilation increment
-                         CALL tra_sbc    ( kstp,      Nnn, ts, Nrhs )  ! surface boundary condition
-      IF( ln_traqsr  )   CALL tra_qsr    ( kstp,      Nnn, ts, Nrhs )  ! penetrative solar radiation qsr
-      IF( ln_isf     )   CALL tra_isf    ( kstp,      Nnn, ts, Nrhs )  ! ice shelf heat flux
-      IF( ln_trabbc  )   CALL tra_bbc    ( kstp,      Nnn, ts, Nrhs )  ! bottom heat flux
-      IF( ln_trabbl  )   CALL tra_bbl    ( kstp, Nbb, Nnn, ts, Nrhs )  ! advective (and/or diffusive) bottom boundary layer scheme
-      IF( ln_tradmp  )   CALL tra_dmp    ( kstp, Nbb, Nnn, ts, Nrhs )  ! internal damping trends
-      IF( ln_bdy     )   CALL bdy_tra_dmp( kstp, Nbb,      ts, Nrhs )  ! bdy damping trends
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())  &
-               &         CALL Agrif_Sponge_tra        ! tracers sponge
-#endif
-                         CALL tra_adv    ( kstp, Nbb, Nnn, ts, Nrhs )  ! hor. + vert. advection	==> RHS
-      IF( ln_zdfosm  )   CALL tra_osm    ( kstp,      Nnn, ts, Nrhs )  ! OSMOSIS non-local tracer fluxes ==> RHS
-      IF( lrst_oce .AND. ln_zdfosm ) &
-           &             CALL osm_rst    ( kstp,      Nnn, 'WRITE'  )  ! write OSMOSIS outputs + ww (so must do here) to restarts
-                         CALL tra_ldf    ( kstp, Nbb, Nnn, ts, Nrhs )  ! lateral mixing
-
-                         CALL tra_zdf    ( kstp, Nbb, Nnn, Nrhs, ts, Naa  )  ! vertical mixing and after tracer fields
-      IF( ln_zdfnpc  )   CALL tra_npc    ( kstp,      Nnn, Nrhs, ts, Naa  )  ! update after fields by non-penetrative convection
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Set boundary conditions, time filter and swap time levels
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-!!jc1: For agrif, it would be much better to finalize tracers/momentum here (e.g. bdy conditions) and move the swap
-!!    (and time filtering) after Agrif update. Then restart would be done after and would contain updated fields.
-!!    If so:
-!!    (i) no need to call agrif update at initialization time
-!!    (ii) no need to update "before" fields
-!!
-!!    Apart from creating new tra_swp/dyn_swp routines, this however:
-!!    (i) makes boundary conditions at initialization time computed from updated fields which is not the case between
-!!    two restarts => restartability issue. One can circumvent this, maybe, by assuming "interface separation",
-!!    e.g. a shift of the feedback interface inside child domain.
-!!    (ii) requires that all restart outputs of updated variables by agrif (e.g. passive tracers/tke/barotropic arrays) are done at the same
-!!    place.
-!!
-                         CALL mlf_baro_corr ( Nnn, Naa, uu, vv )                    ! barotrope ajustment
-                         CALL finalize_sbc  ( kstp, Nbb, Naa, uu, vv, ts )          ! boundary condifions
-                         CALL tra_atf_qco   ( kstp, Nbb, Nnn, Naa, ts )             ! time filtering of "now" tracer arrays
-                         CALL dyn_atf_qco   ( kstp, Nbb, Nnn, Naa, uu, vv  )        ! time filtering of "now" velocities and scale factors
-                         r3t(:,:,Nnn) = r3t_f(:,:)
-                         r3u(:,:,Nnn) = r3u_f(:,:)
-                         r3v(:,:,Nnn) = r3v_f(:,:)
-
-      !
-      ! Swap time levels
-      Nrhs = Nbb
-      Nbb = Nnn
-      Nnn = Naa
-      Naa = Nrhs
-      !
-      !
-      IF( ln_diahsb  )   CALL dia_hsb       ( kstp, Nbb, Nnn )  ! - ML - global conservation diagnostics
-
-!!gm : This does not only concern the dynamics ==>>> add a new title
-!!gm2: why ouput restart before AGRIF update?
-!!
-!!jc: That would be better, but see comment above
-!!
-      IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
-      IF( ln_sto_eos )   CALL sto_rst_write( kstp )   ! write restart file for stochastic parameters
-
-#if defined key_agrif
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! AGRIF
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs      ! agrif_oce module copies of time level indices
-                         CALL Agrif_Integrate_ChildGrids( stp_MLF )       ! allows to finish all the Child Grids before updating
-
-                         IF( Agrif_NbStepint() == 0 ) THEN
-                            CALL Agrif_update_all( )                  ! Update all components
-                         ENDIF
-#endif
-      IF( ln_diaobs  )   CALL dia_obs      ( kstp, Nnn )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Control
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nbb, Nnn, indic )
-
-      IF( kstp == nit000 ) THEN                          ! 1st time step only
-                                        CALL iom_close( numror )   ! close input  ocean restart file
-         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
-         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
-      ENDIF
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Coupled mode
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-!!gm why lk_oasis and not lk_cpl ????
-      IF( lk_oasis   )   CALL sbc_cpl_snd( kstp, Nbb, Nnn )        ! coupled mode : field exchanges
-      !
-#if defined key_iomput
-      IF( kstp == nitend .OR. indic < 0 ) THEN
-                      CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-         IF(lrxios) CALL iom_context_finalize(      cr_ocerst_cxt          )
-         IF( ln_crs ) CALL iom_context_finalize( trim(cxios_context)//"_crs" ) !
-      ENDIF
-#endif
-      !
-      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
-         rDt = 2._wp * rn_Dt   
-         r1_Dt = 1._wp / rDt
-         l_1st_euler = .FALSE.      
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('stp_MLF')
-      !
-   END SUBROUTINE stp_MLF
-
-
-   SUBROUTINE mlf_baro_corr (Kmm, Kaa, puu, pvv)
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE mlf_baro_corr  ***
-      !!
-      !! ** Purpose :   Finalize after horizontal velocity.
-      !!
-      !! ** Method  : * Ensure after velocities transport matches time splitting
-      !!             estimate (ln_dynspg_ts=T)
-      !!
-      !! ** Action :   puu(Kmm),pvv(Kmm),puu(Kaa),pvv(Kaa)   now and after horizontal velocity
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT(in   ) :: Kmm, Kaa    ! before and after time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: puu, pvv         ! velocities
-      !
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   zue, zve
-      !
-      INTEGER  ::   jk   ! dummy loop indices
-      !!----------------------------------------------------------------------
-
-      IF ( ln_dynspg_ts ) THEN
-         ALLOCATE( zue(jpi,jpj)     , zve(jpi,jpj)     )
-         ! Ensure below that barotropic velocities match time splitting estimate
-         ! Compute actual transport and replace it with ts estimate at "after" time step
-         zue(:,:) = e3u(:,:,1,Kaa) * puu(:,:,1,Kaa) * umask(:,:,1)
-         zve(:,:) = e3v(:,:,1,Kaa) * pvv(:,:,1,Kaa) * vmask(:,:,1)
-         DO jk = 2, jpkm1
-            zue(:,:) = zue(:,:) + e3u(:,:,jk,Kaa) * puu(:,:,jk,Kaa) * umask(:,:,jk)
-            zve(:,:) = zve(:,:) + e3v(:,:,jk,Kaa) * pvv(:,:,jk,Kaa) * vmask(:,:,jk)
-         END DO
-         DO jk = 1, jpkm1
-            puu(:,:,jk,Kaa) = ( puu(:,:,jk,Kaa) - zue(:,:) * r1_hu(:,:,Kaa) + uu_b(:,:,Kaa) ) * umask(:,:,jk)
-            pvv(:,:,jk,Kaa) = ( pvv(:,:,jk,Kaa) - zve(:,:) * r1_hv(:,:,Kaa) + vv_b(:,:,Kaa) ) * vmask(:,:,jk)
-         END DO
-         !
-         IF( .NOT.ln_bt_fw ) THEN
-            ! Remove advective velocity from "now velocities"
-            ! prior to asselin filtering
-            ! In the forward case, this is done below after asselin filtering
-            ! so that asselin contribution is removed at the same time
-            DO jk = 1, jpkm1
-               puu(:,:,jk,Kmm) = ( puu(:,:,jk,Kmm) - un_adv(:,:)*r1_hu(:,:,Kmm) + uu_b(:,:,Kmm) )*umask(:,:,jk)
-               pvv(:,:,jk,Kmm) = ( pvv(:,:,jk,Kmm) - vn_adv(:,:)*r1_hv(:,:,Kmm) + vv_b(:,:,Kmm) )*vmask(:,:,jk)
-            END DO
-         ENDIF
-         !
-         DEALLOCATE( zue, zve )
-         !
-      ENDIF
-      !
-   END SUBROUTINE mlf_baro_corr
-
-
-   SUBROUTINE finalize_sbc (kt, Kbb, Kaa, puu, pvv, pts)
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE finalize_sbc  ***
-      !!
-      !! ** Purpose :   Apply the boundary condition on the after velocity
-      !!
-      !! ** Method  : * Apply lateral boundary conditions on after velocity
-      !!             at the local domain boundaries through lbc_lnk call,
-      !!             at the one-way open boundaries (ln_bdy=T),
-      !!             at the AGRIF zoom   boundaries (lk_agrif=T)
-      !!
-      !! ** Action :   puu(Kaa),pvv(Kaa)   after horizontal velocity and tracers
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT(in   ) :: kt               ! ocean time-step index
-      INTEGER                             , INTENT(in   ) :: Kbb, Kaa    ! before and after time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: puu, pvv         ! velocities to be time filtered
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts,jpt), INTENT(inout) :: pts            ! active tracers
-      !
-      ! Update after tracer and velocity on domain lateral boundaries
-      !
-#if defined key_agrif
-            CALL Agrif_tra                     ! AGRIF zoom boundaries
-            CALL Agrif_dyn( kt )               !* AGRIF zoom boundaries
-#endif
-      !                                        ! local domain boundaries  (T-point, unchanged sign)
-      CALL lbc_lnk_multi( 'finalize_sbc', puu(:,:,:,       Kaa), 'U', -1., pvv(:,:,:       ,Kaa), 'V', -1.   &
-                       &                , pts(:,:,:,jp_tem,Kaa), 'T',  1., pts(:,:,:,jp_sal,Kaa), 'T',  1. )     !* local domain boundaries
-      !
-      !                                        !* BDY open boundaries
-      IF( ln_bdy )   THEN
-                               CALL bdy_tra( kt, Kbb, pts,      Kaa )
-         IF( ln_dynspg_exp )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa )
-         IF( ln_dynspg_ts  )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa, dyn3d_only=.true. )
-      ENDIF
-      !
-   END SUBROUTINE finalize_sbc
-#endif
-   !
-   !!======================================================================
-END MODULE stepMLF
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpctl.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpctl.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpctl.F90	(revision 14062)
@@ -26,6 +26,6 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! distributed memory computing
-   !
    USE netcdf          ! NetCDF library
+
    IMPLICIT NONE
    PRIVATE
@@ -71,4 +71,5 @@
       CHARACTER(len=20)               ::   clname
       !!----------------------------------------------------------------------
+      !
       IF( nstop > 0 .AND. ngrdstop > -1 )   RETURN   !   stpctl was already called by a child grid
       !
@@ -179,5 +180,5 @@
          END DO
          IF( kt == nitend )   istatus = NF90_CLOSE(nrunid)
-      END IF
+      ENDIF
       !                                   !==               error handling               ==!
       !                                   !==  done by all processes at every time step  ==!
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpmlf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpmlf.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/stpmlf.F90	(revision 14062)
@@ -0,0 +1,478 @@
+MODULE stpmlf
+   !!======================================================================
+   !!                       ***  MODULE stpMLF  ***
+   !! Time-stepping   : manager of the ocean, tracer and ice time stepping
+   !!                   using Modified Leap Frog for OCE
+   !!======================================================================
+   !! History :  OPA  !  1991-03  (G. Madec)  Original code
+   !!             -   !  1991-11  (G. Madec)
+   !!             -   !  1992-06  (M. Imbard)  add a first output record
+   !!             -   !  1996-04  (G. Madec)  introduction of dynspg
+   !!             -   !  1996-04  (M.A. Foujols)  introduction of passive tracer
+   !!            8.0  !  1997-06  (G. Madec)  new architecture of call
+   !!            8.2  !  1997-06  (G. Madec, M. Imbard, G. Roullet)  free surface
+   !!             -   !  1999-02  (G. Madec, N. Grima)  hpg implicit
+   !!             -   !  2000-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
+   !!   NEMO     1.0  !  2002-06  (G. Madec)  free form, suppress macro-tasking
+   !!             -   !  2004-08  (C. Talandier) New trends organization
+   !!             -   !  2005-01  (C. Ethe) Add the KPP closure scheme
+   !!             -   !  2005-11  (G. Madec)  Reorganisation of tra and dyn calls
+   !!             -   !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!             -   !  2006-07  (S. Masson)  restart using iom
+   !!            3.2  !  2009-02  (G. Madec, R. Benshila)  reintroduicing z*-coordinate
+   !!             -   !  2009-06  (S. Masson, G. Madec)  TKE restart compatible with key_cpl
+   !!            3.3  !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
+   !!             -   !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
+   !!            3.4  !  2011-04  (G. Madec, C. Ethe) Merge of dtatem and dtasal
+   !!            3.6  !  2012-07  (J. Simeon, G. Madec. C. Ethe)  Online coarsening of outputs
+   !!            3.6  !  2014-04  (F. Roquet, G. Madec) New equations of state
+   !!            3.6  !  2014-10  (E. Clementi, P. Oddo) Add Qiao vertical mixing in case of waves
+   !!            3.7  !  2014-10  (G. Madec)  LDF simplication
+   !!             -   !  2014-12  (G. Madec) remove KPP scheme
+   !!             -   !  2015-11  (J. Chanut) free surface simplification (remove filtered free surface)
+   !!            4.0  !  2017-05  (G. Madec)  introduction of the vertical physics manager (zdfphy)
+   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rewrite in preparation for new timestepping scheme
+   !!            4.x  !  2020-08  (S. Techene, G. Madec)  quasi eulerian coordinate time stepping
+   !!----------------------------------------------------------------------
+
+#if defined key_qco
+   !!----------------------------------------------------------------------
+   !!   'key_qco'       Quasi-Eulerian vertical coordonate
+   !!----------------------------------------------------------------------
+   
+   !!----------------------------------------------------------------------
+   !!   stp_MLF       : NEMO modified Leap Frog time-stepping with qco
+   !!----------------------------------------------------------------------
+   USE step_oce       ! time stepping definition modules
+   !
+   USE domqco         ! quasi-eulerian coordinate
+   USE traatf_qco     ! time filtering                   (tra_atf_qco routine)
+   USE dynatf_qco     ! time filtering                   (dyn_atf_qco routine)
+   
+   USE bdydyn         ! ocean open boundary conditions (define bdy_dyn)
+
+#if defined key_agrif
+   USE agrif_oce_interp
+#endif
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   stp_MLF   ! called by nemogcm.F90
+
+   !                                          !**  time level indices  **!
+   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !: used by nemo_init
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: step.F90 12377 2020-02-12 14:39:06Z acc $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+#if defined key_agrif
+   RECURSIVE SUBROUTINE stp_MLF( )
+      INTEGER             ::   kstp   ! ocean time-step index
+#else
+   SUBROUTINE stp_MLF( kstp )
+      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
+#endif
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp_MLF  ***
+      !!
+      !! ** Purpose : - Time stepping of OPA  (momentum and active tracer eqs.)
+      !!              - Time stepping of SI3 (dynamic and thermodynamic eqs.)
+      !!              - Time stepping of TRC  (passive tracer eqs.)
+      !!
+      !! ** Method  : -1- Update forcings and data
+      !!              -2- Update ocean physics
+      !!              -3- Compute the t and s trends
+      !!              -4- Update t and s
+      !!              -5- Compute the momentum trends
+      !!              -6- Update the horizontal velocity
+      !!              -7- Compute the diagnostics variables (rd,N2, hdiv,w)
+      !!              -8- Outputs and diagnostics
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji, jj, jk   ! dummy loop indice
+      INTEGER ::   indic        ! error indicator if < 0
+      REAL(wp),              DIMENSION(jpi,jpj,jpk) ::   zgdept
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:)         ::   zssh_f
+      !! ---------------------------------------------------------------------
+#if defined key_agrif
+      kstp = nit000 + Agrif_Nb_Step()
+      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+      IF( lk_agrif_debug ) THEN
+         IF( Agrif_Root() .and. lwp)   WRITE(*,*) '---'
+         IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
+      ENDIF
+      IF( kstp == nit000 + 1 )   lk_agrif_fstep = .FALSE.
+# if defined key_iomput
+      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
+# endif
+#endif
+      !
+      IF( ln_timing )   CALL timing_start('stp_MLF')
+      !
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! model timestep
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !
+      IF( l_1st_euler ) THEN     ! start or restart with Euler 1st time-step
+         rDt   = rn_Dt   
+         r1_Dt = 1._wp / rDt
+      ENDIF
+      !
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! update I/O and calendar
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                             indic = 0                ! reset to no error condition
+
+      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
+                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
+         IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
+                             CALL iom_init_closedef
+         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
+      ENDIF
+      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
+                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
+      IF( ln_crs         )   CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" )   ! tell IOM we are at time step kstp
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update external forcing (tides, open boundaries, ice shelf interaction and surface boundary condition (including sea-ice)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_tide    )   CALL tide_update( kstp )                     ! update tide potential
+      IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                        ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib)
+      IF( ln_bdy     )   CALL bdy_dta ( kstp, Nnn )                   ! update dynamic & tracer data at open boundaries
+      IF( ln_isf     )   CALL isf_stp ( kstp, Nnn )
+                         CALL sbc     ( kstp, Nbb, Nnn )              ! Sea Boundary Condition (including sea-ice)
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update stochastic parameters and random T/S fluctuations
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      IF( ln_sto_eos ) CALL sto_par( kstp )          ! Stochastic parameters
+      IF( ln_sto_eos ) CALL sto_pts( ts(:,:,:,:,Nnn)  )          ! Random T/S fluctuations
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !  THERMODYNAMICS
+                         CALL eos_rab( ts(:,:,:,:,Nbb), rab_b, Nnn )       ! before local thermal/haline expension ratio at T-points
+                         CALL eos_rab( ts(:,:,:,:,Nnn), rab_n, Nnn )       ! now    local thermal/haline expension ratio at T-points
+                         CALL bn2    ( ts(:,:,:,:,Nbb), rab_b, rn2b, Nnn ) ! before Brunt-Vaisala frequency
+                         CALL bn2    ( ts(:,:,:,:,Nnn), rab_n, rn2, Nnn  ) ! now    Brunt-Vaisala frequency
+
+      !  VERTICAL PHYSICS
+                         CALL zdf_phy( kstp, Nbb, Nnn, Nrhs )   ! vertical physics update (top/bot drag, avt, avs, avm + MLD)
+
+      !  LATERAL  PHYSICS
+      !
+      IF( l_ldfslp ) THEN                             ! slope of lateral mixing
+                         CALL eos( ts(:,:,:,:,Nbb), rhd, gdept_0(:,:,:) )               ! before in situ density
+
+         IF( ln_zps .AND. .NOT. ln_isfcav)                                    &
+            &            CALL zps_hde    ( kstp, Nnn, jpts, ts(:,:,:,:,Nbb), gtsu, gtsv,  &  ! Partial steps: before horizontal gradient
+            &                                          rhd, gru , grv    )       ! of t, s, rd at the last ocean level
+
+         IF( ln_zps .AND.       ln_isfcav)                                                &
+            &            CALL zps_hde_isf( kstp, Nnn, jpts, ts(:,:,:,:,Nbb), gtsu, gtsv, gtui, gtvi,  &  ! Partial steps for top cell (ISF)
+            &                                          rhd, gru , grv , grui, grvi   )       ! of t, s, rd at the first ocean level
+         IF( ln_traldf_triad ) THEN
+                         CALL ldf_slp_triad( kstp, Nbb, Nnn )             ! before slope for triad operator
+         ELSE
+                         CALL ldf_slp     ( kstp, rhd, rn2b, Nbb, Nnn )   ! before slope for standard operator
+         ENDIF
+      ENDIF
+      !                                                                        ! eddy diffusivity coeff.
+      IF( l_ldftra_time .OR. l_ldfeiv_time )   CALL ldf_tra( kstp, Nbb, Nnn )  !       and/or eiv coeff.
+      IF( l_ldfdyn_time                    )   CALL ldf_dyn( kstp, Nbb )       ! eddy viscosity coeff.
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  Ocean dynamics : hdiv, ssh, e3, u, v, w
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      DO jk = 1, jpk
+         zgdept(:,:,jk) = gdept(:,:,jk,Nnn)
+      END DO
+                            CALL ssh_nxt    ( kstp, Nbb, Nnn, ssh,  Naa )   ! after ssh (includes call to div_hor)
+      IF( .NOT.ln_linssh )  THEN
+                             CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa)           )   ! "after" ssh/h_0 ratio at t,u,v pts
+         IF( ln_dynspg_exp ) CALL dom_qco_r3c( ssh(:,:,Nnn), r3t(:,:,Nnn), r3u(:,:,Nnn), r3v(:,:,Nnn), r3f(:,:) )   ! spg_exp : needed only for "now" ssh/h_0 ratio at f point
+      ENDIF
+                            CALL wzv        ( kstp, Nbb, Nnn, Naa, ww  )    ! Nnn cross-level velocity
+      IF( ln_zad_Aimp )     CALL wAimp      ( kstp,      Nnn           )    ! Adaptive-implicit vertical advection partitioning
+                            CALL eos        ( ts(:,:,:,:,Nnn), rhd, rhop, zgdept ) ! now in situ density for hpg computation
+
+
+                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
+                         vv(:,:,:,Nrhs) = 0._wp
+
+      IF(  lk_asminc .AND. ln_asmiau .AND. ln_dyninc )   &
+               &         CALL dyn_asm_inc   ( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! apply dynamics assimilation increment
+      IF( ln_bdy     )   CALL bdy_dyn3d_dmp ( kstp, Nbb,      uu, vv, Nrhs )  ! bdy damping trends
+#if defined key_agrif
+      IF(.NOT. Agrif_Root())  &
+               &         CALL Agrif_Sponge_dyn        ! momentum sponge
+#endif
+                         CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
+                         CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
+                         CALL dyn_ldf( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! lateral mixing
+      IF( ln_zdfosm  )   CALL dyn_osm( kstp,      Nnn      , uu, vv, Nrhs )  ! OSMOSIS non-local velocity fluxes ==> RHS
+                         CALL dyn_hpg( kstp,      Nnn      , uu, vv, Nrhs )  ! horizontal gradient of Hydrostatic pressure
+                         CALL dyn_spg( kstp, Nbb, Nnn, Nrhs, uu, vv, ssh, uu_b, vv_b, Naa )  ! surface pressure gradient
+                                                      ! With split-explicit free surface, since now transports have been updated and ssh(:,:,Nrhs) as well
+
+      IF( ln_dynspg_ts ) THEN                         ! vertical scale factors and vertical velocity need to be updated
+                            CALL div_hor    ( kstp, Nbb, Nnn )                ! Horizontal divergence  (2nd call in time-split case)
+         IF(.NOT.ln_linssh) CALL dom_qco_r3c ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! update ssh/h_0 ratio at t,u,v,f pts 
+      ENDIF
+                            CALL dyn_zdf    ( kstp, Nbb, Nnn, Nrhs, uu, vv, Naa  )  ! vertical diffusion
+      IF( ln_dynspg_ts ) THEN                                                       ! vertical scale factors and vertical velocity need to be updated
+                            CALL wzv        ( kstp, Nbb, Nnn, Naa, ww )             ! Nnn cross-level velocity
+         IF( ln_zad_Aimp )  CALL wAimp      ( kstp,      Nnn )                      ! Adaptive-implicit vertical advection partitioning
+      ENDIF
+
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! cool skin
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF ( ln_diurnal )  CALL diurnal_layers( kstp )
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      IF( ln_floats  )   CALL flo_stp   ( kstp, Nbb, Nnn )      ! drifting Floats
+      IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
+                         CALL dia_hth   ( kstp,      Nnn )      ! Thermocline depth (20 degres isotherm depth)
+      IF( ln_diadct  )   CALL dia_dct   ( kstp,      Nnn )      ! Transports
+                         CALL dia_ar5   ( kstp,      Nnn )      ! ar5 diag
+                         CALL dia_ptr   ( kstp,      Nnn )      ! Poleward adv/ldf TRansports diagnostics
+                         CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
+      IF( ln_crs     )   CALL crs_fld   ( kstp,      Nnn )      ! ocean model: online field coarsening & output
+      IF( lk_diadetide ) CALL dia_detide( kstp )                ! Weights computation for daily detiding of model diagnostics
+      IF( lk_diamlr  )   CALL dia_mlr                           ! Update time used in multiple-linear-regression analysis
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Now ssh filtering
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL ssh_atf    ( kstp, Nbb, Nnn, Naa, ssh )            ! time filtering of "now" sea surface height
+                         CALL dom_qco_r3c( ssh(:,:,Nnn), r3t_f, r3u_f, r3v_f )   ! "now" ssh/h_0 ratio from filtrered ssh
+#if defined key_top
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Passive Tracer Model
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL trc_stp    ( kstp, Nbb, Nnn, Nrhs, Naa )           ! time-stepping
+#endif
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Active tracers
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         ts(:,:,:,:,Nrhs) = 0._wp         ! set tracer trends to zero
+
+      IF(  lk_asminc .AND. ln_asmiau .AND. &
+         & ln_trainc )   CALL tra_asm_inc( kstp, Nbb, Nnn, ts, Nrhs )  ! apply tracer assimilation increment
+                         CALL tra_sbc    ( kstp,      Nnn, ts, Nrhs )  ! surface boundary condition
+      IF( ln_traqsr  )   CALL tra_qsr    ( kstp,      Nnn, ts, Nrhs )  ! penetrative solar radiation qsr
+      IF( ln_isf     )   CALL tra_isf    ( kstp,      Nnn, ts, Nrhs )  ! ice shelf heat flux
+      IF( ln_trabbc  )   CALL tra_bbc    ( kstp,      Nnn, ts, Nrhs )  ! bottom heat flux
+      IF( ln_trabbl  )   CALL tra_bbl    ( kstp, Nbb, Nnn, ts, Nrhs )  ! advective (and/or diffusive) bottom boundary layer scheme
+      IF( ln_tradmp  )   CALL tra_dmp    ( kstp, Nbb, Nnn, ts, Nrhs )  ! internal damping trends
+      IF( ln_bdy     )   CALL bdy_tra_dmp( kstp, Nbb,      ts, Nrhs )  ! bdy damping trends
+#if defined key_agrif
+      IF(.NOT. Agrif_Root())  &
+               &         CALL Agrif_Sponge_tra        ! tracers sponge
+#endif
+                         CALL tra_adv    ( kstp, Nbb, Nnn, ts, Nrhs )  ! hor. + vert. advection	==> RHS
+      IF( ln_zdfosm  )   CALL tra_osm    ( kstp,      Nnn, ts, Nrhs )  ! OSMOSIS non-local tracer fluxes ==> RHS
+      IF( lrst_oce .AND. ln_zdfosm ) &
+           &             CALL osm_rst    ( kstp,      Nnn, 'WRITE'  )  ! write OSMOSIS outputs + ww (so must do here) to restarts
+                         CALL tra_ldf    ( kstp, Nbb, Nnn, ts, Nrhs )  ! lateral mixing
+
+                         CALL tra_zdf    ( kstp, Nbb, Nnn, Nrhs, ts, Naa  )  ! vertical mixing and after tracer fields
+      IF( ln_zdfnpc  )   CALL tra_npc    ( kstp,      Nnn, Nrhs, ts, Naa  )  ! update after fields by non-penetrative convection
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Set boundary conditions, time filter and swap time levels
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+!!jc1: For agrif, it would be much better to finalize tracers/momentum here (e.g. bdy conditions) and move the swap
+!!    (and time filtering) after Agrif update. Then restart would be done after and would contain updated fields.
+!!    If so:
+!!    (i) no need to call agrif update at initialization time
+!!    (ii) no need to update "before" fields
+!!
+!!    Apart from creating new tra_swp/dyn_swp routines, this however:
+!!    (i) makes boundary conditions at initialization time computed from updated fields which is not the case between
+!!    two restarts => restartability issue. One can circumvent this, maybe, by assuming "interface separation",
+!!    e.g. a shift of the feedback interface inside child domain.
+!!    (ii) requires that all restart outputs of updated variables by agrif (e.g. passive tracers/tke/barotropic arrays) are done at the same
+!!    place.
+!!
+      IF( ln_dynspg_ts ) CALL mlf_baro_corr (            Nnn, Naa, uu, vv     )   ! barotrope adjustment
+                         CALL finalize_lbc  ( kstp, Nbb     , Naa, uu, vv, ts )   ! boundary conditions
+                         CALL tra_atf_qco   ( kstp, Nbb, Nnn, Naa        , ts )   ! time filtering of "now" tracer arrays
+                         CALL dyn_atf_qco   ( kstp, Nbb, Nnn, Naa, uu, vv     )   ! time filtering of "now" velocities 
+                         r3t(:,:,Nnn) = r3t_f(:,:)                                ! update now ssh/h_0 with time filtered values
+                         r3u(:,:,Nnn) = r3u_f(:,:)
+                         r3v(:,:,Nnn) = r3v_f(:,:)
+
+      !
+      ! Swap time levels
+      Nrhs = Nbb
+      Nbb = Nnn
+      Nnn = Naa
+      Naa = Nrhs
+      !
+      !
+      IF( ln_diahsb  )   CALL dia_hsb       ( kstp, Nbb, Nnn )  ! - ML - global conservation diagnostics
+
+!!gm : This does not only concern the dynamics ==>>> add a new title
+!!gm2: why ouput restart before AGRIF update?
+!!
+!!jc: That would be better, but see comment above
+!!
+      IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
+      IF( ln_sto_eos )   CALL sto_rst_write( kstp )   ! write restart file for stochastic parameters
+
+#if defined key_agrif
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! AGRIF
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs      ! agrif_oce module copies of time level indices
+                         CALL Agrif_Integrate_ChildGrids( stp_MLF )       ! allows to finish all the Child Grids before updating
+
+                         IF( Agrif_NbStepint() == 0 ) THEN
+                            CALL Agrif_update_all( )                  ! Update all components
+                         ENDIF
+#endif
+      IF( ln_diaobs  )   CALL dia_obs      ( kstp, Nnn )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL stp_ctl      ( kstp, Nnn )
+
+      IF( kstp == nit000 ) THEN                          ! 1st time step only
+                                        CALL iom_close( numror )   ! close input  ocean restart file
+         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
+         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Coupled mode
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+!!gm why lk_oasis and not lk_cpl ????
+      IF( lk_oasis   )   CALL sbc_cpl_snd( kstp, Nbb, Nnn )        ! coupled mode : field exchanges
+      !
+#if defined key_iomput
+      IF( kstp == nitend .OR. indic < 0 ) THEN
+                      CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
+         IF( lrxios ) CALL iom_context_finalize(      crxios_context          )
+         IF( ln_crs ) CALL iom_context_finalize( trim(cxios_context)//"_crs" ) !
+      ENDIF
+#endif
+      !
+      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
+         rDt   = 2._wp * rn_Dt   
+         r1_Dt = 1._wp / rDt
+         l_1st_euler = .FALSE.      
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('stp_MLF')
+      !
+   END SUBROUTINE stp_MLF
+
+
+   SUBROUTINE mlf_baro_corr( Kmm, Kaa, puu, pvv )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE mlf_baro_corr  ***
+      !!
+      !! ** Purpose :   Finalize after horizontal velocity.
+      !!
+      !! ** Method  : * Ensure after velocities transport matches time splitting
+      !!             estimate (ln_dynspg_ts=T)
+      !!
+      !! ** Action :   puu(Kmm),pvv(Kmm)   updated now horizontal velocity (ln_bt_fw=F)
+      !!               puu(Kaa),pvv(Kaa)   after horizontal velocity
+      !!----------------------------------------------------------------------
+      USE dynspg_ts, ONLY : un_adv, vn_adv   ! updated Kmm barotropic transport 
+      !!
+      INTEGER                             , INTENT(in   ) ::   Kmm, Kaa   ! before and after time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::   puu, pvv   ! velocities
+      !
+      INTEGER  ::   jk   ! dummy loop indices
+      REAL(wp), DIMENSION(jpi,jpj) ::   zue, zve
+      !!----------------------------------------------------------------------
+
+      ! Ensure below that barotropic velocities match time splitting estimate
+      ! Compute actual transport and replace it with ts estimate at "after" time step
+      zue(:,:) = e3u(:,:,1,Kaa) * puu(:,:,1,Kaa) * umask(:,:,1)
+      zve(:,:) = e3v(:,:,1,Kaa) * pvv(:,:,1,Kaa) * vmask(:,:,1)
+      DO jk = 2, jpkm1
+         zue(:,:) = zue(:,:) + e3u(:,:,jk,Kaa) * puu(:,:,jk,Kaa) * umask(:,:,jk)
+         zve(:,:) = zve(:,:) + e3v(:,:,jk,Kaa) * pvv(:,:,jk,Kaa) * vmask(:,:,jk)
+      END DO
+      DO jk = 1, jpkm1
+         puu(:,:,jk,Kaa) = ( puu(:,:,jk,Kaa) - zue(:,:) * r1_hu(:,:,Kaa) + uu_b(:,:,Kaa) ) * umask(:,:,jk)
+         pvv(:,:,jk,Kaa) = ( pvv(:,:,jk,Kaa) - zve(:,:) * r1_hv(:,:,Kaa) + vv_b(:,:,Kaa) ) * vmask(:,:,jk)
+      END DO
+      !
+      IF( .NOT.ln_bt_fw ) THEN
+         ! Remove advective velocity from "now velocities"
+         ! prior to asselin filtering
+         ! In the forward case, this is done below after asselin filtering
+         ! so that asselin contribution is removed at the same time
+         DO jk = 1, jpkm1
+            puu(:,:,jk,Kmm) = ( puu(:,:,jk,Kmm) - un_adv(:,:)*r1_hu(:,:,Kmm) + uu_b(:,:,Kmm) )*umask(:,:,jk)
+            pvv(:,:,jk,Kmm) = ( pvv(:,:,jk,Kmm) - vn_adv(:,:)*r1_hv(:,:,Kmm) + vv_b(:,:,Kmm) )*vmask(:,:,jk)
+         END DO
+      ENDIF
+      !
+   END SUBROUTINE mlf_baro_corr
+
+
+   SUBROUTINE finalize_lbc( kt, Kbb, Kaa, puu, pvv, pts )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE finalize_lbc  ***
+      !!
+      !! ** Purpose :   Apply the boundary condition on the after velocity
+      !!
+      !! ** Method  : * Apply lateral boundary conditions on after velocity
+      !!             at the local domain boundaries through lbc_lnk call,
+      !!             at the one-way open boundaries (ln_bdy=T),
+      !!             at the AGRIF zoom   boundaries (lk_agrif=T)
+      !!
+      !! ** Action :   puu(Kaa),pvv(Kaa)   after horizontal velocity and tracers
+      !!----------------------------------------------------------------------
+      INTEGER                                  , INTENT(in   ) ::   kt         ! ocean time-step index
+      INTEGER                                  , INTENT(in   ) ::   Kbb, Kaa   ! before and after time level indices
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt)     , INTENT(inout) ::   puu, pvv   ! velocities to be time filtered
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts,jpt), INTENT(inout) ::   pts        ! active tracers
+      !!----------------------------------------------------------------------
+      !
+      ! Update after tracer and velocity on domain lateral boundaries
+      !
+# if defined key_agrif
+            CALL Agrif_tra                     !* AGRIF zoom boundaries
+            CALL Agrif_dyn( kt )
+# endif
+      !                                        ! local domain boundaries  (T-point, unchanged sign)
+      CALL lbc_lnk_multi( 'finalize_lbc', puu(:,:,:,       Kaa), 'U', -1., pvv(:,:,:       ,Kaa), 'V', -1.   &
+                       &                , pts(:,:,:,jp_tem,Kaa), 'T',  1., pts(:,:,:,jp_sal,Kaa), 'T',  1. )
+      !
+      !                                        !* BDY open boundaries
+      IF( ln_bdy )   THEN
+                               CALL bdy_tra( kt, Kbb, pts,      Kaa )
+         IF( ln_dynspg_exp )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa )
+         IF( ln_dynspg_ts  )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa, dyn3d_only=.true. )
+      ENDIF
+      !
+   END SUBROUTINE finalize_lbc
+
+#else
+   !!----------------------------------------------------------------------
+   !!   default option             EMPTY MODULE           qco not activated
+   !!----------------------------------------------------------------------
+#endif
+   
+   !!======================================================================
+END MODULE stpmlf
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OFF/dtadyn.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OFF/dtadyn.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OFF/dtadyn.F90	(revision 14062)
@@ -23,8 +23,8 @@
    USE c1d             ! 1D configuration: lk_c1d
    USE dom_oce         ! ocean domain: variables
-#if ! defined key_qco 
-   USE domvvl          ! variable volume
+#if defined key_qco 
+   USE domqco          ! variable volume
 #else
-   USE domqco
+   USE domvvl
 #endif
    USE zdf_oce         ! ocean vertical physics: variables
@@ -97,4 +97,6 @@
    !! * Substitutions
 #  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
+   
    !!----------------------------------------------------------------------
    !! NEMO/OFF 4.0 , NEMO Consortium (2018)
@@ -388,6 +390,6 @@
         gdepw(:,:,:,Kbb) = gdepw(:,:,:,Kmm)
         !
-      ENDIF
 #endif
+      ENDIF
       !
       IF( ln_dynrnf .AND. ln_dynrnf_depth ) THEN       ! read depht over which runoffs are distributed
@@ -412,4 +414,5 @@
             ENDIF
          END_2D
+         !
          DO_2D( 1, 1, 1, 1 )                           ! set the associated depth
             h_rnf(ji,jj) = 0._wp
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OFF/nemogcm.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OFF/nemogcm.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OFF/nemogcm.F90	(revision 14062)
@@ -64,5 +64,9 @@
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
    USE lbcnfd  , ONLY : isendto, nsndto   ! Setup of north fold exchanges
-   USE step, ONLY : Nbb, Nnn, Naa, Nrhs   ! time level indices
+#if defined key_qco
+   USE stpmlf , ONLY : Nbb, Nnn, Naa, Nrhs   ! time level indices
+#else
+   USE step    , ONLY : Nbb, Nnn, Naa, Nrhs   ! time level indices
+#endif
    USE halo_mng
 
@@ -143,12 +147,12 @@
                                 CALL dta_dyn_atf( istp, Nbb, Nnn, Naa )       ! time filter of sea  surface height and vertical scale factors
 # if defined key_qco
-                                CALL dom_qco_r3c( ssh(:,:,Kmm), r3t_f, r3u_f, r3v_f )
+                                CALL dom_qco_r3c( ssh(:,:,Nnn), r3t_f, r3u_f, r3v_f )
 # endif
          ENDIF
                                 CALL trc_stp    ( istp, Nbb, Nnn, Nrhs, Naa ) ! time-stepping
 # if defined key_qco
-                                !r3t(:,:,Kmm) = r3t_f(:,:)                     ! update ssh to h0 ratio
-                                !r3u(:,:,Kmm) = r3u_f(:,:)
-                                !r3v(:,:,Kmm) = r3v_f(:,:)
+                                !r3t(:,:,Nnn) = r3t_f(:,:)                     ! update ssh to h0 ratio
+                                !r3u(:,:,Nnn) = r3u_f(:,:)
+                                !r3v(:,:,Nnn) = r3v_f(:,:)
 # endif
 #endif
@@ -160,7 +164,7 @@
          !
 #if ! defined key_qco
-#if ! defined key_sed_off
+# if ! defined key_sed_off
          IF( .NOT.ln_linssh )   CALL dta_dyn_sf_interp( istp, Nnn )  ! calculate now grid parameters
-#endif
+# endif
 #endif         
          CALL stp_ctl    ( istp )             ! Time loop: control and print
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SAS/nemogcm.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SAS/nemogcm.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SAS/nemogcm.F90	(revision 14062)
@@ -216,8 +216,10 @@
       !!----------------------------------------------------------------------
       !
-      IF( lk_oasis ) THEN   ;   cxios_context = 'sas'
-      ELSE                  ;   cxios_context = 'nemo'
+      IF( lk_oasis ) THEN   ;   cxios_context = 'sas'    ! when coupling SAS to OCE
+      ELSE                  ;   cxios_context = 'nemo'   ! 
       ENDIF
       nn_hls = 1
+      !
+      l_SAS = .TRUE.   ! used in domain:dom_nam
       !
       !                             !-------------------------------------------------!
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/asminc.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/asminc.F90	(revision 14059)
+++ 	(revision )
@@ -1,1030 +1,0 @@
-MODULE asminc
-   !!======================================================================
-   !!                       ***  MODULE asminc  ***
-   !! Assimilation increment : Apply an increment generated by data
-   !!                          assimilation
-   !!======================================================================
-   !! History :       ! 2007-03  (M. Martin)  Met Office version
-   !!                 ! 2007-04  (A. Weaver)  calc_date original code
-   !!                 ! 2007-04  (A. Weaver)  Merge with OPAVAR/NEMOVAR
-   !!   NEMO     3.3  ! 2010-05  (D. Lea)  Update to work with NEMO v3.2
-   !!             -   ! 2010-05  (D. Lea)  add calc_month_len routine based on day_init 
-   !!            3.4  ! 2012-10  (A. Weaver and K. Mogensen) Fix for direct initialization
-   !!                 ! 2014-09  (D. Lea)  Local calc_date removed use routine from OBS
-   !!                 ! 2015-11  (D. Lea)  Handle non-zero initial time of day
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   asm_inc_init   : Initialize the increment arrays and IAU weights
-   !!   tra_asm_inc    : Apply the tracer (T and S) increments
-   !!   dyn_asm_inc    : Apply the dynamic (u and v) increments
-   !!   ssh_asm_inc    : Apply the SSH increment
-   !!   ssh_asm_div    : Apply divergence associated with SSH increment
-   !!   seaice_asm_inc : Apply the seaice increment
-   !!----------------------------------------------------------------------
-   USE oce             ! Dynamics and active tracers defined in memory
-   USE par_oce         ! Ocean space and time domain variables
-   USE dom_oce         ! Ocean space and time domain
-   USE domvvl          ! domain: variable volume level
-   USE ldfdyn          ! lateral diffusion: eddy viscosity coefficients
-   USE eosbn2          ! Equation of state - in situ and potential density
-   USE zpshde          ! Partial step : Horizontal Derivative
-   USE asmpar          ! Parameters for the assmilation interface
-   USE asmbkg          ! 
-   USE c1d             ! 1D initialization
-   USE sbc_oce         ! Surface boundary condition variables.
-   USE diaobs   , ONLY : calc_date     ! Compute the calendar date on a given step
-#if defined key_si3
-   USE ice      , ONLY : hm_i, at_i, at_i_b
-#endif
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! Library to read input files
-   USE lib_mpp         ! MPP library
-
-   IMPLICIT NONE
-   PRIVATE
-   
-   PUBLIC   asm_inc_init   !: Initialize the increment arrays and IAU weights
-   PUBLIC   tra_asm_inc    !: Apply the tracer (T and S) increments
-   PUBLIC   dyn_asm_inc    !: Apply the dynamic (u and v) increments
-   PUBLIC   ssh_asm_inc    !: Apply the SSH increment
-   PUBLIC   ssh_asm_div    !: Apply the SSH divergence
-   PUBLIC   seaice_asm_inc !: Apply the seaice increment
-
-#if defined key_asminc
-    LOGICAL, PUBLIC, PARAMETER :: lk_asminc = .TRUE.   !: Logical switch for assimilation increment interface
-#else
-    LOGICAL, PUBLIC, PARAMETER :: lk_asminc = .FALSE.  !: No assimilation increments
-#endif
-   LOGICAL, PUBLIC :: ln_bkgwri     !: No output of the background state fields
-   LOGICAL, PUBLIC :: ln_asmiau     !: No applying forcing with an assimilation increment
-   LOGICAL, PUBLIC :: ln_asmdin     !: No direct initialization
-   LOGICAL, PUBLIC :: ln_trainc     !: No tracer (T and S) assimilation increments
-   LOGICAL, PUBLIC :: ln_dyninc     !: No dynamics (u and v) assimilation increments
-   LOGICAL, PUBLIC :: ln_sshinc     !: No sea surface height assimilation increment
-   LOGICAL, PUBLIC :: ln_seaiceinc  !: No sea ice concentration increment
-   LOGICAL, PUBLIC :: ln_salfix     !: Apply minimum salinity check
-   LOGICAL, PUBLIC :: ln_temnofreeze = .FALSE. !: Don't allow the temperature to drop below freezing
-   INTEGER, PUBLIC :: nn_divdmp     !: Apply divergence damping filter nn_divdmp times
-
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   t_bkg   , s_bkg      !: Background temperature and salinity
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   u_bkg   , v_bkg      !: Background u- & v- velocity components
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   t_bkginc, s_bkginc   !: Increment to the background T & S
-   REAL(wp), PUBLIC, DIMENSION(:,:,:), ALLOCATABLE ::   u_bkginc, v_bkginc   !: Increment to the u- & v-components 
-   REAL(wp), PUBLIC, DIMENSION(:)    , ALLOCATABLE ::   wgtiau               !: IAU weights for each time step
-#if defined key_asminc
-   REAL(wp), PUBLIC, DIMENSION(:,:)  , ALLOCATABLE ::   ssh_iau              !: IAU-weighted sea surface height increment
-#endif
-   !                                !!! time steps relative to the cycle interval [0,nitend-nit000-1]
-   INTEGER , PUBLIC ::   nitbkg      !: Time step of the background state used in the Jb term
-   INTEGER , PUBLIC ::   nitdin      !: Time step of the background state for direct initialization
-   INTEGER , PUBLIC ::   nitiaustr   !: Time step of the start of the IAU interval 
-   INTEGER , PUBLIC ::   nitiaufin   !: Time step of the end of the IAU interval
-   ! 
-   INTEGER , PUBLIC ::   niaufn      !: Type of IAU weighing function: = 0   Constant weighting
-   !                                 !: = 1   Linear hat-like, centred in middle of IAU interval 
-   REAL(wp), PUBLIC ::   salfixmin   !: Ensure that the salinity is larger than this  value if (ln_salfix)
-
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ssh_bkg, ssh_bkginc   ! Background sea surface height and its increment
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   seaice_bkginc         ! Increment to the background sea ice conc
-#if defined key_cice && defined key_asminc
-   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ndaice_da             ! ice increment tendency into CICE
-#endif
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-!!st10
-#  include "domzgr_substitute.h90"
-!!st10
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: asminc.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE asm_inc_init( Kbb, Kmm, Krhs )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE asm_inc_init  ***
-      !!          
-      !! ** Purpose : Initialize the assimilation increment and IAU weights.
-      !!
-      !! ** Method  : Initialize the assimilation increment and IAU weights.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::  Kbb, Kmm, Krhs  ! time level indices
-      !
-      INTEGER :: ji, jj, jk, jt  ! dummy loop indices
-      INTEGER :: imid, inum      ! local integers
-      INTEGER :: ios             ! Local integer output status for namelist read
-      INTEGER :: iiauper         ! Number of time steps in the IAU period
-      INTEGER :: icycper         ! Number of time steps in the cycle
-      REAL(KIND=dp) :: ditend_date     ! Date YYYYMMDD.HHMMSS of final time step
-      REAL(KIND=dp) :: ditbkg_date     ! Date YYYYMMDD.HHMMSS of background time step for Jb term
-      REAL(KIND=dp) :: ditdin_date     ! Date YYYYMMDD.HHMMSS of background time step for DI
-      REAL(KIND=dp) :: ditiaustr_date  ! Date YYYYMMDD.HHMMSS of IAU interval start time step
-      REAL(KIND=dp) :: ditiaufin_date  ! Date YYYYMMDD.HHMMSS of IAU interval final time step
-
-      REAL(wp) :: znorm        ! Normalization factor for IAU weights
-      REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights (should be equal to one)
-      REAL(wp) :: z_inc_dateb  ! Start date of interval on which increment is valid
-      REAL(wp) :: z_inc_datef  ! End date of interval on which increment is valid
-      REAL(wp) :: zdate_bkg    ! Date in background state file for DI
-      REAL(wp) :: zdate_inc    ! Time axis in increments file
-      !
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zhdiv   ! 2D workspace
-      !!
-      NAMELIST/nam_asminc/ ln_bkgwri,                                      &
-         &                 ln_trainc, ln_dyninc, ln_sshinc,                &
-         &                 ln_asmdin, ln_asmiau,                           &
-         &                 nitbkg, nitdin, nitiaustr, nitiaufin, niaufn,   &
-         &                 ln_salfix, salfixmin, nn_divdmp
-      !!----------------------------------------------------------------------
-
-      !-----------------------------------------------------------------------
-      ! Read Namelist nam_asminc : assimilation increment interface
-      !-----------------------------------------------------------------------
-      ln_seaiceinc   = .FALSE.
-      ln_temnofreeze = .FALSE.
-
-      READ  ( numnam_ref, nam_asminc, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_asminc in reference namelist' )
-      READ  ( numnam_cfg, nam_asminc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_asminc in configuration namelist' )
-      IF(lwm) WRITE ( numond, nam_asminc )
-
-      ! Control print
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'asm_inc_init : Assimilation increment initialization :'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist namasm : set assimilation increment parameters'
-         WRITE(numout,*) '      Logical switch for writing out background state          ln_bkgwri = ', ln_bkgwri
-         WRITE(numout,*) '      Logical switch for applying tracer increments            ln_trainc = ', ln_trainc
-         WRITE(numout,*) '      Logical switch for applying velocity increments          ln_dyninc = ', ln_dyninc
-         WRITE(numout,*) '      Logical switch for applying SSH increments               ln_sshinc = ', ln_sshinc
-         WRITE(numout,*) '      Logical switch for Direct Initialization (DI)            ln_asmdin = ', ln_asmdin
-         WRITE(numout,*) '      Logical switch for applying sea ice increments        ln_seaiceinc = ', ln_seaiceinc
-         WRITE(numout,*) '      Logical switch for Incremental Analysis Updating (IAU)   ln_asmiau = ', ln_asmiau
-         WRITE(numout,*) '      Timestep of background in [0,nitend-nit000-1]            nitbkg    = ', nitbkg
-         WRITE(numout,*) '      Timestep of background for DI in [0,nitend-nit000-1]     nitdin    = ', nitdin
-         WRITE(numout,*) '      Timestep of start of IAU interval in [0,nitend-nit000-1] nitiaustr = ', nitiaustr
-         WRITE(numout,*) '      Timestep of end of IAU interval in [0,nitend-nit000-1]   nitiaufin = ', nitiaufin
-         WRITE(numout,*) '      Type of IAU weighting function                           niaufn    = ', niaufn
-         WRITE(numout,*) '      Logical switch for ensuring that the sa > salfixmin      ln_salfix = ', ln_salfix
-         WRITE(numout,*) '      Minimum salinity after applying the increments           salfixmin = ', salfixmin
-      ENDIF
-
-      nitbkg_r    = nitbkg    + nit000 - 1            ! Background time referenced to nit000
-      nitdin_r    = nitdin    + nit000 - 1            ! Background time for DI referenced to nit000
-      nitiaustr_r = nitiaustr + nit000 - 1            ! Start of IAU interval referenced to nit000
-      nitiaufin_r = nitiaufin + nit000 - 1            ! End of IAU interval referenced to nit000
-
-      iiauper     = nitiaufin_r - nitiaustr_r + 1     ! IAU interval length
-      icycper     = nitend      - nit000      + 1     ! Cycle interval length
-
-      CALL calc_date( nitend     , ditend_date    )   ! Date of final time step
-      CALL calc_date( nitbkg_r   , ditbkg_date    )   ! Background time for Jb referenced to ndate0
-      CALL calc_date( nitdin_r   , ditdin_date    )   ! Background time for DI referenced to ndate0
-      CALL calc_date( nitiaustr_r, ditiaustr_date )   ! IAU start time referenced to ndate0
-      CALL calc_date( nitiaufin_r, ditiaufin_date )   ! IAU end time referenced to ndate0
-
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '   Time steps referenced to current cycle:'
-         WRITE(numout,*) '       iitrst      = ', nit000 - 1
-         WRITE(numout,*) '       nit000      = ', nit000
-         WRITE(numout,*) '       nitend      = ', nitend
-         WRITE(numout,*) '       nitbkg_r    = ', nitbkg_r
-         WRITE(numout,*) '       nitdin_r    = ', nitdin_r
-         WRITE(numout,*) '       nitiaustr_r = ', nitiaustr_r
-         WRITE(numout,*) '       nitiaufin_r = ', nitiaufin_r
-         WRITE(numout,*)
-         WRITE(numout,*) '   Dates referenced to current cycle:'
-         WRITE(numout,*) '       ndastp         = ', ndastp
-         WRITE(numout,*) '       ndate0         = ', ndate0
-         WRITE(numout,*) '       nn_time0       = ', nn_time0
-         WRITE(numout,*) '       ditend_date    = ', ditend_date
-         WRITE(numout,*) '       ditbkg_date    = ', ditbkg_date
-         WRITE(numout,*) '       ditdin_date    = ', ditdin_date
-         WRITE(numout,*) '       ditiaustr_date = ', ditiaustr_date
-         WRITE(numout,*) '       ditiaufin_date = ', ditiaufin_date
-      ENDIF
-
-
-      IF ( ( ln_asmdin ).AND.( ln_asmiau ) )   &
-         & CALL ctl_stop( ' ln_asmdin and ln_asmiau :', &
-         &                ' Choose Direct Initialization OR Incremental Analysis Updating')
-
-      IF (      ( ( .NOT. ln_asmdin ).AND.( .NOT. ln_asmiau ) ) &
-           .AND.( ( ln_trainc ).OR.( ln_dyninc ).OR.( ln_sshinc ) .OR. ( ln_seaiceinc) )) &
-         & CALL ctl_stop( ' One or more of ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc is set to .true.', &
-         &                ' but ln_asmdin and ln_asmiau are both set to .false. :', &
-         &                ' Inconsistent options')
-
-      IF ( ( niaufn /= 0 ).AND.( niaufn /= 1 ) ) &
-         & CALL ctl_stop( ' niaufn /= 0 or niaufn /=1 :',  &
-         &                ' Type IAU weighting function is invalid')
-
-      IF ( ( .NOT. ln_trainc ).AND.( .NOT. ln_dyninc ).AND.( .NOT. ln_sshinc ).AND.( .NOT. ln_seaiceinc ) &
-         &                     )  &
-         & CALL ctl_warn( ' ln_trainc, ln_dyninc, ln_sshinc and ln_seaiceinc are set to .false. :', &
-         &                ' The assimilation increments are not applied')
-
-      IF ( ( ln_asmiau ).AND.( nitiaustr == nitiaufin ) ) &
-         & CALL ctl_stop( ' nitiaustr = nitiaufin :',  &
-         &                ' IAU interval is of zero length')
-
-      IF ( ( ln_asmiau ).AND.( ( nitiaustr_r < nit000 ).OR.( nitiaufin_r > nitend ) ) ) &
-         & CALL ctl_stop( ' nitiaustr or nitiaufin :',  &
-         &                ' IAU starting or final time step is outside the cycle interval', &
-         &                 ' Valid range nit000 to nitend')
-
-      IF ( ( nitbkg_r < nit000 - 1 ).OR.( nitbkg_r > nitend ) ) &
-         & CALL ctl_stop( ' nitbkg :',  &
-         &                ' Background time step is outside the cycle interval')
-
-      IF ( ( nitdin_r < nit000 - 1 ).OR.( nitdin_r > nitend ) ) &
-         & CALL ctl_stop( ' nitdin :',  &
-         &                ' Background time step for Direct Initialization is outside', &
-         &                ' the cycle interval')
-
-      IF ( nstop > 0 ) RETURN       ! if there are any errors then go no further
-
-      !--------------------------------------------------------------------
-      ! Initialize the Incremental Analysis Updating weighting function
-      !--------------------------------------------------------------------
-
-      IF( ln_asmiau ) THEN
-         !
-         ALLOCATE( wgtiau( icycper ) )
-         !
-         wgtiau(:) = 0._wp
-         !
-         !                                !---------------------------------------------------------
-         IF( niaufn == 0 ) THEN           ! Constant IAU forcing 
-            !                             !---------------------------------------------------------
-            DO jt = 1, iiauper
-               wgtiau(jt+nitiaustr-1) = 1.0 / REAL( iiauper )
-            END DO
-            !                             !---------------------------------------------------------
-         ELSEIF ( niaufn == 1 ) THEN      ! Linear hat-like, centred in middle of IAU interval 
-            !                             !---------------------------------------------------------
-            ! Compute the normalization factor
-            znorm = 0._wp
-            IF( MOD( iiauper, 2 ) == 0 ) THEN   ! Even number of time steps in IAU interval
-               imid = iiauper / 2 
-               DO jt = 1, imid
-                  znorm = znorm + REAL( jt )
-               END DO
-               znorm = 2.0 * znorm
-            ELSE                                ! Odd number of time steps in IAU interval
-               imid = ( iiauper + 1 ) / 2        
-               DO jt = 1, imid - 1
-                  znorm = znorm + REAL( jt )
-               END DO
-               znorm = 2.0 * znorm + REAL( imid )
-            ENDIF
-            znorm = 1.0 / znorm
-            !
-            DO jt = 1, imid - 1
-               wgtiau(jt+nitiaustr-1) = REAL( jt ) * znorm
-            END DO
-            DO jt = imid, iiauper
-               wgtiau(jt+nitiaustr-1) = REAL( iiauper - jt + 1 ) * znorm
-            END DO
-            !
-         ENDIF
-
-         ! Test that the integral of the weights over the weighting interval equals 1
-          IF(lwp) THEN
-             WRITE(numout,*)
-             WRITE(numout,*) 'asm_inc_init : IAU weights'
-             WRITE(numout,*) '~~~~~~~~~~~~'
-             WRITE(numout,*) '             time step         IAU  weight'
-             WRITE(numout,*) '             =========     ====================='
-             ztotwgt = 0.0
-             DO jt = 1, icycper
-                ztotwgt = ztotwgt + wgtiau(jt)
-                WRITE(numout,*) '         ', jt, '       ', wgtiau(jt) 
-             END DO   
-             WRITE(numout,*) '         ==================================='
-             WRITE(numout,*) '         Time-integrated weight = ', ztotwgt
-             WRITE(numout,*) '         ==================================='
-          ENDIF
-         
-      ENDIF
-
-      !--------------------------------------------------------------------
-      ! Allocate and initialize the increment arrays
-      !--------------------------------------------------------------------
-
-      ALLOCATE( t_bkginc     (jpi,jpj,jpk) )   ;   t_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( s_bkginc     (jpi,jpj,jpk) )   ;   s_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( u_bkginc     (jpi,jpj,jpk) )   ;   u_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( v_bkginc     (jpi,jpj,jpk) )   ;   v_bkginc     (:,:,:) = 0._wp
-      ALLOCATE( ssh_bkginc   (jpi,jpj)     )   ;   ssh_bkginc   (:,:)   = 0._wp
-      ALLOCATE( seaice_bkginc(jpi,jpj)     )   ;   seaice_bkginc(:,:)   = 0._wp
-#if defined key_asminc
-      ALLOCATE( ssh_iau      (jpi,jpj)     )   ;   ssh_iau      (:,:)   = 0._wp
-#endif
-#if defined key_cice && defined key_asminc
-      ALLOCATE( ndaice_da    (jpi,jpj)     )   ;   ndaice_da    (:,:)   = 0._wp
-#endif
-      !
-      IF ( ln_trainc .OR. ln_dyninc .OR.   &       !--------------------------------------
-         & ln_sshinc .OR. ln_seaiceinc   ) THEN    ! Read the increments from file
-         !                                         !--------------------------------------
-         CALL iom_open( c_asminc, inum )
-         !
-         CALL iom_get( inum, 'time'       , zdate_inc   ) 
-         CALL iom_get( inum, 'z_inc_dateb', z_inc_dateb )
-         CALL iom_get( inum, 'z_inc_datef', z_inc_datef )
-         z_inc_dateb = zdate_inc
-         z_inc_datef = zdate_inc
-         !
-         IF(lwp) THEN
-            WRITE(numout,*) 
-            WRITE(numout,*) 'asm_inc_init : Assimilation increments valid between dates ', z_inc_dateb,' and ', z_inc_datef
-            WRITE(numout,*) '~~~~~~~~~~~~'
-         ENDIF
-         !
-         IF ( ( z_inc_dateb < ndastp + nn_time0*0.0001_wp ) .OR.   &
-            & ( z_inc_datef > ditend_date ) ) &
-            &    CALL ctl_warn( ' Validity time of assimilation increments is ', &
-            &                   ' outside the assimilation interval' )
-
-         IF ( ( ln_asmdin ).AND.( zdate_inc /= ditdin_date ) ) &
-            & CALL ctl_warn( ' Validity time of assimilation increments does ', &
-            &                ' not agree with Direct Initialization time' )
-
-         IF ( ln_trainc ) THEN   
-            CALL iom_get( inum, jpdom_auto, 'bckint', t_bkginc, 1 )
-            CALL iom_get( inum, jpdom_auto, 'bckins', s_bkginc, 1 )
-            ! Apply the masks
-            t_bkginc(:,:,:) = t_bkginc(:,:,:) * tmask(:,:,:)
-            s_bkginc(:,:,:) = s_bkginc(:,:,:) * tmask(:,:,:)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( t_bkginc(:,:,:) ) > 1.0e+10 ) t_bkginc(:,:,:) = 0.0
-            WHERE( ABS( s_bkginc(:,:,:) ) > 1.0e+10 ) s_bkginc(:,:,:) = 0.0
-         ENDIF
-
-         IF ( ln_dyninc ) THEN   
-            CALL iom_get( inum, jpdom_auto, 'bckinu', u_bkginc, 1 )              
-            CALL iom_get( inum, jpdom_auto, 'bckinv', v_bkginc, 1 )              
-            ! Apply the masks
-            u_bkginc(:,:,:) = u_bkginc(:,:,:) * umask(:,:,:)
-            v_bkginc(:,:,:) = v_bkginc(:,:,:) * vmask(:,:,:)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( u_bkginc(:,:,:) ) > 1.0e+10 ) u_bkginc(:,:,:) = 0.0
-            WHERE( ABS( v_bkginc(:,:,:) ) > 1.0e+10 ) v_bkginc(:,:,:) = 0.0
-         ENDIF
-        
-         IF ( ln_sshinc ) THEN
-            CALL iom_get( inum, jpdom_auto, 'bckineta', ssh_bkginc, 1 )
-            ! Apply the masks
-            ssh_bkginc(:,:) = ssh_bkginc(:,:) * tmask(:,:,1)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( ssh_bkginc(:,:) ) > 1.0e+10 ) ssh_bkginc(:,:) = 0.0
-         ENDIF
-
-         IF ( ln_seaiceinc ) THEN
-            CALL iom_get( inum, jpdom_auto, 'bckinseaice', seaice_bkginc, 1 )
-            ! Apply the masks
-            seaice_bkginc(:,:) = seaice_bkginc(:,:) * tmask(:,:,1)
-            ! Set missing increments to 0.0 rather than 1e+20
-            ! to allow for differences in masks
-            WHERE( ABS( seaice_bkginc(:,:) ) > 1.0e+10 ) seaice_bkginc(:,:) = 0.0
-         ENDIF
-         !
-         CALL iom_close( inum )
-         !
-      ENDIF
-      !
-      !                                            !--------------------------------------
-      IF ( ln_dyninc .AND. nn_divdmp > 0 ) THEN    ! Apply divergence damping filter
-         !                                         !--------------------------------------
-         ALLOCATE( zhdiv(jpi,jpj) ) 
-         !
-         DO jt = 1, nn_divdmp
-            !
-            DO jk = 1, jpkm1           ! zhdiv = e1e1 * div
-               zhdiv(:,:) = 0._wp
-               DO_2D( 0, 0, 0, 0 )
-                  zhdiv(ji,jj) = (  e2u(ji  ,jj) * e3u(ji  ,jj,jk,Kmm) * u_bkginc(ji  ,jj,jk)    &
-                     &            - e2u(ji-1,jj) * e3u(ji-1,jj,jk,Kmm) * u_bkginc(ji-1,jj,jk)    &
-                     &            + e1v(ji,jj  ) * e3v(ji,jj  ,jk,Kmm) * v_bkginc(ji,jj  ,jk)    &
-                     &            - e1v(ji,jj-1) * e3v(ji,jj-1,jk,Kmm) * v_bkginc(ji,jj-1,jk)  ) &
-                     &            / e3t(ji,jj,jk,Kmm)
-               END_2D
-               CALL lbc_lnk( 'asminc', zhdiv, 'T', 1. )   ! lateral boundary cond. (no sign change)
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk)                         &
-                     &               + 0.2_wp * ( zhdiv(ji+1,jj) - zhdiv(ji  ,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
-                  v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk)                         &
-                     &               + 0.2_wp * ( zhdiv(ji,jj+1) - zhdiv(ji,jj  ) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
-               END_2D
-            END DO
-            !
-         END DO
-         !
-         DEALLOCATE( zhdiv ) 
-         !
-      ENDIF
-      !
-      !                             !-----------------------------------------------------
-      IF ( ln_asmdin ) THEN         ! Allocate and initialize the background state arrays
-         !                          !-----------------------------------------------------
-         !
-         ALLOCATE( t_bkg  (jpi,jpj,jpk) )   ;   t_bkg  (:,:,:) = 0._wp
-         ALLOCATE( s_bkg  (jpi,jpj,jpk) )   ;   s_bkg  (:,:,:) = 0._wp
-         ALLOCATE( u_bkg  (jpi,jpj,jpk) )   ;   u_bkg  (:,:,:) = 0._wp
-         ALLOCATE( v_bkg  (jpi,jpj,jpk) )   ;   v_bkg  (:,:,:) = 0._wp
-         ALLOCATE( ssh_bkg(jpi,jpj)     )   ;   ssh_bkg(:,:)   = 0._wp
-         !
-         !
-         !--------------------------------------------------------------------
-         ! Read from file the background state at analysis time
-         !--------------------------------------------------------------------
-         !
-         CALL iom_open( c_asmdin, inum )
-         !
-         CALL iom_get( inum, 'rdastp', zdate_bkg ) 
-         !
-         IF(lwp) THEN
-            WRITE(numout,*) 
-            WRITE(numout,*) '   ==>>>  Assimilation background state valid at : ', zdate_bkg
-            WRITE(numout,*)
-         ENDIF
-         !
-         IF ( zdate_bkg /= ditdin_date )   &
-            & CALL ctl_warn( ' Validity time of assimilation background state does', &
-            &                ' not agree with Direct Initialization time' )
-         !
-         IF ( ln_trainc ) THEN   
-            CALL iom_get( inum, jpdom_auto, 'tn', t_bkg )
-            CALL iom_get( inum, jpdom_auto, 'sn', s_bkg )
-            t_bkg(:,:,:) = t_bkg(:,:,:) * tmask(:,:,:)
-            s_bkg(:,:,:) = s_bkg(:,:,:) * tmask(:,:,:)
-         ENDIF
-         !
-         IF ( ln_dyninc ) THEN   
-            CALL iom_get( inum, jpdom_auto, 'un', u_bkg )
-            CALL iom_get( inum, jpdom_auto, 'vn', v_bkg )
-            u_bkg(:,:,:) = u_bkg(:,:,:) * umask(:,:,:)
-            v_bkg(:,:,:) = v_bkg(:,:,:) * vmask(:,:,:)
-         ENDIF
-         !
-         IF ( ln_sshinc ) THEN
-            CALL iom_get( inum, jpdom_auto, 'sshn', ssh_bkg )
-            ssh_bkg(:,:) = ssh_bkg(:,:) * tmask(:,:,1)
-         ENDIF
-         !
-         CALL iom_close( inum )
-         !
-      ENDIF
-      !
-      IF(lwp) WRITE(numout,*) '   ==>>>   Euler time step switch is ', l_1st_euler
-      !
-      IF( lk_asminc ) THEN                            !==  data assimilation  ==!
-         IF( ln_bkgwri )   CALL asm_bkg_wri( nit000 - 1, Kmm )      ! Output background fields
-         IF( ln_asmdin ) THEN                                  ! Direct initialization
-            IF( ln_trainc )   CALL tra_asm_inc( nit000 - 1, Kbb, Kmm, ts    , Krhs )      ! Tracers
-            IF( ln_dyninc )   CALL dyn_asm_inc( nit000 - 1, Kbb, Kmm, uu, vv, Krhs )      ! Dynamics
-            IF( ln_sshinc )   CALL ssh_asm_inc( nit000 - 1, Kbb, Kmm )                    ! SSH
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE asm_inc_init
-   
-   
-   SUBROUTINE tra_asm_inc( kt, Kbb, Kmm, pts, Krhs )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE tra_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the tracer (T and S) assimilation increments
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER                                  , INTENT(in   ) :: kt             ! Current time step
-      INTEGER                                  , INTENT(in   ) :: Kbb, Kmm, Krhs ! Time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts,jpt), INTENT(inout) :: pts            ! active tracers and RHS of tracer equation
-      !
-      INTEGER  :: ji, jj, jk
-      INTEGER  :: it
-      REAL(wp) :: zincwgt  ! IAU weight for current time step
-      REAL (wp), DIMENSION(jpi,jpj,jpk) :: fzptnz ! 3d freezing point values
-      !!----------------------------------------------------------------------
-      !
-      ! freezing point calculation taken from oc_fz_pt (but calculated for all depths) 
-      ! used to prevent the applied increments taking the temperature below the local freezing point 
-      DO jk = 1, jpkm1
-        CALL eos_fzp( pts(:,:,jk,jp_sal,Kmm), fzptnz(:,:,jk), gdept(:,:,jk,Kmm) )
-      END DO
-         !
-         !                             !--------------------------------------
-      IF ( ln_asmiau ) THEN            ! Incremental Analysis Updating
-         !                             !--------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it) / rn_Dt   ! IAU weight for the current time step
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'tra_asm_inc : Tracer IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Update the tracer tendencies
-            DO jk = 1, jpkm1
-               IF (ln_temnofreeze) THEN
-                  ! Do not apply negative increments if the temperature will fall below freezing
-                  WHERE(t_bkginc(:,:,jk) > 0.0_wp .OR. &
-                     &   pts(:,:,jk,jp_tem,Kmm) + pts(:,:,jk,jp_tem,Krhs) + t_bkginc(:,:,jk) * wgtiau(it) > fzptnz(:,:,jk) ) 
-                     pts(:,:,jk,jp_tem,Krhs) = pts(:,:,jk,jp_tem,Krhs) + t_bkginc(:,:,jk) * zincwgt  
-                  END WHERE
-               ELSE
-                  pts(:,:,jk,jp_tem,Krhs) = pts(:,:,jk,jp_tem,Krhs) + t_bkginc(:,:,jk) * zincwgt  
-               ENDIF
-               IF (ln_salfix) THEN
-                  ! Do not apply negative increments if the salinity will fall below a specified
-                  ! minimum value salfixmin
-                  WHERE(s_bkginc(:,:,jk) > 0.0_wp .OR. &
-                     &   pts(:,:,jk,jp_sal,Kmm) + pts(:,:,jk,jp_sal,Krhs) + s_bkginc(:,:,jk) * wgtiau(it) > salfixmin ) 
-                     pts(:,:,jk,jp_sal,Krhs) = pts(:,:,jk,jp_sal,Krhs) + s_bkginc(:,:,jk) * zincwgt
-                  END WHERE
-               ELSE
-                  pts(:,:,jk,jp_sal,Krhs) = pts(:,:,jk,jp_sal,Krhs) + s_bkginc(:,:,jk) * zincwgt
-               ENDIF
-            END DO
-            !
-         ENDIF
-         !
-         IF ( kt == nitiaufin_r + 1  ) THEN   ! For bias crcn to work
-            DEALLOCATE( t_bkginc )
-            DEALLOCATE( s_bkginc )
-         ENDIF
-         !                             !--------------------------------------
-      ELSEIF ( ln_asmdin ) THEN        ! Direct Initialization
-         !                             !--------------------------------------
-         !            
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.  ! Force Euler forward step
-            !
-            ! Initialize the now fields with the background + increment
-            IF (ln_temnofreeze) THEN
-               ! Do not apply negative increments if the temperature will fall below freezing
-               WHERE( t_bkginc(:,:,:) > 0.0_wp .OR. pts(:,:,:,jp_tem,Kmm) + t_bkginc(:,:,:) > fzptnz(:,:,:) ) 
-                  pts(:,:,:,jp_tem,Kmm) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
-               END WHERE
-            ELSE
-               pts(:,:,:,jp_tem,Kmm) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
-            ENDIF
-            IF (ln_salfix) THEN
-               ! Do not apply negative increments if the salinity will fall below a specified
-               ! minimum value salfixmin
-               WHERE( s_bkginc(:,:,:) > 0.0_wp .OR. pts(:,:,:,jp_sal,Kmm) + s_bkginc(:,:,:) > salfixmin ) 
-                  pts(:,:,:,jp_sal,Kmm) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
-               END WHERE
-            ELSE
-               pts(:,:,:,jp_sal,Kmm) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
-            ENDIF
-
-            pts(:,:,:,:,Kbb) = pts(:,:,:,:,Kmm)                 ! Update before fields
-
-            CALL eos( pts(:,:,:,:,Kbb), rhd, rhop, gdept_0(:,:,:) )  ! Before potential and in situ densities
-!!gm  fabien
-!            CALL eos( pts(:,:,:,:,Kbb), rhd, rhop )                ! Before potential and in situ densities
-!!gm
-
-            IF( ln_zps .AND. .NOT. lk_c1d .AND. .NOT. ln_isfcav)           &
-               &  CALL zps_hde    ( kt, Kmm, jpts, pts(:,:,:,:,Kbb), gtsu, gtsv,        &  ! Partial steps: before horizontal gradient
-               &                              rhd, gru , grv               )  ! of t, s, rd at the last ocean level
-            IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav)                       &
-               &  CALL zps_hde_isf( nit000, Kmm, jpts, pts(:,:,:,:,Kbb), gtsu, gtsv, gtui, gtvi,    &  ! Partial steps for top cell (ISF)
-               &                                  rhd, gru , grv , grui, grvi          )  ! of t, s, rd at the last ocean level
-
-            DEALLOCATE( t_bkginc )
-            DEALLOCATE( s_bkginc )
-            DEALLOCATE( t_bkg    )
-            DEALLOCATE( s_bkg    )
-         ENDIF
-         !  
-      ENDIF
-      ! Perhaps the following call should be in step
-      IF ( ln_seaiceinc  )   CALL seaice_asm_inc ( kt )   ! apply sea ice concentration increment
-      !
-   END SUBROUTINE tra_asm_inc
-
-
-   SUBROUTINE dyn_asm_inc( kt, Kbb, Kmm, puu, pvv, Krhs )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE dyn_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the dynamics (u and v) assimilation increments.
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT( in )  ::  kt             ! ocean time-step index
-      INTEGER                             , INTENT( in )  ::  Kbb, Kmm, Krhs ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv       ! ocean velocities and RHS of momentum equation
-      !
-      INTEGER :: jk
-      INTEGER :: it
-      REAL(wp) :: zincwgt  ! IAU weight for current time step
-      !!----------------------------------------------------------------------
-      !
-      !                          !--------------------------------------------
-      IF ( ln_asmiau ) THEN      ! Incremental Analysis Updating
-         !                       !--------------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it) / rn_Dt   ! IAU weight for the current time step
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'dyn_asm_inc : Dynamics IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Update the dynamic tendencies
-            DO jk = 1, jpkm1
-               puu(:,:,jk,Krhs) = puu(:,:,jk,Krhs) + u_bkginc(:,:,jk) * zincwgt
-               pvv(:,:,jk,Krhs) = pvv(:,:,jk,Krhs) + v_bkginc(:,:,jk) * zincwgt
-            END DO
-            !
-            IF ( kt == nitiaufin_r ) THEN
-               DEALLOCATE( u_bkginc )
-               DEALLOCATE( v_bkginc )
-            ENDIF
-            !
-         ENDIF
-         !                          !-----------------------------------------
-      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
-         !                          !-----------------------------------------
-         !         
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.                    ! Force Euler forward step
-            !
-            ! Initialize the now fields with the background + increment
-            puu(:,:,:,Kmm) = u_bkg(:,:,:) + u_bkginc(:,:,:)
-            pvv(:,:,:,Kmm) = v_bkg(:,:,:) + v_bkginc(:,:,:)  
-            !
-            puu(:,:,:,Kbb) = puu(:,:,:,Kmm)         ! Update before fields
-            pvv(:,:,:,Kbb) = pvv(:,:,:,Kmm)
-            !
-            DEALLOCATE( u_bkg    )
-            DEALLOCATE( v_bkg    )
-            DEALLOCATE( u_bkginc )
-            DEALLOCATE( v_bkginc )
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE dyn_asm_inc
-
-
-   SUBROUTINE ssh_asm_inc( kt, Kbb, Kmm )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE ssh_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the sea surface height assimilation increment.
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(IN) :: kt         ! Current time step
-      INTEGER, INTENT(IN) :: Kbb, Kmm   ! Current time step
-      !
-      INTEGER :: it
-      INTEGER :: jk
-      REAL(wp) :: zincwgt  ! IAU weight for current time step
-      !!----------------------------------------------------------------------
-      !
-      !                             !-----------------------------------------
-      IF ( ln_asmiau ) THEN         ! Incremental Analysis Updating
-         !                          !-----------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it) / rn_Dt   ! IAU weight for the current time step
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'ssh_asm_inc : SSH IAU at time step = ', &
-                  &  kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Save the tendency associated with the IAU weighted SSH increment
-            ! (applied in dynspg.*)
-#if defined key_asminc
-            ssh_iau(:,:) = ssh_bkginc(:,:) * zincwgt
-#endif
-            !
-         ELSE IF( kt == nitiaufin_r+1 ) THEN
-            !
-            ! test on ssh_bkginc needed as ssh_asm_inc is called twice by time step
-            IF (ALLOCATED(ssh_bkginc)) DEALLOCATE( ssh_bkginc )
-            !
-#if defined key_asminc
-            ssh_iau(:,:) = 0._wp
-#endif
-            !
-         ENDIF
-         !                          !-----------------------------------------
-      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
-         !                          !-----------------------------------------
-         !
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.                            ! Force Euler forward step
-            !
-            ssh(:,:,Kmm) = ssh_bkg(:,:) + ssh_bkginc(:,:)   ! Initialize the now fields the background + increment
-            !
-            ssh(:,:,Kbb) = ssh(:,:,Kmm)                        ! Update before fields
-!!st11
-#if ! defined key_qco
-            e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-#endif
-!!st11
-!!gm why not e3u(:,:,:,Kbb), e3v(:,:,:,Kbb), gdept(:,:,jk,Kbb) ????
-            !
-            DEALLOCATE( ssh_bkg    )
-            DEALLOCATE( ssh_bkginc )
-            !
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE ssh_asm_inc
-
-
-   SUBROUTINE ssh_asm_div( kt, Kbb, Kmm, phdivn )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ssh_asm_div  ***
-      !!
-      !! ** Purpose :   ssh increment with z* is incorporated via a correction of the local divergence          
-      !!                across all the water column
-      !!
-      !! ** Method  :
-      !!                CAUTION : sshiau is positive (inflow) decreasing the
-      !!                          divergence and expressed in m/s
-      !!
-      !! ** Action  :   phdivn   decreased by the ssh increment
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(IN) :: kt                               ! ocean time-step index
-      INTEGER, INTENT(IN) :: Kbb, Kmm                         ! time level indices
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   phdivn   ! horizontal divergence
-      !!
-      INTEGER  ::   jk                                        ! dummy loop index
-      REAL(wp), DIMENSION(:,:)  , POINTER       ::   ztim     ! local array
-      !!----------------------------------------------------------------------
-      ! 
-#if defined key_asminc
-      CALL ssh_asm_inc( kt, Kbb, Kmm ) !==   (calculate increments)
-      !
-      IF( ln_linssh ) THEN 
-         phdivn(:,:,1) = phdivn(:,:,1) - ssh_iau(:,:) / e3t(:,:,1,Kmm) * tmask(:,:,1)
-      ELSE 
-         ALLOCATE( ztim(jpi,jpj) )
-         ztim(:,:) = ssh_iau(:,:) / ( ht(:,:) + 1.0 - ssmask(:,:) )
-         DO jk = 1, jpkm1                                 
-            phdivn(:,:,jk) = phdivn(:,:,jk) - ztim(:,:) * tmask(:,:,jk) 
-         END DO
-         !
-         DEALLOCATE(ztim)
-      ENDIF
-#endif
-      !
-   END SUBROUTINE ssh_asm_div
-
-
-   SUBROUTINE seaice_asm_inc( kt, kindic )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE seaice_asm_inc  ***
-      !!          
-      !! ** Purpose : Apply the sea ice assimilation increment.
-      !!
-      !! ** Method  : Direct initialization or Incremental Analysis Updating.
-      !!
-      !! ** Action  : 
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in)           ::   kt       ! Current time step
-      INTEGER, INTENT(in), OPTIONAL ::   kindic   ! flag for disabling the deallocation
-      !
-      INTEGER  ::   it
-      REAL(wp) ::   zincwgt   ! IAU weight for current time step
-#if defined key_si3
-      REAL(wp), DIMENSION(jpi,jpj) ::   zofrld, zohicif, zseaicendg, zhicifinc
-      REAL(wp) ::   zhicifmin = 0.5_wp      ! ice minimum depth in metres
-#endif
-      !!----------------------------------------------------------------------
-      !
-      !                             !-----------------------------------------
-      IF ( ln_asmiau ) THEN         ! Incremental Analysis Updating
-         !                          !-----------------------------------------
-         !
-         IF ( ( kt >= nitiaustr_r ).AND.( kt <= nitiaufin_r ) ) THEN
-            !
-            it = kt - nit000 + 1
-            zincwgt = wgtiau(it)      ! IAU weight for the current time step 
-            ! note this is not a tendency so should not be divided by rn_Dt (as with the tracer and other increments)
-            !
-            IF(lwp) THEN
-               WRITE(numout,*) 
-               WRITE(numout,*) 'seaice_asm_inc : sea ice conc IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
-               WRITE(numout,*) '~~~~~~~~~~~~'
-            ENDIF
-            !
-            ! Sea-ice : SI3 case
-            !
-#if defined key_si3
-            zofrld (:,:) = 1._wp - at_i(:,:)
-            zohicif(:,:) = hm_i(:,:)
-            !
-            at_i  (:,:) = 1. - MIN( MAX( 1.-at_i  (:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
-            at_i_b(:,:) = 1. - MIN( MAX( 1.-at_i_b(:,:) - seaice_bkginc(:,:) * zincwgt, 0.0_wp), 1.0_wp)
-            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
-            !
-            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
-            !
-            ! Nudge sea ice depth to bring it up to a required minimum depth
-            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
-               zhicifinc(:,:) = (zhicifmin - hm_i(:,:)) * zincwgt    
-            ELSEWHERE
-               zhicifinc(:,:) = 0.0_wp
-            END WHERE
-            !
-            ! nudge ice depth
-            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
-            !
-            ! seaice salinity balancing (to add)
-#endif
-            !
-#if defined key_cice && defined key_asminc
-            ! Sea-ice : CICE case. Pass ice increment tendency into CICE
-            ndaice_da(:,:) = seaice_bkginc(:,:) * zincwgt / rn_Dt
-#endif
-            !
-            IF ( kt == nitiaufin_r ) THEN
-               DEALLOCATE( seaice_bkginc )
-            ENDIF
-            !
-         ELSE
-            !
-#if defined key_cice && defined key_asminc
-            ndaice_da(:,:) = 0._wp        ! Sea-ice : CICE case. Zero ice increment tendency into CICE
-#endif
-            !
-         ENDIF
-         !                          !-----------------------------------------
-      ELSEIF ( ln_asmdin ) THEN     ! Direct Initialization
-         !                          !-----------------------------------------
-         !
-         IF ( kt == nitdin_r ) THEN
-            !
-            l_1st_euler = .TRUE.              ! Force Euler forward step
-            !
-            ! Sea-ice : SI3 case
-            !
-#if defined key_si3
-            zofrld (:,:) = 1._wp - at_i(:,:)
-            zohicif(:,:) = hm_i(:,:)
-            ! 
-            ! Initialize the now fields the background + increment
-            at_i(:,:) = 1. - MIN( MAX( 1.-at_i(:,:) - seaice_bkginc(:,:), 0.0_wp), 1.0_wp)
-            at_i_b(:,:) = at_i(:,:) 
-            fr_i(:,:) = at_i(:,:)        ! adjust ice fraction
-            !
-            zseaicendg(:,:) = zofrld(:,:) - (1. - at_i(:,:))   ! find out actual sea ice nudge applied
-            !
-            ! Nudge sea ice depth to bring it up to a required minimum depth
-            WHERE( zseaicendg(:,:) > 0.0_wp .AND. hm_i(:,:) < zhicifmin ) 
-               zhicifinc(:,:) = zhicifmin - hm_i(:,:)
-            ELSEWHERE
-               zhicifinc(:,:) = 0.0_wp
-            END WHERE
-            !
-            ! nudge ice depth
-            hm_i (:,:) = hm_i (:,:) + zhicifinc(:,:)
-            !
-            ! seaice salinity balancing (to add)
-#endif
-            !
-#if defined key_cice && defined key_asminc
-            ! Sea-ice : CICE case. Pass ice increment tendency into CICE
-           ndaice_da(:,:) = seaice_bkginc(:,:) / rn_Dt
-#endif
-            IF ( .NOT. PRESENT(kindic) ) THEN
-               DEALLOCATE( seaice_bkginc )
-            END IF
-            !
-         ELSE
-            !
-#if defined key_cice && defined key_asminc
-            ndaice_da(:,:) = 0._wp     ! Sea-ice : CICE case. Zero ice increment tendency into CICE
-#endif
-            !
-         ENDIF
-
-!#if defined defined key_si3 || defined key_cice
-!
-!            IF (ln_seaicebal ) THEN       
-!             !! balancing salinity increments
-!             !! simple case from limflx.F90 (doesn't include a mass flux)
-!             !! assumption is that as ice concentration is reduced or increased
-!             !! the snow and ice depths remain constant
-!             !! note that snow is being created where ice concentration is being increased
-!             !! - could be more sophisticated and
-!             !! not do this (but would need to alter h_snow)
-!
-!             usave(:,:,:)=sb(:,:,:)   ! use array as a temporary store
-!
-!             DO jj = 1, jpj
-!               DO ji = 1, jpi 
-!           ! calculate change in ice and snow mass per unit area
-!           ! positive values imply adding salt to the ocean (results from ice formation)
-!           ! fwf : ice formation and melting
-!
-!                 zfons = ( -nfresh_da(ji,jj)*soce + nfsalt_da(ji,jj) )*rn_Dt
-!
-!           ! change salinity down to mixed layer depth
-!                 mld=hmld_kara(ji,jj)
-!
-!           ! prevent small mld
-!           ! less than 10m can cause salinity instability 
-!                 IF (mld < 10) mld=10
-!
-!           ! set to bottom of a level 
-!                 DO jk = jpk-1, 2, -1
-!                   IF ((mld > gdepw(ji,jj,jk,Kmm)) .and. (mld < gdepw(ji,jj,jk+1,Kmm))) THEN 
-!                     mld=gdepw(ji,jj,jk+1,Kmm)
-!                     jkmax=jk
-!                   ENDIF
-!                 ENDDO
-!
-!            ! avoid applying salinity balancing in shallow water or on land
-!            ! 
-!
-!            ! dsal_ocn (psu kg m^-2) / (kg m^-3 * m)
-!
-!                 dsal_ocn=0.0_wp
-!                 sal_thresh=5.0_wp        ! minimum salinity threshold for salinity balancing
-!
-!                 if (tmask(ji,jj,1) > 0 .AND. tmask(ji,jj,jkmax) > 0 ) &
-!                              dsal_ocn = zfons / (rhop(ji,jj,1) * mld)
-!
-!           ! put increments in for levels in the mixed layer
-!           ! but prevent salinity below a threshold value 
-!
-!                   DO jk = 1, jkmax              
-!
-!                     IF (dsal_ocn > 0.0_wp .or. sb(ji,jj,jk)+dsal_ocn > sal_thresh) THEN 
-!                           sb(ji,jj,jk) = sb(ji,jj,jk) + dsal_ocn
-!                           sn(ji,jj,jk) = sn(ji,jj,jk) + dsal_ocn
-!                     ENDIF
-!
-!                   ENDDO
-!
-!      !            !  salt exchanges at the ice/ocean interface
-!      !            zpmess         = zfons / rDt_ice    ! rDt_ice is ice timestep
-!      !
-!      !! Adjust fsalt. A +ve fsalt means adding salt to ocean
-!      !!           fsalt(ji,jj) =  fsalt(ji,jj) + zpmess     ! adjust fsalt  
-!      !!               
-!      !!           emps(ji,jj) = emps(ji,jj) + zpmess        ! or adjust emps (see icestp1d) 
-!      !!                                                     ! E-P (kg m-2 s-2)
-!      !            emp(ji,jj) = emp(ji,jj) + zpmess          ! E-P (kg m-2 s-2)
-!               ENDDO !ji
-!             ENDDO !jj!
-!
-!            ENDIF !ln_seaicebal
-!
-!#endif
-         !
-      ENDIF
-      !
-   END SUBROUTINE seaice_asm_inc
-   
-   !!======================================================================
-END MODULE asminc
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/diawri.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/diawri.F90	(revision 14059)
+++ 	(revision )
@@ -1,985 +1,0 @@
-MODULE diawri
-   !!======================================================================
-   !!                     ***  MODULE  diawri  ***
-   !! Ocean diagnostics :  write ocean output files
-   !!=====================================================================
-   !! History :  OPA  ! 1991-03  (M.-A. Foujols)  Original code
-   !!            4.0  ! 1991-11  (G. Madec)
-   !!                 ! 1992-06  (M. Imbard)  correction restart file
-   !!                 ! 1992-07  (M. Imbard)  split into diawri and rstwri
-   !!                 ! 1993-03  (M. Imbard)  suppress writibm
-   !!                 ! 1998-01  (C. Levy)  NETCDF format using ioipsl INTERFACE
-   !!                 ! 1999-02  (E. Guilyardi)  name of netCDF files + variables
-   !!            8.2  ! 2000-06  (M. Imbard)  Original code (diabort.F)
-   !!   NEMO     1.0  ! 2002-06  (A.Bozec, E. Durand)  Original code (diainit.F)
-   !!             -   ! 2002-09  (G. Madec)  F90: Free form and module
-   !!             -   ! 2002-12  (G. Madec)  merge of diabort and diainit, F90
-   !!                 ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.2  ! 2008-11  (B. Lemaire) creation from old diawri
-   !!            3.7  ! 2014-01  (G. Madec) remove eddy induced velocity from no-IOM output
-   !!                 !                     change name of output variables in dia_wri_state
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dia_wri       : create the standart output files
-   !!   dia_wri_state : create an output NetCDF file for a single instantaeous ocean state and forcing fields
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers 
-   USE isf_oce
-   USE isfcpl
-   USE abl            ! abl variables in case ln_abl = .true.
-   USE dom_oce        ! ocean space and time domain
-   USE phycst         ! physical constants
-   USE dianam         ! build name of file (routine)
-   USE diahth         ! thermocline diagnostics
-   USE dynadv   , ONLY: ln_dynadv_vec
-   USE icb_oce        ! Icebergs
-   USE icbdia         ! Iceberg budgets
-   USE ldftra         ! lateral physics: eddy diffusivity coef.
-   USE ldfdyn         ! lateral physics: eddy viscosity   coef.
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbc_ice        ! Surface boundary condition: ice fields
-   USE sbcssr         ! restoring term toward SST/SSS climatology
-   USE sbcwave        ! wave parameters
-   USE wet_dry        ! wetting and drying
-   USE zdf_oce        ! ocean vertical physics
-   USE zdfdrg         ! ocean vertical physics: top/bottom friction
-   USE zdfmxl         ! mixed layer
-   !
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE in_out_manager ! I/O manager
-   USE dia25h         ! 25h Mean output
-   USE iom            ! 
-   USE ioipsl         ! 
-
-#if defined key_si3
-   USE ice 
-   USE icewri 
-#endif
-   USE lib_mpp         ! MPP library
-   USE timing          ! preformance summary
-   USE diu_bulk        ! diurnal warm layer
-   USE diu_coolskin    ! Cool skin
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dia_wri                 ! routines called by step.F90
-   PUBLIC   dia_wri_state
-   PUBLIC   dia_wri_alloc           ! Called by nemogcm module
-#if ! defined key_iomput   
-   PUBLIC   dia_wri_alloc_abl       ! Called by sbcabl  module (if ln_abl = .true.)
-#endif
-   INTEGER ::   nid_T, nz_T, nh_T, ndim_T, ndim_hT   ! grid_T file
-   INTEGER ::          nb_T              , ndim_bT   ! grid_T file
-   INTEGER ::   nid_U, nz_U, nh_U, ndim_U, ndim_hU   ! grid_U file
-   INTEGER ::   nid_V, nz_V, nh_V, ndim_V, ndim_hV   ! grid_V file
-   INTEGER ::   nid_W, nz_W, nh_W                    ! grid_W file
-   INTEGER ::   nid_A, nz_A, nh_A, ndim_A, ndim_hA   ! grid_ABL file   
-   INTEGER ::   ndex(1)                              ! ???
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hT, ndex_hU, ndex_hV
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hA, ndex_A ! ABL
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_T, ndex_U, ndex_V
-   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_bT
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-!!st12
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: diawri.F90 12667 2020-04-03 14:22:29Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_iomput
-   !!----------------------------------------------------------------------
-   !!   'key_iomput'                                        use IOM library
-   !!----------------------------------------------------------------------
-   INTEGER FUNCTION dia_wri_alloc()
-      !
-      dia_wri_alloc = 0
-      !
-   END FUNCTION dia_wri_alloc
-
-   
-   SUBROUTINE dia_wri( kt, Kmm )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_wri  ***
-      !!                   
-      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
-      !!      NETCDF format is used by default 
-      !!
-      !! ** Method  :  use iom_put
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
-      INTEGER, INTENT( in ) ::   Kmm     ! ocean time level index
-      !!
-      INTEGER ::   ji, jj, jk       ! dummy loop indices
-      INTEGER ::   ikbot            ! local integer
-      REAL(wp)::   zztmp , zztmpx   ! local scalar
-      REAL(wp)::   zztmp2, zztmpy   !   -      -
-      REAL(wp)::   ze3              !   -      -
-      REAL(wp), DIMENSION(jpi,jpj)     ::   z2d   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   z3d   ! 3D workspace
-      !!----------------------------------------------------------------------
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
-      ! 
-      ! Output the initial state and forcings
-      IF( ninist == 1 ) THEN                       
-         CALL dia_wri_state( Kmm, 'output.init' )
-         ninist = 0
-      ENDIF
-
-      ! Output of initial vertical scale factor
-      CALL iom_put("e3t_0", e3t_0(:,:,:) )
-      CALL iom_put("e3u_0", e3u_0(:,:,:) )
-      CALL iom_put("e3v_0", e3v_0(:,:,:) )
-      !
-!!st13
-#if ! defined key_qco
-      IF ( iom_use("e3t") .OR. iom_use("e3tdef") ) THEN  ! time-varying e3t
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3t(:,:,jk,Kmm)
-         END DO
-         CALL iom_put( "e3t"     ,     z3d(:,:,:) )
-         CALL iom_put( "e3tdef"  , ( ( z3d(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 ) 
-      ENDIF 
-      IF ( iom_use("e3u") ) THEN                         ! time-varying e3u
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3u(:,:,jk,Kmm)
-         END DO 
-         CALL iom_put( "e3u" , z3d(:,:,:) )
-      ENDIF
-      IF ( iom_use("e3v") ) THEN                         ! time-varying e3v
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3v(:,:,jk,Kmm)
-         END DO 
-         CALL iom_put( "e3v" , z3d(:,:,:) )
-      ENDIF
-      IF ( iom_use("e3w") ) THEN                         ! time-varying e3w
-         DO jk = 1, jpk
-            z3d(:,:,jk) =  e3w(:,:,jk,Kmm)
-         END DO 
-         CALL iom_put( "e3w" , z3d(:,:,:) )
-      ENDIF
-#endif 
-!!st13
-      IF( ll_wd ) THEN
-         CALL iom_put( "ssh" , (ssh(:,:,Kmm)+ssh_ref)*tmask(:,:,1) )   ! sea surface height (brought back to the reference used for wetting and drying)
-      ELSE
-         CALL iom_put( "ssh" , ssh(:,:,Kmm) )                          ! sea surface height
-      ENDIF
-
-!!an 
-        IF( iom_use("ht") )   &                  ! water column at t-point
-         CALL iom_put( "ht" , ht_0(:,:) + ssh(:,:,Kmm) )
-      !
-      IF( iom_use("hu") )   THEN                   ! water column at u-point
-         z2d(:,:) = 0._wp
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.5_wp * ( e3t(ji  ,jj,1,Kmm) * e1e2t(ji  ,jj)  &
-               &                  + e3t(ji+1,jj,1,Kmm) * e1e2t(ji+1,jj)  ) * r1_e1e2u(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'U', 1._wp )
-         CALL iom_put( "hu", z2d ) 
-      ENDIF
-     !                    
-      IF( iom_use("hv") )   THEN                  ! water column at v-point
-         z2d(:,:) = 0._wp
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.5_wp * (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1)   &
-              &                    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  )   ) * r1_e1e2v(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'V', 1._wp )
-         CALL iom_put( "hv", z2d )    
-      ENDIF             
-      !
-      IF( iom_use("hf") )  THEN                    ! water column at f-point
-         z2d(:,:) = 0._wp
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.25_wp * (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
-              &                     + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
-         END_2D
-         z2d(:,:) = z2d(:,:) * ssfmask(:,:)
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1._wp )
-         CALL iom_put( "hf", z2d )   
-      ENDIF              
-!!an
-
-      IF( iom_use("wetdep") )   &                  ! wet depth
-         CALL iom_put( "wetdep" , ht_0(:,:) + ssh(:,:,Kmm) )
-
-      IF ( iom_use("taubot") ) THEN                ! bottom stress
-         zztmp = rho0 * 0.25
-         z2d(:,:) = 0._wp
-         DO_2D( 0, 0, 0, 0 )
-            zztmp2 = (  ( rCdU_bot(ji+1,jj)+rCdU_bot(ji  ,jj) ) * uu(ji  ,jj,mbku(ji  ,jj),Kmm)  )**2   &
-               &   + (  ( rCdU_bot(ji  ,jj)+rCdU_bot(ji-1,jj) ) * uu(ji-1,jj,mbku(ji-1,jj),Kmm)  )**2   &
-               &   + (  ( rCdU_bot(ji,jj+1)+rCdU_bot(ji,jj  ) ) * vv(ji,jj  ,mbkv(ji,jj  ),Kmm)  )**2   &
-               &   + (  ( rCdU_bot(ji,jj  )+rCdU_bot(ji,jj-1) ) * vv(ji,jj-1,mbkv(ji,jj-1),Kmm)  )**2
-            z2d(ji,jj) = zztmp * SQRT( zztmp2 ) * tmask(ji,jj,1) 
-            !
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1. )
-         CALL iom_put( "taubot", z2d )           
-      ENDIF
-      !  
-      CALL iom_put(  "ssu" , uu(:,:,1,Kmm) )            ! surface i-current
-      CALL iom_put(  "ssv" , vv(:,:,1,Kmm) )            ! surface j-current
-      CALL iom_put(  "woce", ww )                       ! vertical velocity
-      !
-      
-      IF ( iom_use("sKE") ) THEN                        ! surface kinetic energy at T point
-         z2d(:,:) = 0._wp
-         DO_2D( 0, 0, 0, 0 )
-            z2d(ji,jj) =    0.25_wp * ( uu(ji  ,jj,1,Kmm) * uu(ji  ,jj,1,Kmm) * e1e2u(ji  ,jj) * e3u(ji  ,jj,1,Kmm)  &
-               &                      + uu(ji-1,jj,1,Kmm) * uu(ji-1,jj,1,Kmm) * e1e2u(ji-1,jj) * e3u(ji-1,jj,1,Kmm)  &
-               &                      + vv(ji,jj  ,1,Kmm) * vv(ji,jj  ,1,Kmm) * e1e2v(ji,jj  ) * e3v(ji,jj  ,1,Kmm)  & 
-               &                      + vv(ji,jj-1,1,Kmm) * vv(ji,jj-1,1,Kmm) * e1e2v(ji,jj-1) * e3v(ji,jj-1,1,Kmm)  )  &
-               &                    * r1_e1e2t(ji,jj) / e3t(ji,jj,1,Kmm) * tmask(ji,jj,1)
-         END_2D
-         !
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1. )
-         IF ( iom_use("sKE" ) )  CALL iom_put( "sKE" , z2d )   
-                           
-      ENDIF
-           
-!!an sKEf
-      IF ( iom_use("sKEf") ) THEN                        ! surface kinetic energy at F point
-         z2d(:,:) = 0._wp                                ! CAUTION : only valid in SWE, not with bathymetry
-         DO_2D( 0, 0, 0, 0 )
-            z2d(ji,jj) =    0.25_wp * ( uu(ji,jj  ,1,Kmm) * uu(ji,jj  ,1,Kmm) * e1e2u(ji,jj  ) * e3u(ji,jj  ,1,Kmm)  &
-               &                      + uu(ji,jj+1,1,Kmm) * uu(ji,jj+1,1,Kmm) * e1e2u(ji,jj+1) * e3u(ji,jj+1,1,Kmm)  &
-               &                      + vv(ji  ,jj,1,Kmm) * vv(ji,jj  ,1,Kmm) * e1e2v(ji  ,jj) * e3v(ji  ,jj,1,Kmm)  & 
-               &                      + vv(ji+1,jj,1,Kmm) * vv(ji+1,jj,1,Kmm) * e1e2v(ji+1,jj) * e3v(ji+1,jj,1,Kmm)  )  &
-               &                    * r1_e1e2f(ji,jj) / e3f(ji,jj,1) * ssfmask(ji,jj)
-         END_2D
-         !
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "sKEf", z2d )                     
-      ENDIF
-!!an
-      !
-      CALL iom_put( "hdiv", hdiv )                  ! Horizontal divergence
-      !
-      ! Output of vorticity terms
-      IF ( iom_use("relvor")    .OR. iom_use("plavor")    .OR.   &
-         & iom_use("relpotvor") .OR. iom_use("abspotvor") .OR.   &
-         & iom_use("Ens")                                        ) THEN
-         !
-         z2d(:,:) = 0._wp 
-         ze3 = 0._wp 
-         DO_2D( 1, 0, 1, 0 )
-            z2d(ji,jj) = (   e2v(ji+1,jj  ) * vv(ji+1,jj  ,1,Kmm) - e2v(ji,jj) * vv(ji,jj,1,Kmm)    &
-            &              - e1u(ji  ,jj+1) * uu(ji  ,jj+1,1,Kmm) + e1u(ji,jj) * uu(ji,jj,1,Kmm)  ) * r1_e1e2f(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "relvor", z2d )                  ! relative vorticity ( zeta ) 
-         !
-         CALL iom_put( "plavor", ff_f )                 ! planetary vorticity ( f )
-         !
-         DO_2D( 1, 0, 1, 0 )  
-            ze3 = (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
-              &    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
-            IF( ze3 /= 0._wp ) THEN   ;   ze3 = 4._wp / ze3
-            ELSE                      ;   ze3 = 0._wp
-            ENDIF
-            z2d(ji,jj) = ze3 * z2d(ji,jj) 
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "relpotvor", z2d )                  ! relative potential vorticity (zeta/h)
-         !
-         DO_2D( 1, 0, 1, 0 )
-            ze3 = (  e3t(ji,jj+1,1,Kmm) * e1e2t(ji,jj+1) + e3t(ji+1,jj+1,1,Kmm) * e1e2t(ji+1,jj+1)    &
-              &    + e3t(ji,jj  ,1,Kmm) * e1e2t(ji,jj  ) + e3t(ji+1,jj  ,1,Kmm) * e1e2t(ji+1,jj  )  ) * r1_e1e2f(ji,jj)
-            IF( ze3 /= 0._wp ) THEN   ;   ze3 = 4._wp / ze3
-            ELSE                      ;   ze3 = 0._wp
-            ENDIF
-            z2d(ji,jj) = ze3 * ff_f(ji,jj) + z2d(ji,jj) 
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "abspotvor", z2d )                  ! absolute potential vorticity ( q )
-         !
-         DO_2D( 1, 0, 1, 0 )  
-            z2d(ji,jj) = 0.5_wp * z2d(ji,jj)  * z2d(ji,jj) 
-         END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'F', 1. )
-         CALL iom_put( "Ens", z2d )                        ! potential enstrophy ( 1/2*q2 )
-         !
-      ENDIF
-      
-      !
-      IF( ln_timing )   CALL timing_stop('dia_wri')
-      !
-   END SUBROUTINE dia_wri
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option                                  use IOIPSL  library
-   !!----------------------------------------------------------------------
-
-   INTEGER FUNCTION dia_wri_alloc()
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(2) :: ierr
-      !!----------------------------------------------------------------------
-      IF( nn_write == -1 ) THEN
-         dia_wri_alloc = 0
-      ELSE    
-         ierr = 0
-         ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     &
-            &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     &
-            &      ndex_hV(jpi*jpj) , ndex_V(jpi*jpj*jpk) , STAT=ierr(1) )
-         !
-         dia_wri_alloc = MAXVAL(ierr)
-         CALL mpp_sum( 'diawri', dia_wri_alloc )
-         !
-      ENDIF
-      !
-   END FUNCTION dia_wri_alloc
- 
-   INTEGER FUNCTION dia_wri_alloc_abl()
-      !!----------------------------------------------------------------------
-	  ALLOCATE(   ndex_hA(jpi*jpj), ndex_A (jpi*jpj*jpkam1), STAT=dia_wri_alloc_abl)
-      CALL mpp_sum( 'diawri', dia_wri_alloc_abl )
-      !
-   END FUNCTION dia_wri_alloc_abl
-
-   
-   SUBROUTINE dia_wri( kt, Kmm )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_wri  ***
-      !!                   
-      !! ** Purpose :   Standard output of opa: dynamics and tracer fields 
-      !!      NETCDF format is used by default 
-      !!
-      !! ** Method  :   At the beginning of the first time step (nit000), 
-      !!      define all the NETCDF files and fields
-      !!      At each time step call histdef to compute the mean if ncessary
-      !!      Each nn_write time step, output the instantaneous or mean fields
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      INTEGER, INTENT( in ) ::   Kmm  ! ocean time level index
-      !
-      LOGICAL ::   ll_print = .FALSE.                        ! =T print and flush numout
-      CHARACTER (len=40) ::   clhstnam, clop, clmx           ! local names
-      INTEGER  ::   inum = 11                                ! temporary logical unit
-      INTEGER  ::   ji, jj, jk                               ! dummy loop indices
-      INTEGER  ::   ierr                                     ! error code return from allocation
-      INTEGER  ::   iimi, iima, ipk, it, itmod, ijmi, ijma   ! local integers
-      INTEGER  ::   ipka                                     ! ABL
-      INTEGER  ::   jn, ierror                               ! local integers
-      REAL(wp) ::   zsto, zout, zmax, zjulian                ! local scalars
-      !
-      REAL(wp), DIMENSION(jpi,jpj)   :: zw2d       ! 2D workspace
-!!st14
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zw3d, ze3t, zgdept       ! 3D workspace
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zw3d_abl   ! ABL 3D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( ninist == 1 ) THEN     !==  Output the initial state and forcings  ==!
-         CALL dia_wri_state( Kmm, 'output.init' )
-         ninist = 0
-      ENDIF
-      !
-      IF( nn_write == -1 )   RETURN   ! we will never do any output
-      ! 
-      IF( ln_timing )   CALL timing_start('dia_wri')
-      !
-      ! 0. Initialisation
-      ! -----------------
-
-      ll_print = .FALSE.                  ! local variable for debugging
-      ll_print = ll_print .AND. lwp
-
-      ! Define frequency of output and means
-      clop = "x"         ! no use of the mask value (require less cpu time and otherwise the model crashes)
-#if defined key_diainstant
-      zsto = nn_write * rn_Dt
-      clop = "inst("//TRIM(clop)//")"
-#else
-      zsto=rn_Dt
-      clop = "ave("//TRIM(clop)//")"
-#endif
-      zout = nn_write * rn_Dt
-      zmax = ( nitend - nit000 + 1 ) * rn_Dt
-
-      ! Define indices of the horizontal output zoom and vertical limit storage
-      iimi = 1      ;      iima = jpi
-      ijmi = 1      ;      ijma = jpj
-      ipk = jpk
-      IF(ln_abl) ipka = jpkam1
-
-      ! define time axis
-      it = kt
-      itmod = kt - nit000 + 1
-!!st15
-      ! store e3t for subsitute
-      DO jk = 1, jpk
-         ze3t  (:,:,jk) =  e3t  (:,:,jk,Kmm)
-         zgdept(:,:,jk) =  gdept(:,:,jk,Kmm)
-      END DO
-!!st15
-
-      ! 1. Define NETCDF files and fields at beginning of first time step
-      ! -----------------------------------------------------------------
-
-      IF( kt == nit000 ) THEN
-
-         ! Define the NETCDF files (one per grid)
-
-         ! Compute julian date from starting date of the run
-         CALL ymds2ju( nyear, nmonth, nday, rn_Dt, zjulian )
-         zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
-         IF(lwp)WRITE(numout,*)
-         IF(lwp)WRITE(numout,*) 'Date 0 used :', nit000, ' YEAR ', nyear,   &
-            &                    ' MONTH ', nmonth, ' DAY ', nday, 'Julian day : ', zjulian
-         IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,   &
-                                 ' limit storage in depth = ', ipk
-
-         ! WRITE root name in date.file for use by postpro
-         IF(lwp) THEN
-            CALL dia_nam( clhstnam, nn_write,' ' )
-            CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-            WRITE(inum,*) clhstnam
-            CLOSE(inum)
-         ENDIF
-
-         ! Define the T grid FILE ( nid_T )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_T' )
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_1d, nz_T, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndex_T , ndim_T  )      ! volume
-         CALL wheneq( jpi*jpj    , tmask, 1, 1., ndex_hT, ndim_hT )      ! surface
-         !
-         IF( ln_icebergs ) THEN
-            !
-            !! allocation cant go in dia_wri_alloc because ln_icebergs is only set after 
-            !! that routine is called from nemogcm, so do it here immediately before its needed
-            ALLOCATE( ndex_bT(jpi*jpj*nclasses), STAT=ierror )
-            CALL mpp_sum( 'diawri', ierror )
-            IF( ierror /= 0 ) THEN
-               CALL ctl_stop('dia_wri: failed to allocate iceberg diagnostic array')
-               RETURN
-            ENDIF
-            !
-            !! iceberg vertical coordinate is class number
-            CALL histvert( nid_T, "class", "Iceberg class",      &  ! Vertical grid: class
-               &           "number", nclasses, class_num, nb_T )
-            !
-            !! each class just needs the surface index pattern
-            ndim_bT = 3
-            DO jn = 1,nclasses
-               ndex_bT((jn-1)*jpi*jpj+1:jn*jpi*jpj) = ndex_hT(1:jpi*jpj)
-            ENDDO
-            !
-         ENDIF
-
-         ! Define the U grid FILE ( nid_U )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_U' )
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-         CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
-            &           "m", ipk, gdept_1d, nz_U, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, umask, 1, 1., ndex_U , ndim_U  )      ! volume
-         CALL wheneq( jpi*jpj    , umask, 1, 1., ndex_hU, ndim_hU )      ! surface
-
-         ! Define the V grid FILE ( nid_V )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_V' )                   ! filename
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
-         CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
-            &          "m", ipk, gdept_1d, nz_V, "down" )
-         !                                                            ! Index of ocean points
-         CALL wheneq( jpi*jpj*ipk, vmask, 1, 1., ndex_V , ndim_V  )      ! volume
-         CALL wheneq( jpi*jpj    , vmask, 1, 1., ndex_hV, ndim_hV )      ! surface
-
-         ! Define the W grid FILE ( nid_W )
-
-         CALL dia_nam( clhstnam, nn_write, 'grid_W' )                   ! filename
-         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
-         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-            &          nit000-1, zjulian, rn_Dt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
-         CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
-            &          "m", ipk, gdepw_1d, nz_W, "down" )
-
-         IF( ln_abl ) THEN 
-         ! Define the ABL grid FILE ( nid_A )
-            CALL dia_nam( clhstnam, nn_write, 'grid_ABL' )
-            IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
-            CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
-               &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
-               &          nit000-1, zjulian, rn_Dt, nh_A, nid_A, domain_id=nidom, snc4chunks=snc4set )
-            CALL histvert( nid_A, "ght_abl", "Vertical T levels",      &  ! Vertical grid: gdept
-               &           "m", ipka, ght_abl(2:jpka), nz_A, "up" )
-            !                                                            ! Index of ocean points
-			ALLOCATE( zw3d_abl(jpi,jpj,ipka) ) 
-			zw3d_abl(:,:,:) = 1._wp 
-			CALL wheneq( jpi*jpj*ipka, zw3d_abl, 1, 1., ndex_A , ndim_A  )      ! volume
-            CALL wheneq( jpi*jpj     , zw3d_abl, 1, 1., ndex_hA, ndim_hA )      ! surface
-			DEALLOCATE(zw3d_abl)
-         ENDIF
-
-         ! Declare all the output fields as NETCDF variables
-
-         !                                                                                      !!! nid_T : 3D
-         CALL histdef( nid_T, "votemper", "Temperature"                        , "C"      ,   &  ! tn
-            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
-            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         IF(  .NOT.ln_linssh  ) THEN
-            CALL histdef( nid_T, "vovvle3t", "Level thickness"                    , "m"      ,&  ! ze3t(:,:,:,Kmm)
-            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-            CALL histdef( nid_T, "vovvldep", "T point depth"                      , "m"      ,&  ! ze3t(:,:,:,Kmm)
-            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-            CALL histdef( nid_T, "vovvldef", "Squared level deformation"          , "%^2"    ,&  ! ze3t(:,:,:,Kmm)
-            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_T : 2D
-         CALL histdef( nid_T, "sosstsst", "Sea Surface temperature"            , "C"      ,   &  ! sst
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosaline", "Sea Surface Salinity"               , "PSU"    ,   &  ! sss
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sossheig", "Sea Surface Height"                 , "m"      ,   &  ! ssh
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowaflup", "Net Upward Water Flux"              , "Kg/m2/s",   &  ! (emp-rnf)
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sorunoff", "River runoffs"                      , "Kg/m2/s",   &  ! runoffs
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosfldow", "downward salt flux"                 , "PSU/m2/s",  &  ! sfx
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         IF(  ln_linssh  ) THEN
-            CALL histdef( nid_T, "sosst_cd", "Concentration/Dilution term on temperature"     &  ! emp * ts(:,:,1,jp_tem,Kmm)
-            &                                                                  , "KgC/m2/s",  &  ! sosst_cd
-            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sosss_cd", "Concentration/Dilution term on salinity"        &  ! emp * ts(:,:,1,jp_sal,Kmm)
-            &                                                                  , "KgPSU/m2/s",&  ! sosss_cd
-            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         ENDIF
-         CALL histdef( nid_T, "sohefldo", "Net Downward Heat Flux"             , "W/m2"   ,   &  ! qns + qsr
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "soshfldo", "Shortwave Radiation"                , "W/m2"   ,   &  ! qsr
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "somixhgt", "Turbocline Depth"                   , "m"      ,   &  ! hmld
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "somxl010", "Mixed Layer Depth 0.01"             , "m"      ,   &  ! hmlp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "soicecov", "Ice fraction"                       , "[0,1]"  ,   &  ! fr_i
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowindsp", "wind speed at 10m"                  , "m/s"    ,   &  ! wndm
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         !
-         IF( ln_abl ) THEN
-            CALL histdef( nid_A, "t_abl", "Potential Temperature"     , "K"        ,       &  ! t_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout )
-            CALL histdef( nid_A, "q_abl", "Humidity"                  , "kg/kg"    ,       &  ! q_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "u_abl", "Atmospheric U-wind   "     , "m/s"        ,     &  ! u_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout )
-            CALL histdef( nid_A, "v_abl", "Atmospheric V-wind   "     , "m/s"    ,         &  ! v_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "tke_abl", "Atmospheric TKE   "     , "m2/s2"    ,        &  ! tke_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "avm_abl", "Atmospheric turbulent viscosity", "m2/s"   ,  &  ! avm_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "avt_abl", "Atmospheric turbulent diffusivity", "m2/s2",  &  ! avt_abl
-               &          jpi, jpj, nh_A, ipka, 1, ipka, nz_A, 32, clop, zsto, zout ) 
-            CALL histdef( nid_A, "pblh", "Atmospheric boundary layer height "  , "m",      &  ! pblh
-               &          jpi, jpj, nh_A,  1  , 1, 1   , -99 , 32, clop, zsto, zout )		 			   
-#if defined key_si3
-            CALL histdef( nid_A, "oce_frac", "Fraction of open ocean"  , " ",      &  ! ato_i
-               &          jpi, jpj, nh_A,  1  , 1, 1   , -99 , 32, clop, zsto, zout )
-#endif
-            CALL histend( nid_A, snc4chunks=snc4set )
-         ENDIF
-         !
-         IF( ln_icebergs ) THEN
-            CALL histdef( nid_T, "calving"             , "calving mass input"                       , "kg/s"   , &
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "calving_heat"        , "calving heat flux"                        , "XXXX"   , &
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "berg_floating_melt"  , "Melt rate of icebergs + bits"             , "kg/m2/s", &
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "berg_stored_ice"     , "Accumulated ice mass by class"            , "kg"     , &
-               &          jpi, jpj, nh_T, nclasses  , 1, nclasses  , nb_T , 32, clop, zsto, zout )
-            IF( ln_bergdia ) THEN
-               CALL histdef( nid_T, "berg_melt"           , "Melt rate of icebergs"                    , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_buoy_melt"      , "Buoyancy component of iceberg melt rate"  , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_eros_melt"      , "Erosion component of iceberg melt rate"   , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_conv_melt"      , "Convective component of iceberg melt rate", "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_virtual_area"   , "Virtual coverage by icebergs"             , "m2"     , &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "bits_src"           , "Mass source of bergy bits"                , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "bits_melt"          , "Melt rate of bergy bits"                  , "kg/m2/s", &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "bits_mass"          , "Bergy bit density field"                  , "kg/m2"  , &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_mass"           , "Iceberg density field"                    , "kg/m2"  , &
-                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-               CALL histdef( nid_T, "berg_real_calving"   , "Calving into iceberg class"               , "kg/s"   , &
-                  &          jpi, jpj, nh_T, nclasses  , 1, nclasses  , nb_T , 32, clop, zsto, zout )
-            ENDIF
-         ENDIF
-
-         IF( ln_ssr ) THEN
-            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-            CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
-               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         ENDIF
-       
-         clmx ="l_max(only(x))"    ! max index on a period
-!         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
-!            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clmx, zsto, zout )
-#if defined key_diahth
-         CALL histdef( nid_T, "sothedep", "Thermocline Depth"                  , "m"      ,   & ! hth
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "so20chgt", "Depth of 20C isotherm"              , "m"      ,   & ! hd20
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "so28chgt", "Depth of 28C isotherm"              , "m"      ,   & ! hd28
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sohtc300", "Heat content 300 m"                 , "J/m2"   ,   & ! htc3
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-
-         CALL histend( nid_T, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_U : 3D
-         CALL histdef( nid_U, "vozocrtx", "Zonal Current"                      , "m/s"    ,   &  ! uu(:,:,:,Kmm)
-            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
-         IF( ln_wave .AND. ln_sdw) THEN
-            CALL histdef( nid_U, "sdzocrtx", "Stokes Drift Zonal Current"         , "m/s"    ,   &  ! usd
-               &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_U : 2D
-         CALL histdef( nid_U, "sozotaux", "Wind Stress along i-axis"           , "N/m2"   ,   &  ! utau
-            &          jpi, jpj, nh_U, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-
-         CALL histend( nid_U, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_V : 3D
-         CALL histdef( nid_V, "vomecrty", "Meridional Current"                 , "m/s"    ,   &  ! vv(:,:,:,Kmm)
-            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
-         IF( ln_wave .AND. ln_sdw) THEN
-            CALL histdef( nid_V, "sdmecrty", "Stokes Drift Meridional Current"    , "m/s"    ,   &  ! vsd
-               &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_V : 2D
-         CALL histdef( nid_V, "sometauy", "Wind Stress along j-axis"           , "N/m2"   ,   &  ! vtau
-            &          jpi, jpj, nh_V, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
-
-         CALL histend( nid_V, snc4chunks=snc4set )
-
-         !                                                                                      !!! nid_W : 3D
-         CALL histdef( nid_W, "vovecrtz", "Vertical Velocity"                  , "m/s"    ,   &  ! ww
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         CALL histdef( nid_W, "votkeavt", "Vertical Eddy Diffusivity"          , "m2/s"   ,   &  ! avt
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         CALL histdef( nid_W, "votkeavm", "Vertical Eddy Viscosity"             , "m2/s"  ,   &  ! avm
-            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-
-         IF( ln_zdfddm ) THEN
-            CALL histdef( nid_W,"voddmavs","Salt Vertical Eddy Diffusivity"    , "m2/s"   ,   &  ! avs
-               &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         ENDIF
-         
-         IF( ln_wave .AND. ln_sdw) THEN
-            CALL histdef( nid_W, "sdvecrtz", "Stokes Drift Vertical Current"   , "m/s"    ,   &  ! wsd
-               &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
-         ENDIF
-         !                                                                                      !!! nid_W : 2D
-         CALL histend( nid_W, snc4chunks=snc4set )
-
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization'
-         IF(ll_print) CALL FLUSH(numout )
-
-      ENDIF
-
-      ! 2. Start writing data
-      ! ---------------------
-
-      ! ndex(1) est utilise ssi l'avant dernier argument est different de 
-      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
-      ! donne le nombre d'elements, et ndex la liste des indices a sortir
-
-      IF( lwp .AND. MOD( itmod, nn_write ) == 0 ) THEN 
-         WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
-         WRITE(numout,*) '~~~~~~ '
-      ENDIF
-!!st16
-      IF( .NOT.ln_linssh ) THEN
-         CALL histwrite( nid_T, "votemper", it, ts(:,:,:,jp_tem,Kmm) * ze3t(:,:,:) , ndim_T , ndex_T  )   ! heat content
-         CALL histwrite( nid_T, "vosaline", it, ts(:,:,:,jp_sal,Kmm) * ze3t(:,:,:) , ndim_T , ndex_T  )   ! salt content
-         CALL histwrite( nid_T, "sosstsst", it, ts(:,:,1,jp_tem,Kmm) * ze3t(:,:,1) , ndim_hT, ndex_hT )   ! sea surface heat content
-         CALL histwrite( nid_T, "sosaline", it, ts(:,:,1,jp_sal,Kmm) * ze3t(:,:,1) , ndim_hT, ndex_hT )   ! sea surface salinity content
-!!st16
-      ELSE
-         CALL histwrite( nid_T, "votemper", it, ts(:,:,:,jp_tem,Kmm) , ndim_T , ndex_T  )   ! temperature
-         CALL histwrite( nid_T, "vosaline", it, ts(:,:,:,jp_sal,Kmm) , ndim_T , ndex_T  )   ! salinity
-         CALL histwrite( nid_T, "sosstsst", it, ts(:,:,1,jp_tem,Kmm) , ndim_hT, ndex_hT )   ! sea surface temperature
-         CALL histwrite( nid_T, "sosaline", it, ts(:,:,1,jp_sal,Kmm) , ndim_hT, ndex_hT )   ! sea surface salinity
-      ENDIF
-      IF( .NOT.ln_linssh ) THEN
-!!st17 if ! defined key_qco 
-         zw3d(:,:,:) = ( ( ze3t(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2
-         CALL histwrite( nid_T, "vovvle3t", it, ze3t (:,:,:)     , ndim_T , ndex_T  )   ! level thickness
-         CALL histwrite( nid_T, "vovvldep", it, zgdept , ndim_T , ndex_T  )   ! t-point depth 
-!!st17
-         CALL histwrite( nid_T, "vovvldef", it, zw3d             , ndim_T , ndex_T  )   ! level thickness deformation
-      ENDIF
-      CALL histwrite( nid_T, "sossheig", it, ssh(:,:,Kmm)          , ndim_hT, ndex_hT )   ! sea surface height
-      CALL histwrite( nid_T, "sowaflup", it, ( emp-rnf )   , ndim_hT, ndex_hT )   ! upward water flux
-      CALL histwrite( nid_T, "sorunoff", it, rnf           , ndim_hT, ndex_hT )   ! river runoffs
-      CALL histwrite( nid_T, "sosfldow", it, sfx           , ndim_hT, ndex_hT )   ! downward salt flux 
-                                                                                  ! (includes virtual salt flux beneath ice 
-                                                                                  ! in linear free surface case)
-      IF( ln_linssh ) THEN
-         zw2d(:,:) = emp (:,:) * ts(:,:,1,jp_tem,Kmm)
-         CALL histwrite( nid_T, "sosst_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sst
-         zw2d(:,:) = emp (:,:) * ts(:,:,1,jp_sal,Kmm)
-         CALL histwrite( nid_T, "sosss_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sss
-      ENDIF
-      CALL histwrite( nid_T, "sohefldo", it, qns + qsr     , ndim_hT, ndex_hT )   ! total heat flux
-      CALL histwrite( nid_T, "soshfldo", it, qsr           , ndim_hT, ndex_hT )   ! solar heat flux
-      CALL histwrite( nid_T, "somixhgt", it, hmld          , ndim_hT, ndex_hT )   ! turbocline depth
-      CALL histwrite( nid_T, "somxl010", it, hmlp          , ndim_hT, ndex_hT )   ! mixed layer depth
-      CALL histwrite( nid_T, "soicecov", it, fr_i          , ndim_hT, ndex_hT )   ! ice fraction   
-      CALL histwrite( nid_T, "sowindsp", it, wndm          , ndim_hT, ndex_hT )   ! wind speed   
-      !
-      IF( ln_abl ) THEN 
-         ALLOCATE( zw3d_abl(jpi,jpj,jpka) )
-         IF( ln_mskland )   THEN 
-            DO jk=1,jpka
-               zw3d_abl(:,:,jk) = tmask(:,:,1)
-            END DO       
-         ELSE
-            zw3d_abl(:,:,:) = 1._wp		 
-         ENDIF			
-         CALL histwrite( nid_A,  "pblh"   , it, pblh(:,:)                  *zw3d_abl(:,:,1     ), ndim_hA, ndex_hA )   ! pblh 
-         CALL histwrite( nid_A,  "u_abl"  , it, u_abl   (:,:,2:jpka,nt_n  )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! u_abl
-         CALL histwrite( nid_A,  "v_abl"  , it, v_abl   (:,:,2:jpka,nt_n  )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! v_abl
-         CALL histwrite( nid_A,  "t_abl"  , it, tq_abl  (:,:,2:jpka,nt_n,1)*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! t_abl
-         CALL histwrite( nid_A,  "q_abl"  , it, tq_abl  (:,:,2:jpka,nt_n,2)*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! q_abl		 
-         CALL histwrite( nid_A,  "tke_abl", it, tke_abl (:,:,2:jpka,nt_n  )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! tke_abl
-         CALL histwrite( nid_A,  "avm_abl", it, avm_abl (:,:,2:jpka       )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! avm_abl
-         CALL histwrite( nid_A,  "avt_abl", it, avt_abl (:,:,2:jpka       )*zw3d_abl(:,:,2:jpka), ndim_A , ndex_A  )   ! avt_abl	
-#if defined key_si3
-         CALL histwrite( nid_A,  "oce_frac"   , it, ato_i(:,:)                                  , ndim_hA, ndex_hA )   ! ato_i
-#endif
-         DEALLOCATE(zw3d_abl)
-      ENDIF
-      !
-      IF( ln_icebergs ) THEN
-         !
-         CALL histwrite( nid_T, "calving"             , it, berg_grid%calving      , ndim_hT, ndex_hT )  
-         CALL histwrite( nid_T, "calving_heat"        , it, berg_grid%calving_hflx , ndim_hT, ndex_hT )         
-         CALL histwrite( nid_T, "berg_floating_melt"  , it, berg_grid%floating_melt, ndim_hT, ndex_hT )  
-         !
-         CALL histwrite( nid_T, "berg_stored_ice"     , it, berg_grid%stored_ice   , ndim_bT, ndex_bT )
-         !
-         IF( ln_bergdia ) THEN
-            CALL histwrite( nid_T, "berg_melt"           , it, berg_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_buoy_melt"      , it, buoy_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_eros_melt"      , it, eros_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_conv_melt"      , it, conv_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_virtual_area"   , it, virtual_area     , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "bits_src"            , it, bits_src         , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "bits_melt"           , it, bits_melt        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "bits_mass"           , it, bits_mass        , ndim_hT, ndex_hT   )  
-            CALL histwrite( nid_T, "berg_mass"           , it, berg_mass        , ndim_hT, ndex_hT   )  
-            !
-            CALL histwrite( nid_T, "berg_real_calving"   , it, real_calving     , ndim_bT, ndex_bT   )
-         ENDIF
-      ENDIF
-
-      IF( ln_ssr ) THEN
-         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
-         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
-         zw2d(:,:) = erp(:,:) * ts(:,:,1,jp_sal,Kmm) * tmask(:,:,1)
-         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-      ENDIF
-!      zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
-!      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
-
-#if defined key_diahth
-      CALL histwrite( nid_T, "sothedep", it, hth           , ndim_hT, ndex_hT )   ! depth of the thermocline
-      CALL histwrite( nid_T, "so20chgt", it, hd20          , ndim_hT, ndex_hT )   ! depth of the 20 isotherm
-      CALL histwrite( nid_T, "so28chgt", it, hd28          , ndim_hT, ndex_hT )   ! depth of the 28 isotherm
-      CALL histwrite( nid_T, "sohtc300", it, htc3          , ndim_hT, ndex_hT )   ! first 300m heaat content
-#endif
-
-      CALL histwrite( nid_U, "vozocrtx", it, uu(:,:,:,Kmm)            , ndim_U , ndex_U )    ! i-current
-      CALL histwrite( nid_U, "sozotaux", it, utau          , ndim_hU, ndex_hU )   ! i-wind stress
-
-      CALL histwrite( nid_V, "vomecrty", it, vv(:,:,:,Kmm)            , ndim_V , ndex_V  )   ! j-current
-      CALL histwrite( nid_V, "sometauy", it, vtau          , ndim_hV, ndex_hV )   ! j-wind stress
-
-      IF( ln_zad_Aimp ) THEN
-         CALL histwrite( nid_W, "vovecrtz", it, ww + wi     , ndim_T, ndex_T )    ! vert. current
-      ELSE
-         CALL histwrite( nid_W, "vovecrtz", it, ww          , ndim_T, ndex_T )    ! vert. current
-      ENDIF
-      CALL histwrite( nid_W, "votkeavt", it, avt            , ndim_T, ndex_T )    ! T vert. eddy diff. coef.
-      CALL histwrite( nid_W, "votkeavm", it, avm            , ndim_T, ndex_T )    ! T vert. eddy visc. coef.
-      IF( ln_zdfddm ) THEN
-         CALL histwrite( nid_W, "voddmavs", it, avs         , ndim_T, ndex_T )    ! S vert. eddy diff. coef.
-      ENDIF
-
-      IF( ln_wave .AND. ln_sdw ) THEN
-         CALL histwrite( nid_U, "sdzocrtx", it, usd         , ndim_U , ndex_U )    ! i-StokesDrift-current
-         CALL histwrite( nid_V, "sdmecrty", it, vsd         , ndim_V , ndex_V )    ! j-StokesDrift-current
-         CALL histwrite( nid_W, "sdvecrtz", it, wsd         , ndim_T , ndex_T )    ! StokesDrift vert. current
-      ENDIF
-
-      ! 3. Close all files
-      ! ---------------------------------------
-      IF( kt == nitend ) THEN
-         CALL histclo( nid_T )
-         CALL histclo( nid_U )
-         CALL histclo( nid_V )
-         CALL histclo( nid_W )
-         IF(ln_abl) CALL histclo( nid_A )
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('dia_wri')
-      !
-   END SUBROUTINE dia_wri
-#endif
-
-   SUBROUTINE dia_wri_state( Kmm, cdfile_name )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE dia_wri_state  ***
-      !!        
-      !! ** Purpose :   create a NetCDF file named cdfile_name which contains 
-      !!      the instantaneous ocean state and forcing fields.
-      !!        Used to find errors in the initial state or save the last
-      !!      ocean state in case of abnormal end of a simulation
-      !!
-      !! ** Method  :   NetCDF files using ioipsl
-      !!      File 'output.init.nc'  is created if ninist = 1 (namelist)
-      !!      File 'output.abort.nc' is created in case of abnormal job end
-      !!----------------------------------------------------------------------
-      INTEGER           , INTENT( in ) ::   Kmm              ! time level index
-      CHARACTER (len=* ), INTENT( in ) ::   cdfile_name      ! name of the file created
-      !!
-      INTEGER :: inum, jk
-!!st18  TBR
-      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t, zgdept      ! 3D workspace !!st patch to use substitution
-      !!----------------------------------------------------------------------
-      ! 
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dia_wri_state : single instantaneous ocean state'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   and forcing fields file created '
-      IF(lwp) WRITE(numout,*) '                and named :', cdfile_name, '...nc'
-!!st19 TBR
-      DO jk = 1, jpk
-         ze3t(:,:,jk) =  e3t(:,:,jk,Kmm)
-         zgdept(:,:,jk) =  gdept(:,:,jk,Kmm)
-      END DO
-!!st19
-#if defined key_si3
-     CALL iom_open( TRIM(cdfile_name), inum, ldwrt = .TRUE., kdlev = jpl )
-#else
-     CALL iom_open( TRIM(cdfile_name), inum, ldwrt = .TRUE. )
-#endif
-
-      CALL iom_rstput( 0, 0, inum, 'votemper', ts(:,:,:,jp_tem,Kmm) )    ! now temperature
-      CALL iom_rstput( 0, 0, inum, 'vosaline', ts(:,:,:,jp_sal,Kmm) )    ! now salinity
-      CALL iom_rstput( 0, 0, inum, 'sossheig', ssh(:,:,Kmm)              )    ! sea surface height
-      CALL iom_rstput( 0, 0, inum, 'vozocrtx', uu(:,:,:,Kmm)                )    ! now i-velocity
-      CALL iom_rstput( 0, 0, inum, 'vomecrty', vv(:,:,:,Kmm)                )    ! now j-velocity
-      IF( ln_zad_Aimp ) THEN
-         CALL iom_rstput( 0, 0, inum, 'vovecrtz', ww + wi        )    ! now k-velocity
-      ELSE
-         CALL iom_rstput( 0, 0, inum, 'vovecrtz', ww             )    ! now k-velocity
-      ENDIF
-      CALL iom_rstput( 0, 0, inum, 'risfdep', risfdep            )    ! now k-velocity
-      CALL iom_rstput( 0, 0, inum, 'ht'     , ht(:,:)            )    ! now water column height
-
-      IF ( ln_isf ) THEN
-         IF (ln_isfcav_mlt) THEN
-            CALL iom_rstput( 0, 0, inum, 'fwfisf_cav', fwfisf_cav          )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rhisf_cav_tbl', rhisf_tbl_cav    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rfrac_cav_tbl', rfrac_tbl_cav    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkb_cav', REAL(misfkb_cav,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkt_cav', REAL(misfkt_cav,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'mskisf_cav', REAL(mskisf_cav,wp), ktype = jp_i1 )
-         END IF
-         IF (ln_isfpar_mlt) THEN
-            CALL iom_rstput( 0, 0, inum, 'isfmsk_par', REAL(mskisf_par,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'fwfisf_par', fwfisf_par          )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rhisf_par_tbl', rhisf_tbl_par    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'rfrac_par_tbl', rfrac_tbl_par    )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkb_par', REAL(misfkb_par,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'misfkt_par', REAL(misfkt_par,wp) )    ! now k-velocity
-            CALL iom_rstput( 0, 0, inum, 'mskisf_par', REAL(mskisf_par,wp), ktype = jp_i1 )
-         END IF
-      END IF
-      !
-      IF( ALLOCATED(ahtu) ) THEN
-         CALL iom_rstput( 0, 0, inum,  'ahtu', ahtu              )    ! aht at u-point
-         CALL iom_rstput( 0, 0, inum,  'ahtv', ahtv              )    ! aht at v-point
-      ENDIF
-      IF( ALLOCATED(ahmt) ) THEN
-         CALL iom_rstput( 0, 0, inum,  'ahmt', ahmt              )    ! ahmt at u-point
-         CALL iom_rstput( 0, 0, inum,  'ahmf', ahmf              )    ! ahmf at v-point
-      ENDIF
-      CALL iom_rstput( 0, 0, inum, 'sowaflup', emp - rnf         )    ! freshwater budget
-      CALL iom_rstput( 0, 0, inum, 'sohefldo', qsr + qns         )    ! total heat flux
-      CALL iom_rstput( 0, 0, inum, 'soshfldo', qsr               )    ! solar heat flux
-      CALL iom_rstput( 0, 0, inum, 'soicecov', fr_i              )    ! ice fraction
-      CALL iom_rstput( 0, 0, inum, 'sozotaux', utau              )    ! i-wind stress
-      CALL iom_rstput( 0, 0, inum, 'sometauy', vtau              )    ! j-wind stress
-!!st20 TBR
-      IF(  .NOT.ln_linssh  ) THEN
-         CALL iom_rstput( 0, 0, inum, 'vovvldep', zgdept        )    !  T-cell depth 
-         CALL iom_rstput( 0, 0, inum, 'vovvle3t', ze3t          )    !  T-cell thickness  
-      END IF
-      IF( ln_wave .AND. ln_sdw ) THEN
-         CALL iom_rstput( 0, 0, inum, 'sdzocrtx', usd            )    ! now StokesDrift i-velocity
-         CALL iom_rstput( 0, 0, inum, 'sdmecrty', vsd            )    ! now StokesDrift j-velocity
-         CALL iom_rstput( 0, 0, inum, 'sdvecrtz', wsd            )    ! now StokesDrift k-velocity
-      ENDIF
-      IF ( ln_abl ) THEN
-         CALL iom_rstput ( 0, 0, inum, "uz1_abl",   u_abl(:,:,2,nt_a  ) )   ! now first level i-wind
-         CALL iom_rstput ( 0, 0, inum, "vz1_abl",   v_abl(:,:,2,nt_a  ) )   ! now first level j-wind
-         CALL iom_rstput ( 0, 0, inum, "tz1_abl",  tq_abl(:,:,2,nt_a,1) )   ! now first level temperature
-         CALL iom_rstput ( 0, 0, inum, "qz1_abl",  tq_abl(:,:,2,nt_a,2) )   ! now first level humidity
-      ENDIF
- 
-#if defined key_si3
-      IF( nn_ice == 2 ) THEN   ! condition needed in case agrif + ice-model but no-ice in child grid
-         CALL ice_wri_state( inum )
-      ENDIF
-#endif
-      !
-      CALL iom_close( inum )
-      ! 
-   END SUBROUTINE dia_wri_state
-
-   !!======================================================================
-END MODULE diawri
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dom_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dom_oce.F90	(revision 14059)
+++ 	(revision )
@@ -1,335 +1,0 @@
-MODULE dom_oce
-   !!======================================================================
-   !!                       ***  MODULE dom_oce  ***
-   !!       
-   !! ** Purpose :   Define in memory all the ocean space domain variables
-   !!======================================================================
-   !! History :  1.0  ! 2005-10  (A. Beckmann, G. Madec)  reactivate s-coordinate 
-   !!            3.3  ! 2010-11  (G. Madec) add mbk. arrays associated to the deepest ocean level
-   !!            3.4  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
-   !!            3.5  ! 2012     (S. Mocavero, I. Epicoco) Add arrays associated
-   !!                             to the optimization of BDY communications
-   !!            3.7  ! 2015-11  (G. Madec) introduce surface and scale factor ratio
-   !!             -   ! 2015-11  (G. Madec, A. Coward)  time varying zgr by default
-   !!            4.1  ! 2019-08  (A. Coward, D. Storkey) rename prognostic variables in preparation for new time scheme.
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   Agrif_Root    : dummy function used when lk_agrif=F
-   !!   Agrif_CFixed  : dummy function used when lk_agrif=F
-   !!   dom_oce_alloc : dynamical allocation of dom_oce arrays
-   !!----------------------------------------------------------------------
-   USE par_oce        ! ocean parameters
-
-   IMPLICIT NONE
-   PUBLIC             ! allows the acces to par_oce when dom_oce is used (exception to coding rules)
-
-   PUBLIC dom_oce_alloc  ! Called from nemogcm.F90
-
-   !!----------------------------------------------------------------------
-   !! time & space domain namelist
-   !! ----------------------------
-   !                                   !!* Namelist namdom : time & space domain *
-   LOGICAL , PUBLIC ::   ln_linssh      !: =T  linear free surface ==>> model level are fixed in time
-   LOGICAL , PUBLIC ::   ln_meshmask    !: =T  create a mesh-mask file (mesh_mask.nc)
-   REAL(wp), PUBLIC ::   rn_Dt          !: time step for the dynamics and tracer
-   REAL(wp), PUBLIC ::   rn_atfp        !: asselin time filter parameter
-   LOGICAL , PUBLIC ::   ln_1st_euler   !: =T start with forward time step or not (=F)
-   LOGICAL , PUBLIC ::   ln_crs         !: Apply grid coarsening to dynamical model output or online passive tracers
-
-   !! Free surface parameters
-   !! =======================
-   LOGICAL , PUBLIC :: ln_dynspg_exp    !: Explicit free surface flag
-   LOGICAL , PUBLIC :: ln_dynspg_ts     !: Split-Explicit free surface flag
-
-   !! Time splitting parameters
-   !! =========================
-   LOGICAL,  PUBLIC :: ln_bt_fw         !: Forward integration of barotropic sub-stepping
-   LOGICAL,  PUBLIC :: ln_bt_av         !: Time averaging of barotropic variables
-   LOGICAL,  PUBLIC :: ln_bt_auto       !: Set number of barotropic iterations automatically
-   INTEGER,  PUBLIC :: nn_bt_flt        !: Filter choice
-   INTEGER,  PUBLIC :: nn_e          !: Number of barotropic iterations during one baroclinic step (rn_Dt)
-   REAL(wp), PUBLIC :: rn_bt_cmax       !: Maximum allowed courant number (used if ln_bt_auto=T)
-   REAL(wp), PUBLIC :: rn_bt_alpha      !: Time stepping diffusion parameter
-
-
-   !                                   !!! associated variables
-   LOGICAL , PUBLIC ::   l_1st_euler    !: Euler 1st time-step flag (=T if ln_restart=F or ln_1st_euler=T)
-   REAL(wp), PUBLIC ::   rDt, r1_Dt     !: Current model timestep and reciprocal
-                                        !: rDt = 2 * rn_Dt if leapfrog and l_1st_euler = F
-                                        !:     =     rn_Dt if leapfrog and l_1st_euler = T
-                                        !:     =     rn_Dt if RK3
-
-   !!----------------------------------------------------------------------
-   !! space domain parameters
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC ::   jperio   !: Global domain lateral boundary type (between 0 and 7)
-   !                                !  = 0 closed                 ;   = 1 cyclic East-West
-   !                                !  = 2 cyclic North-South     ;   = 3 North fold T-point pivot
-   !                                !  = 4 cyclic East-West AND North fold T-point pivot
-   !                                !  = 5 North fold F-point pivot
-   !                                !  = 6 cyclic East-West AND North fold F-point pivot
-   !                                !  = 7 bi-cyclic East-West AND North-South
-   LOGICAL, PUBLIC ::   l_Iperio, l_Jperio   !   should we explicitely take care I/J periodicity
-
-   !                             !: domain MPP decomposition parameters
-   INTEGER             , PUBLIC ::   nimpp, njmpp     !: i- & j-indexes for mpp-subdomain left bottom
-   INTEGER             , PUBLIC ::   nreci, nrecj     !: overlap region in i and j
-   INTEGER             , PUBLIC ::   nproc            !: number for local processor
-   INTEGER             , PUBLIC ::   narea            !: number for local area
-   INTEGER             , PUBLIC ::   nbondi, nbondj   !: mark of i- and j-direction local boundaries
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondi_bdy(:)    !: mark i-direction local boundaries for BDY open boundaries
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondj_bdy(:)    !: mark j-direction local boundaries for BDY open boundaries
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondi_bdy_b(:)  !: mark i-direction of neighbours local boundaries for BDY open boundaries  
-   INTEGER, ALLOCATABLE, PUBLIC ::   nbondj_bdy_b(:)  !: mark j-direction of neighbours local boundaries for BDY open boundaries  
-
-   INTEGER, PUBLIC ::   npolj             !: north fold mark (0, 3 or 4)
-   INTEGER, PUBLIC ::   nlci, nldi, nlei  !: i-dimensions of the local subdomain and its first and last indoor indices
-   INTEGER, PUBLIC ::   nlcj, nldj, nlej  !: i-dimensions of the local subdomain and its first and last indoor indices
-   INTEGER, PUBLIC ::   noea, nowe        !: index of the local neighboring processors in
-   INTEGER, PUBLIC ::   noso, nono        !: east, west, south and north directions
-   INTEGER, PUBLIC ::   nidom             !: ???
-
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mig        !: local  ==> global domain i-index
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mjg        !: local  ==> global domain j-index
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mi0, mi1   !: global ==> local  domain i-index (mi0=1 and mi1=0 if the global index
-   !                                                                !                                             is not in the local domain)
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   mj0, mj1   !: global ==> local  domain j-index (mj0=1 and mj1=0 if the global index
-   !                                                                !                                             is not in the local domain)
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nimppt, njmppt   !: i-, j-indexes for each processor
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   ibonit, ibonjt   !: i-, j- processor neighbour existence
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nlcit , nlcjt    !: dimensions of every subdomain
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nldit , nldjt    !: first, last indoor index for each i-domain
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   nleit , nlejt    !: first, last indoor index for each j-domain
-   INTEGER, PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) :: nfiimpp, nfipproc, nfilcit
-
-   !!----------------------------------------------------------------------
-   !! horizontal curvilinear coordinate and scale factors
-   !! ---------------------------------------------------------------------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   glamt , glamu, glamv , glamf    !: longitude at t, u, v, f-points [degree]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   gphit , gphiu, gphiv , gphif    !: latitude  at t, u, v, f-points [degree]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1t   , e2t  , r1_e1t, r1_e2t   !: t-point horizontal scale factors    [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1u   , e2u  , r1_e1u, r1_e2u   !: horizontal scale factors at u-point [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1v   , e2v  , r1_e1v, r1_e2v   !: horizontal scale factors at v-point [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, TARGET, DIMENSION(:,:) ::   e1f   , e2f  , r1_e1f, r1_e2f   !: horizontal scale factors at f-point [m]
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2t , r1_e1e2t                !: associated metrics at t-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2u , r1_e1e2u , e2_e1u       !: associated metrics at u-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2v , r1_e1e2v , e1_e2v       !: associated metrics at v-point
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE        , DIMENSION(:,:) ::   e1e2f , r1_e1e2f                !: associated metrics at f-point
-   !
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ff_f  , ff_t                    !: Coriolis factor at f- & t-points  [1/s]
-   !!----------------------------------------------------------------------
-   !! vertical coordinate and scale factors
-   !! ---------------------------------------------------------------------
-   LOGICAL, PUBLIC ::   ln_zco       !: z-coordinate - full step
-   LOGICAL, PUBLIC ::   ln_zps       !: z-coordinate - partial step
-   LOGICAL, PUBLIC ::   ln_sco       !: s-coordinate or hybrid z-s coordinate
-   LOGICAL, PUBLIC ::   ln_isfcav    !: presence of ISF 
-   !                                                        !  reference scale factors
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3t_0   !: t- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3u_0   !: u- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3v_0   !: v- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3f_0   !: f- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::     e3w_0   !: w- vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::    e3uw_0   !: uw-vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::    e3vw_0   !: vw-vert. scale factor [m]
-   !                                                        !  time-dependent scale factors
-!!st1
-#if ! defined key_qco
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   e3t, e3u, e3v, e3w, e3uw, e3vw  !: vert. scale factor [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   e3f                             !: F-point vert. scale factor [m]
-#endif
-   !                                                        !  time-dependent ratio ssh / h_0
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   r3t, r3u, r3v                   !: time-dependent    ratio at t-, u- and v-point [-]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   r3f                             !: mid-time-level    ratio at f-point            [-]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   r3t_f, r3u_f, r3v_f             !: now time-filtered ratio at t-, u- and v-point [-]
-
-   !                                                        !  reference depths of cells
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gdept_0  !: t- depth              [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gdepw_0  !: w- depth              [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gde3w_0  !: w- depth (sum of e3w) [m]
-   !                                                        !  time-dependent depths of cells
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::   gdept, gdepw
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   gde3w
-!!st2
-   !                                                        !  reference heights of ocean water column and its inverse
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   ht_0, r1_ht_0   !: t-depth        [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hu_0, r1_hu_0   !: u-depth        [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hv_0, r1_hv_0   !: v-depth        [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   hf_0, r1_hf_0   !: f-depth        [m] and [1/m]
-   !                                                        ! time-dependent heights of ocean water column
-#if ! defined key_qco
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:)     ::   ht          !: t-points           [m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   hu, r1_hu   !: u-depth            [m] and [1/m]
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:)   ::   hv, r1_hv   !: v-depth            [m] and [1/m]
-#endif
-!!st2
-   
-   INTEGER, PUBLIC ::   nla10              !: deepest    W level Above  ~10m (nlb10 - 1)
-   INTEGER, PUBLIC ::   nlb10              !: shallowest W level Bellow ~10m (nla10 + 1) 
-
-   !! 1D reference  vertical coordinate
-   !! =-----------------====------
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   gdept_1d, gdepw_1d !: reference depth of t- and w-points (m)
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:)   ::   e3t_1d  , e3w_1d   !: reference vertical scale factors at T- and W-pts (m)
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   risfdep, bathy
-
-   !!----------------------------------------------------------------------
-   !! masks, top and bottom ocean point position
-   !! ---------------------------------------------------------------------
-!!gm Proposition of new name for top/bottom vertical indices
-!   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mtk_t, mtk_u, mtk_v   !: top    first wet T-, U-, and V-level (ISF)
-!   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbk_t, mbk_u, mbk_v   !: bottom last  wet T-, U-, and V-level
-!!gm
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mbkt, mbku, mbkv   !: bottom last wet T-, U- and V-level
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_i            !: interior domain T-point mask
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   tmask_h            !: internal domain T-point mask (Figure 8.5 NEMO book)
-
-   INTEGER , PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   mikt, miku, mikv, mikf  !: top first wet T-, U-, V-, F-level           (ISF)
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   ssmask, ssumask, ssvmask, ssfmask    !: surface mask at T-,U-, V- and F-pts
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: tmask, umask, vmask, fmask   !: land/ocean mask at T-, U-, V- and F-pts
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:), TARGET :: wmask, wumask, wvmask        !: land/ocean mask at WT-, WU- and WV-pts
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:) ::   tpol, fpol          !: north fold mask (jperio= 3 or 4)
-
-   !!----------------------------------------------------------------------
-   !! calendar variables
-   !! ---------------------------------------------------------------------
-   INTEGER , PUBLIC ::   nyear         !: current year
-   INTEGER , PUBLIC ::   nmonth        !: current month
-   INTEGER , PUBLIC ::   nday          !: current day of the month
-   INTEGER , PUBLIC ::   nhour         !: current hour
-   INTEGER , PUBLIC ::   nminute       !: current minute
-   INTEGER , PUBLIC ::   ndastp        !: time step date in yyyymmdd format
-   INTEGER , PUBLIC ::   nday_year     !: current day counted from jan 1st of the current year
-   INTEGER , PUBLIC ::   nsec_year     !: seconds between 00h jan 1st of the current  year and half of the current time step
-   INTEGER , PUBLIC ::   nsec_month    !: seconds between 00h 1st day of the current month and half of the current time step
-   INTEGER , PUBLIC ::   nsec_monday   !: seconds between 00h         of the last Monday   and half of the current time step
-   INTEGER , PUBLIC ::   nsec_day      !: seconds between 00h         of the current   day and half of the current time step
-   REAL(wp), PUBLIC ::   fjulday       !: current julian day 
-   REAL(wp), PUBLIC ::   fjulstartyear !: first day of the current year in julian days
-   REAL(wp), PUBLIC ::   adatrj        !: number of elapsed days since the begining of the whole simulation
-   !                                   !: (cumulative duration of previous runs that may have used different time-step size)
-   INTEGER , PUBLIC, DIMENSION(  0: 2) ::   nyear_len     !: length in days of the previous/current/next year
-   INTEGER , PUBLIC, DIMENSION(-11:25) ::   nmonth_len    !: length in days of the months of the current year
-   INTEGER , PUBLIC, DIMENSION(-11:25) ::   nmonth_beg    !: second since Jan 1st 0h of the current year and the half of the months
-   INTEGER , PUBLIC                  ::   nsec1jan000     !: second since Jan 1st 0h of nit000 year and Jan 1st 0h the current year
-   INTEGER , PUBLIC                  ::   nsec000_1jan000   !: second since Jan 1st 0h of nit000 year and nit000
-   INTEGER , PUBLIC                  ::   nsecend_1jan000   !: second since Jan 1st 0h of nit000 year and nitend
-
-   !!----------------------------------------------------------------------
-   !! agrif domain
-   !!----------------------------------------------------------------------
-#if defined key_agrif
-   LOGICAL, PUBLIC, PARAMETER ::   lk_agrif = .TRUE.    !: agrif flag
-#else
-   LOGICAL, PUBLIC, PARAMETER ::   lk_agrif = .FALSE.   !: agrif flag
-#endif
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dom_oce.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if ! defined key_agrif
-   !!----------------------------------------------------------------------
-   !! NOT 'key_agrif'      dummy function                     No AGRIF zoom
-   !!----------------------------------------------------------------------
-   LOGICAL FUNCTION Agrif_Root()
-      Agrif_Root = .TRUE.
-   END FUNCTION Agrif_Root
-
-   CHARACTER(len=3) FUNCTION Agrif_CFixed()
-      Agrif_CFixed = '0' 
-   END FUNCTION Agrif_CFixed
-#endif
-!!st3: dom_oce_alloc modified to ease the ifdef if necessary (gm stuff)
-   INTEGER FUNCTION dom_oce_alloc()
-      !!----------------------------------------------------------------------
-      INTEGER                ::   ii
-      INTEGER, DIMENSION(30) :: ierr
-      !!----------------------------------------------------------------------
-      ii = 0   ;   ierr(:) = 0
-      !
-      ii = ii+1
-      ALLOCATE( mig(jpi), mjg(jpj), STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( mi0 (jpiglo) , mi1 (jpiglo),  mj0(jpjglo) , mj1 (jpjglo) ,     &
-         &      tpol(jpiglo) , fpol(jpiglo)                              , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( glamt(jpi,jpj) ,    glamu(jpi,jpj) ,  glamv(jpi,jpj) ,  glamf(jpi,jpj) ,     &
-         &      gphit(jpi,jpj) ,    gphiu(jpi,jpj) ,  gphiv(jpi,jpj) ,  gphif(jpi,jpj) ,     &
-         &       e1t (jpi,jpj) ,     e2t (jpi,jpj) , r1_e1t(jpi,jpj) , r1_e2t(jpi,jpj) ,     &
-         &       e1u (jpi,jpj) ,     e2u (jpi,jpj) , r1_e1u(jpi,jpj) , r1_e2u(jpi,jpj) ,     &
-         &       e1v (jpi,jpj) ,     e2v (jpi,jpj) , r1_e1v(jpi,jpj) , r1_e2v(jpi,jpj) ,     &
-         &       e1f (jpi,jpj) ,     e2f (jpi,jpj) , r1_e1f(jpi,jpj) , r1_e2f(jpi,jpj) ,     &
-         &      e1e2t(jpi,jpj) , r1_e1e2t(jpi,jpj)                                     ,     &
-         &      e1e2u(jpi,jpj) , r1_e1e2u(jpi,jpj) , e2_e1u(jpi,jpj)                   ,     &
-         &      e1e2v(jpi,jpj) , r1_e1e2v(jpi,jpj) , e1_e2v(jpi,jpj)                   ,     &
-         &      e1e2f(jpi,jpj) , r1_e1e2f(jpi,jpj)                                     ,     &
-         &      ff_f (jpi,jpj) ,    ff_t (jpi,jpj)                                     , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE(  e3t_0(jpi,jpj,jpk) , e3u_0 (jpi,jpj,jpk) , e3v_0 (jpi,jpj,jpk) , e3f_0(jpi,jpj,jpk) ,      &
-         &       e3w_0(jpi,jpj,jpk) , e3uw_0(jpi,jpj,jpk) , e3vw_0(jpi,jpj,jpk)                      ,  STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( gdept_0(jpi,jpj,jpk)     , gdepw_0(jpi,jpj,jpk)     , gde3w_0(jpi,jpj,jpk) ,      &
-         &      gdept  (jpi,jpj,jpk,jpt) , gdepw  (jpi,jpj,jpk,jpt) , gde3w  (jpi,jpj,jpk) , STAT=ierr(ii) )
-         !
-!!st4
-#if ! defined key_qco
-      ii = ii+1
-      ALLOCATE( e3t(jpi,jpj,jpk,jpt) , e3u (jpi,jpj,jpk,jpt) , e3v (jpi,jpj,jpk,jpt) , e3f(jpi,jpj,jpk) ,      &
-         &      e3w(jpi,jpj,jpk,jpt) , e3uw(jpi,jpj,jpk,jpt) , e3vw(jpi,jpj,jpk,jpt)                    ,  STAT=ierr(ii) )
-#endif
-!!st4
-         !
-      ii = ii+1
-      ALLOCATE( r3t  (jpi,jpj,jpt)   , r3u  (jpi,jpj,jpt)    , r3v  (jpi,jpj,jpt)    , r3f  (jpi,jpj) ,  &
-         &      r3t_f(jpi,jpj)       , r3u_f(jpi,jpj)        , r3v_f(jpi,jpj)                         ,  STAT=ierr(ii) )       
-         !
-      ii = ii+1
-      ALLOCATE( ht_0(jpi,jpj) ,    hu_0(jpi,jpj)    ,    hv_0(jpi,jpj)     , hf_0(jpi,jpj) ,       &
-         &   r1_ht_0(jpi,jpj) , r1_hu_0(jpi,jpj) ,    r1_hv_0(jpi,jpj),   r1_hf_0(jpi,jpj) ,   STAT=ierr(ii)  )
-         !
-#if ! defined key_qco
-      ii = ii+1
-      ALLOCATE( ht  (jpi,jpj) ,    hu  (jpi,jpj,jpt),    hv  (jpi,jpj,jpt)                 ,       &
-         &                      r1_hu  (jpi,jpj,jpt), r1_hv  (jpi,jpj,jpt)                 ,   STAT=ierr(ii)  )
-#endif
-         !
-      ii = ii+1
-      ALLOCATE( risfdep(jpi,jpj) , bathy(jpi,jpj) , STAT=ierr(ii)  ) 
-         !
-      ii = ii+1
-      ALLOCATE( gdept_1d(jpk) , gdepw_1d(jpk) , e3t_1d(jpk) , e3w_1d(jpk) , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( tmask_i(jpi,jpj) , tmask_h(jpi,jpj) ,                                           &
-         &      ssmask (jpi,jpj) , ssumask(jpi,jpj) , ssvmask(jpi,jpj) , ssfmask(jpi,jpj) ,     &
-         &      mbkt   (jpi,jpj) , mbku   (jpi,jpj) , mbkv   (jpi,jpj) ,                    STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( mikt(jpi,jpj), miku(jpi,jpj), mikv(jpi,jpj), mikf(jpi,jpj), STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( tmask(jpi,jpj,jpk) , umask(jpi,jpj,jpk) ,     &
-         &      vmask(jpi,jpj,jpk) , fmask(jpi,jpj,jpk) , STAT=ierr(ii) )
-         !
-      ii = ii+1
-      ALLOCATE( wmask(jpi,jpj,jpk) , wumask(jpi,jpj,jpk), wvmask(jpi,jpj,jpk) , STAT=ierr(ii) )
-      !
-      dom_oce_alloc = MAXVAL(ierr)
-      !
-   END FUNCTION dom_oce_alloc
-
-   !!======================================================================
-END MODULE dom_oce
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/domain.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/domain.F90	(revision 14059)
+++ 	(revision )
@@ -1,727 +1,0 @@
-MODULE domain
-   !!==============================================================================
-   !!                       ***  MODULE domain   ***
-   !! Ocean initialization : domain initialization
-   !!==============================================================================
-   !! History :  OPA  !  1990-10  (C. Levy - G. Madec)  Original code
-   !!                 !  1992-01  (M. Imbard) insert time step initialization
-   !!                 !  1996-06  (G. Madec) generalized vertical coordinate 
-   !!                 !  1997-02  (G. Madec) creation of domwri.F
-   !!                 !  2001-05  (E.Durand - G. Madec) insert closed sea
-   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form and module
-   !!            2.0  !  2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.3  !  2010-11  (G. Madec)  initialisation in C1D configuration
-   !!            3.6  !  2013     ( J. Simeon, C. Calone, G. Madec, C. Ethe ) Online coarsening of outputs
-   !!            3.7  !  2015-11  (G. Madec, A. Coward)  time varying zgr by default
-   !!            4.0  !  2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface
-   !!----------------------------------------------------------------------
-   
-   !!----------------------------------------------------------------------
-   !!   dom_init      : initialize the space and time domain
-   !!   dom_glo       : initialize global domain <--> local domain indices
-   !!   dom_nam       : read and contral domain namelists
-   !!   dom_ctl       : control print for the ocean domain
-   !!   domain_cfg    : read the global domain size in domain configuration file
-   !!   cfg_write     : create the domain configuration file
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean variables
-   USE dom_oce        ! domain: ocean
-   USE sbc_oce        ! surface boundary condition: ocean
-   USE trc_oce        ! shared ocean & passive tracers variab
-   USE phycst         ! physical constants
-   USE domhgr         ! domain: set the horizontal mesh
-   USE domzgr         ! domain: set the vertical mesh
-   USE dommsk         ! domain: set the mask system
-   USE domwri         ! domain: write the meshmask file
-!!st5
-#if ! defined key_qco
-   USE domvvl         ! variable volume
-#else
-   USE domqco          ! variable volume
-#endif
-!!st5
-   USE c1d            ! 1D configuration
-   USE dyncor_c1d     ! 1D configuration: Coriolis term    (cor_c1d routine)
-   USE wet_dry, ONLY : ll_wd
-   USE closea , ONLY : dom_clo ! closed seas
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O library
-   USE lbclnk         ! ocean lateral boundary condition (or mpp link)
-   USE lib_mpp        ! distributed memory computing library
-!!an45
-!   USE usrdef_nam, ONLY : ln_45machin
-   !
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dom_init     ! called by nemogcm.F90
-   PUBLIC   domain_cfg   ! called by nemogcm.F90
-#  include "do_loop_substitute.h90"
-   !!-------------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: domain.F90 12822 2020-04-28 09:10:38Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!-------------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dom_init( Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_init  ***
-      !!                    
-      !! ** Purpose :   Domain initialization. Call the routines that are 
-      !!              required to create the arrays which define the space 
-      !!              and time domain of the ocean model.
-      !!
-      !! ** Method  : - dom_msk: compute the masks from the bathymetry file
-      !!              - dom_hgr: compute or read the horizontal grid-point position
-      !!                         and scale factors, and the coriolis factor
-      !!              - dom_zgr: define the vertical coordinate and the bathymetry
-      !!              - dom_wri: create the meshmask file (ln_meshmask=T)
-      !!              - 1D configuration, move Coriolis, u and v at T-point
-      !!----------------------------------------------------------------------
-      INTEGER          , INTENT(in) :: Kbb, Kmm, Kaa          ! ocean time level indices
-      !
-!!st6
-      INTEGER ::   ji, jj, jk, jt   ! dummy loop indices
-!!st6
-      INTEGER ::   iconf = 0    ! local integers
-      CHARACTER (len=64) ::   cform = "(A12, 3(A13, I7))" 
-      INTEGER , DIMENSION(jpi,jpj) ::   ik_top , ik_bot       ! top and bottom ocean level
-      REAL(wp), DIMENSION(jpi,jpj) ::   z1_hu_0, z1_hv_0
-      REAL(wp)::   zcoeff                                     ! local real
-
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN         ! Ocean domain Parameters (control print)
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_init : domain initialization'
-         WRITE(numout,*) '~~~~~~~~'
-         !
-         WRITE(numout,*)     '   Domain info'
-         WRITE(numout,*)     '      dimension of model:'
-         WRITE(numout,*)     '             Local domain      Global domain       Data domain '
-         WRITE(numout,cform) '        ','   jpi     : ', jpi, '   jpiglo  : ', jpiglo
-         WRITE(numout,cform) '        ','   jpj     : ', jpj, '   jpjglo  : ', jpjglo
-         WRITE(numout,cform) '        ','   jpk     : ', jpk, '   jpkglo  : ', jpkglo
-         WRITE(numout,cform) '       ' ,'   jpij    : ', jpij
-         WRITE(numout,*)     '      mpp local domain info (mpp):'
-         WRITE(numout,*)     '              jpni    : ', jpni, '   nn_hls  : ', nn_hls
-         WRITE(numout,*)     '              jpnj    : ', jpnj, '   nn_hls  : ', nn_hls
-         WRITE(numout,*)     '              jpnij   : ', jpnij
-         WRITE(numout,*)     '      lateral boundary of the Global domain : jperio  = ', jperio
-         SELECT CASE ( jperio )
-         CASE( 0 )   ;   WRITE(numout,*) '         (i.e. closed)'
-         CASE( 1 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west)'
-         CASE( 2 )   ;   WRITE(numout,*) '         (i.e. cyclic north-south)'
-         CASE( 3 )   ;   WRITE(numout,*) '         (i.e. north fold with T-point pivot)'
-         CASE( 4 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west and north fold with T-point pivot)'
-         CASE( 5 )   ;   WRITE(numout,*) '         (i.e. north fold with F-point pivot)'
-         CASE( 6 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west and north fold with F-point pivot)'
-         CASE( 7 )   ;   WRITE(numout,*) '         (i.e. cyclic east-west and north-south)'
-         CASE DEFAULT
-            CALL ctl_stop( 'dom_init:   jperio is out of range' )
-         END SELECT
-         WRITE(numout,*)     '      Ocean model configuration used:'
-         WRITE(numout,*)     '         cn_cfg = ', TRIM( cn_cfg ), '   nn_cfg = ', nn_cfg
-      ENDIF
-      lwxios = .FALSE.
-      ln_xios_read = .FALSE.
-      !
-      !           !==  Reference coordinate system  ==!
-      !
-      CALL dom_glo                     ! global domain versus local domain
-      CALL dom_nam                     ! read namelist ( namrun, namdom )
-      !
-      CALL dom_hgr                      ! Horizontal mesh
-
-      IF( ln_closea ) CALL dom_clo      ! Read in masks to define closed seas and lakes
-
-      CALL dom_zgr( ik_top, ik_bot )    ! Vertical mesh and bathymetry (return top and bottom ocean t-level indices)
-
-      CALL dom_msk( ik_top, ik_bot )    ! Masks
-      !
-      ht_0(:,:) = 0._wp  ! Reference ocean thickness
-      hu_0(:,:) = 0._wp
-      hv_0(:,:) = 0._wp
-      hf_0(:,:) = 0._wp
-      DO jk = 1, jpkm1
-         ht_0(:,:) = ht_0(:,:) + e3t_0(:,:,jk) * tmask(:,:,jk)
-         hu_0(:,:) = hu_0(:,:) + e3u_0(:,:,jk) * umask(:,:,jk)
-         hv_0(:,:) = hv_0(:,:) + e3v_0(:,:,jk) * vmask(:,:,jk)
-         hf_0(:,:) = hf_0(:,:) + e3f_0(:,:,jk) * ssfmask(:,:)     ! CAUTION : only valid in SWE, not with bathymetry
-      END DO
-      !
-!!anhf hf_0 = mean(ht_0*tmask) so hf = mimj( ht0 + ssht)
-! ne pas combiner avec an45 tout de suite
-!      DO_2D( 1, 0, 1, 0 )
-!         hf_0(ji,jj) = 0.25_wp * (   ht_0(ji,jj+1) * tmask(ji,jj+1,1) + ht_0(ji+1,jj+1) * tmask(ji+1,jj+1,1)   &
-!            &                      + ht_0(ji,jj  ) * tmask(ji,jj  ,1) + ht_0(ji+1,jj  ) * tmask(ji+1,jj  ,1)   )
-!      END_2D
-!      CALL lbc_lnk( 'domain', hf_0, 'F', 1. )      ! Lateral boundary conditions
-!!anhf
-      !                                 ! Inverse of reference ocean thickness
-      r1_ht_0(:,:) =  ssmask(:,:) / ( ht_0(:,:) + 1._wp -  ssmask(:,:) )
-      r1_hu_0(:,:) = ssumask(:,:) / ( hu_0(:,:) + 1._wp - ssumask(:,:) )
-      r1_hv_0(:,:) = ssvmask(:,:) / ( hv_0(:,:) + 1._wp - ssvmask(:,:) )
-      r1_hf_0(:,:) = ssfmask(:,:) / ( hf_0(:,:) + 1._wp - ssfmask(:,:) )
-      !
-!!an45 Ligne de cote a 45deg : e1e2t *= ( mi(umask) + mj(vmask) ) /2
-!!                             idem pour e1e2f
-!      DO_2D( 1, 0, 1, 0 )
-!      zcoeff = 0.25_wp * (   umask(ji,jj+1,1) + umask(ji+1,jj+1,1)   &
-!         &                 + vmask(ji,jj  ,1) + vmask(ji+1,jj  ,1)   )
-!         IF ( zcoeff /= 0._wp )   THEN
-!               e1e2t(ji,jj) =    e1e2t(ji,jj) * zcoeff
-!            r1_e1e2t(ji,jj) = r1_e1e2t(ji,jj) / zcoeff
-!         ENDIF
-!      END_2D
-!      WRITE(numout,*) '   an45 half T cell e1e2t '
-!      zcoeff = 0.25_wp * (   umask(ji,jj+1,1) + umask(ji+1,jj+1,1)   &
-!         &                 + vmask(ji,jj  ,1) + vmask(ji+1,jj  ,1)   )
-!         IF ( zcoeff /= 0._wp )   THEN
-!               e1e2t(ji,jj) =    e1e2t(ji,jj) * zcoeff
-!            r1_e1e2t(ji,jj) = r1_e1e2t(ji,jj) / zcoeff
-!!an45
-!!st7 : make it easier to use key_qco condition (gm stuff)
-#if defined key_qco
-      !           !==  initialisation of time varying coordinate  ==!   Quasi-Euerian coordinate case
-      !
-      IF( .NOT.l_offline )   CALL dom_qco_init( Kbb, Kmm, Kaa )
-      !
-      IF( ln_linssh )        CALL ctl_stop('STOP','domain: key_qco and ln_linssh = T are incompatible')
-      !
-#else
-      !           !==  time varying part of coordinate system  ==!
-      !
-      IF( ln_linssh ) THEN       != Fix in time : set to the reference one for all
-         !
-         DO jt = 1, jpt                         ! depth of t- and w-grid-points
-            gdept(:,:,:,jt) = gdept_0(:,:,:)
-            gdepw(:,:,:,jt) = gdepw_0(:,:,:)
-         END DO
-            gde3w(:,:,:)    = gde3w_0(:,:,:)    ! = gdept as the sum of e3t
-         !
-         DO jt = 1, jpt                         ! vertical scale factors
-            e3t(:,:,:,jt) =  e3t_0(:,:,:)
-            e3u(:,:,:,jt) =  e3u_0(:,:,:)
-            e3v(:,:,:,jt) =  e3v_0(:,:,:)
-            e3w(:,:,:,jt) =  e3w_0(:,:,:)
-            e3uw(:,:,:,jt) = e3uw_0(:,:,:)
-            e3vw(:,:,:,jt) = e3vw_0(:,:,:)
-         END DO
-            e3f(:,:,:)    =  e3f_0(:,:,:)
-         !
-         DO jt = 1, jpt                         ! water column thickness and its inverse
-            hu(:,:,jt)    =    hu_0(:,:)
-            hv(:,:,jt)    =    hv_0(:,:)
-            r1_hu(:,:,jt) = r1_hu_0(:,:)
-            r1_hv(:,:,jt) = r1_hv_0(:,:)
-         END DO
-            ht(:,:) =    ht_0(:,:)
-         !
-      ELSE                       != time varying : initialize before/now/after variables
-         !
-         IF( .NOT.l_offline )   CALL dom_vvl_init( Kbb, Kmm, Kaa )
-         !
-      ENDIF
-#endif
-!!st7
-      !
-      IF( lk_c1d         )   CALL cor_c1d       ! 1D configuration: Coriolis set at T-point
-      !
-
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) CALL Agrif_Init_Domain( Kbb, Kmm, Kaa )
-#endif
-      IF( ln_meshmask    )   CALL dom_wri       ! Create a domain file
-      IF( .NOT.ln_rstart )   CALL dom_ctl       ! Domain control
-      !
-      IF( ln_write_cfg   )   CALL cfg_write     ! create the configuration file
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_init :   ==>>>   END of domain initialization'
-         WRITE(numout,*) '~~~~~~~~'
-         WRITE(numout,*) 
-      ENDIF
-      !
-   END SUBROUTINE dom_init
-
-
-   SUBROUTINE dom_glo
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_glo  ***
-      !!
-      !! ** Purpose :   initialization of global domain <--> local domain indices
-      !!
-      !! ** Method  :   
-      !!
-      !! ** Action  : - mig , mjg : local  domain indices ==> global domain, including halos, indices
-      !!              - mig0, mjg0: local  domain indices ==> global domain, excluding halos, indices
-      !!              - mi0 , mi1 : global domain indices ==> local  domain indices
-      !!              - mj0 , mj1   (if global point not in the local domain ==> mi0>mi1 and/or mj0>mj1)
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj   ! dummy loop argument
-      !!----------------------------------------------------------------------
-      !
-      DO ji = 1, jpi                 ! local domain indices ==> global domain indices, including halos
-        mig(ji) = ji + nimpp - 1
-      END DO
-      DO jj = 1, jpj
-        mjg(jj) = jj + njmpp - 1
-      END DO
-      !                              ! local domain indices ==> global domain indices, excluding halos
-      !
-      mig0(:) = mig(:) - nn_hls
-      mjg0(:) = mjg(:) - nn_hls  
-      ! WARNING: to keep compatibility with the trunk that was including periodocity into the input data, 
-      ! we must define mig0 and mjg0 as bellow.
-      ! Once we decide to forget trunk compatibility, we must simply define mig0 and mjg0 as:
-      mig0_oldcmp(:) = mig0(:) + COUNT( (/ jperio == 1 .OR. jperio == 4 .OR. jperio == 6 .OR. jperio == 7 /) )
-      mjg0_oldcmp(:) = mjg0(:) + COUNT( (/ jperio == 2 .OR. jperio == 7 /) )
-      !
-      !                              ! global domain, including halos, indices ==> local domain indices
-      !                                   ! (return (m.0,m.1)=(1,0) if data domain gridpoint is to the west/south of the 
-      !                                   ! local domain, or (m.0,m.1)=(jp.+1,jp.) to the east/north of local domain. 
-      DO ji = 1, jpiglo
-        mi0(ji) = MAX( 1 , MIN( ji - nimpp + 1, jpi+1 ) )
-        mi1(ji) = MAX( 0 , MIN( ji - nimpp + 1, jpi   ) )
-      END DO
-      DO jj = 1, jpjglo
-        mj0(jj) = MAX( 1 , MIN( jj - njmpp + 1, jpj+1 ) )
-        mj1(jj) = MAX( 0 , MIN( jj - njmpp + 1, jpj   ) )
-      END DO
-      IF(lwp) THEN                   ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_glo : domain: global <<==>> local '
-         WRITE(numout,*) '~~~~~~~ '
-         WRITE(numout,*) '   global domain:   jpiglo = ', jpiglo, ' jpjglo = ', jpjglo, ' jpkglo = ', jpkglo
-         WRITE(numout,*) '   local  domain:   jpi    = ', jpi   , ' jpj    = ', jpj   , ' jpk    = ', jpk
-         WRITE(numout,*)
-      ENDIF
-      !
-   END SUBROUTINE dom_glo
-
-
-   SUBROUTINE dom_nam
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_nam  ***
-      !!                    
-      !! ** Purpose :   read domaine namelists and print the variables.
-      !!
-      !! ** input   : - namrun namelist
-      !!              - namdom namelist
-      !!              - namnc4 namelist   ! "key_netcdf4" only
-      !!----------------------------------------------------------------------
-      USE ioipsl
-      !!
-      INTEGER  ::   ios   ! Local integer
-      !
-      NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,                 &
-         &             nn_no   , cn_exp   , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl ,     &
-         &             nn_it000, nn_itend , nn_date0    , nn_time0     , nn_leapy  , nn_istate ,     &
-         &             nn_stock, nn_write , ln_mskland  , ln_clobber   , nn_chunksz, ln_1st_euler  , &
-         &             ln_cfmeta, ln_xios_read, nn_wxios
-      NAMELIST/namdom/ ln_linssh, rn_Dt, rn_atfp, ln_crs, ln_meshmask
-#if defined key_netcdf4
-      NAMELIST/namnc4/ nn_nchunks_i, nn_nchunks_j, nn_nchunks_k, ln_nc4zip
-#endif
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_nam : domain initialization through namelist read'
-         WRITE(numout,*) '~~~~~~~ '
-      ENDIF
-      !
-      !
-      READ  ( numnam_ref, namrun, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namrun in reference namelist' )
-      READ  ( numnam_cfg, namrun, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namrun in configuration namelist' )
-      IF(lwm) WRITE ( numond, namrun )
-
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-            nn_it000 = (Agrif_Parent(nn_it000)-1)*Agrif_IRhot() + 1
-            nn_itend =  Agrif_Parent(nn_itend)   *Agrif_IRhot()
-      ENDIF
-#endif
-      !
-      IF(lwp) THEN                  ! control print
-         WRITE(numout,*) '   Namelist : namrun   ---   run parameters'
-         WRITE(numout,*) '      Assimilation cycle              nn_no           = ', nn_no
-         WRITE(numout,*) '      experiment name for output      cn_exp          = ', TRIM( cn_exp           )
-         WRITE(numout,*) '      file prefix restart input       cn_ocerst_in    = ', TRIM( cn_ocerst_in     )
-         WRITE(numout,*) '      restart input directory         cn_ocerst_indir = ', TRIM( cn_ocerst_indir  )
-         WRITE(numout,*) '      file prefix restart output      cn_ocerst_out   = ', TRIM( cn_ocerst_out    )
-         WRITE(numout,*) '      restart output directory        cn_ocerst_outdir= ', TRIM( cn_ocerst_outdir )
-         WRITE(numout,*) '      restart logical                 ln_rstart       = ', ln_rstart
-         WRITE(numout,*) '      start with forward time step    ln_1st_euler    = ', ln_1st_euler
-         WRITE(numout,*) '      control of time step            nn_rstctl       = ', nn_rstctl
-         WRITE(numout,*) '      number of the first time step   nn_it000        = ', nn_it000
-         WRITE(numout,*) '      number of the last time step    nn_itend        = ', nn_itend
-         WRITE(numout,*) '      initial calendar date aammjj    nn_date0        = ', nn_date0
-         WRITE(numout,*) '      initial time of day in hhmm     nn_time0        = ', nn_time0
-         WRITE(numout,*) '      leap year calendar (0/1)        nn_leapy        = ', nn_leapy
-         WRITE(numout,*) '      initial state output            nn_istate       = ', nn_istate
-         IF( ln_rst_list ) THEN
-            WRITE(numout,*) '      list of restart dump times      nn_stocklist    =', nn_stocklist
-         ELSE
-            WRITE(numout,*) '      frequency of restart file       nn_stock        = ', nn_stock
-         ENDIF
-#if ! defined key_iomput
-         WRITE(numout,*) '      frequency of output file        nn_write        = ', nn_write
-#endif
-         WRITE(numout,*) '      mask land points                ln_mskland      = ', ln_mskland
-         WRITE(numout,*) '      additional CF standard metadata ln_cfmeta       = ', ln_cfmeta
-         WRITE(numout,*) '      overwrite an existing file      ln_clobber      = ', ln_clobber
-         WRITE(numout,*) '      NetCDF chunksize (bytes)        nn_chunksz      = ', nn_chunksz
-         IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-            WRITE(numout,*) '      READ restart for a single file using XIOS ln_xios_read =', ln_xios_read
-            WRITE(numout,*) '      Write restart using XIOS        nn_wxios   = ', nn_wxios
-         ELSE
-            WRITE(numout,*) "      AGRIF: nn_wxios will be ingored. See setting for parent"
-            WRITE(numout,*) "      AGRIF: ln_xios_read will be ingored. See setting for parent"
-         ENDIF
-      ENDIF
-
-      cexper = cn_exp         ! conversion DOCTOR names into model names (this should disappear soon)
-      nrstdt = nn_rstctl
-      nit000 = nn_it000
-      nitend = nn_itend
-      ndate0 = nn_date0
-      nleapy = nn_leapy
-      ninist = nn_istate
-      l_1st_euler = ln_1st_euler
-      IF( .NOT. l_1st_euler .AND. .NOT. ln_rstart ) THEN
-         IF(lwp) WRITE(numout,*)  
-         IF(lwp) WRITE(numout,*)'   ==>>>   Start from rest (ln_rstart=F)'
-         IF(lwp) WRITE(numout,*)'           an Euler initial time step is used : l_1st_euler is forced to .true. '   
-         l_1st_euler = .true.
-      ENDIF
-      !                             ! control of output frequency
-      IF( .NOT. ln_rst_list ) THEN     ! we use nn_stock
-         IF( nn_stock == -1 )   CALL ctl_warn( 'nn_stock = -1 --> no restart will be done' )
-         IF( nn_stock == 0 .OR. nn_stock > nitend ) THEN
-            WRITE(ctmp1,*) 'nn_stock = ', nn_stock, ' it is forced to ', nitend
-            CALL ctl_warn( ctmp1 )
-            nn_stock = nitend
-         ENDIF
-      ENDIF
-#if ! defined key_iomput
-      IF( nn_write == -1 )   CALL ctl_warn( 'nn_write = -1 --> no output files will be done' )
-      IF ( nn_write == 0 ) THEN
-         WRITE(ctmp1,*) 'nn_write = ', nn_write, ' it is forced to ', nitend
-         CALL ctl_warn( ctmp1 )
-         nn_write = nitend
-      ENDIF
-#endif
-
-      IF( Agrif_Root() ) THEN
-         IF(lwp) WRITE(numout,*)
-         SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
-         CASE (  1 ) 
-            CALL ioconf_calendar('gregorian')
-            IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "gregorian", i.e. leap year'
-         CASE (  0 )
-            CALL ioconf_calendar('noleap')
-            IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "noleap", i.e. no leap year'
-         CASE ( 30 )
-            CALL ioconf_calendar('360d')
-            IF(lwp) WRITE(numout,*) '   ==>>>   The IOIPSL calendar is "360d", i.e. 360 days in a year'
-         END SELECT
-      ENDIF
-
-      READ  ( numnam_ref, namdom, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdom in reference namelist' )
-      READ  ( numnam_cfg, namdom, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdom in configuration namelist' )
-      IF(lwm) WRITE( numond, namdom )
-      !
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-            rn_Dt = Agrif_Parent(rn_Dt) / Agrif_Rhot()
-      ENDIF
-#endif
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) '   Namelist : namdom   ---   space & time domain'
-         WRITE(numout,*) '      linear free surface (=T)                ln_linssh   = ', ln_linssh
-         WRITE(numout,*) '      create mesh/mask file                   ln_meshmask = ', ln_meshmask
-         WRITE(numout,*) '      ocean time step                         rn_Dt       = ', rn_Dt
-         WRITE(numout,*) '      asselin time filter parameter           rn_atfp     = ', rn_atfp
-         WRITE(numout,*) '      online coarsening of dynamical fields   ln_crs      = ', ln_crs
-      ENDIF
-      !
-      !! Initialise current model timestep rDt = 2*rn_Dt if MLF or rDt = rn_Dt if RK3
-      rDt  = 2._wp * rn_Dt
-      r1_Dt = 1._wp / rDt
-
-      IF( TRIM(Agrif_CFixed()) == '0' ) THEN
-         lrxios = ln_xios_read.AND.ln_rstart
-!set output file type for XIOS based on NEMO namelist 
-         IF (nn_wxios > 0) lwxios = .TRUE. 
-         nxioso = nn_wxios
-      ENDIF
-
-#if defined key_netcdf4
-      !                             ! NetCDF 4 case   ("key_netcdf4" defined)
-      READ  ( numnam_ref, namnc4, IOSTAT = ios, ERR = 907)
-907   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namnc4 in reference namelist' )
-      READ  ( numnam_cfg, namnc4, IOSTAT = ios, ERR = 908 )
-908   IF( ios >  0 )   CALL ctl_nam ( ios , 'namnc4 in configuration namelist' )
-      IF(lwm) WRITE( numond, namnc4 )
-
-      IF(lwp) THEN                        ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) '   Namelist namnc4 - Netcdf4 chunking parameters'
-         WRITE(numout,*) '      number of chunks in i-dimension             nn_nchunks_i = ', nn_nchunks_i
-         WRITE(numout,*) '      number of chunks in j-dimension             nn_nchunks_j = ', nn_nchunks_j
-         WRITE(numout,*) '      number of chunks in k-dimension             nn_nchunks_k = ', nn_nchunks_k
-         WRITE(numout,*) '      apply netcdf4/hdf5 chunking & compression   ln_nc4zip    = ', ln_nc4zip
-      ENDIF
-
-      ! Put the netcdf4 settings into a simple structure (snc4set, defined in in_out_manager module)
-      ! Note the chunk size in the unlimited (time) dimension will be fixed at 1
-      snc4set%ni   = nn_nchunks_i
-      snc4set%nj   = nn_nchunks_j
-      snc4set%nk   = nn_nchunks_k
-      snc4set%luse = ln_nc4zip
-#else
-      snc4set%luse = .FALSE.        ! No NetCDF 4 case
-#endif
-      !
-   END SUBROUTINE dom_nam
-
-
-   SUBROUTINE dom_ctl
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_ctl  ***
-      !!
-      !! ** Purpose :   Domain control.
-      !!
-      !! ** Method  :   compute and print extrema of masked scale factors
-      !!----------------------------------------------------------------------
-      LOGICAL, DIMENSION(jpi,jpj) ::   llmsk
-      INTEGER, DIMENSION(2)       ::   imil, imip, imi1, imi2, imal, imap, ima1, ima2
-      REAL(wp)                    ::   zglmin, zglmax, zgpmin, zgpmax, ze1min, ze1max, ze2min, ze2max
-      !!----------------------------------------------------------------------
-      !
-      llmsk = tmask_h(:,:) == 1._wp
-      !
-      CALL mpp_minloc( 'domain', glamt(:,:), llmsk, zglmin, imil )
-      CALL mpp_minloc( 'domain', gphit(:,:), llmsk, zgpmin, imip )
-      CALL mpp_minloc( 'domain',   e1t(:,:), llmsk, ze1min, imi1 )
-      CALL mpp_minloc( 'domain',   e2t(:,:), llmsk, ze2min, imi2 )
-      CALL mpp_maxloc( 'domain', glamt(:,:), llmsk, zglmax, imal )
-      CALL mpp_maxloc( 'domain', gphit(:,:), llmsk, zgpmax, imap )
-      CALL mpp_maxloc( 'domain',   e1t(:,:), llmsk, ze1max, ima1 )
-      CALL mpp_maxloc( 'domain',   e2t(:,:), llmsk, ze2max, ima2 )
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_ctl : extrema of the masked scale factors'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,"(14x,'glamt mini: ',1f10.2,' at i = ',i5,' j= ',i5)") zglmin, imil(1), imil(2)
-         WRITE(numout,"(14x,'glamt maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") zglmax, imal(1), imal(2)
-         WRITE(numout,"(14x,'gphit mini: ',1f10.2,' at i = ',i5,' j= ',i5)") zgpmin, imip(1), imip(2)
-         WRITE(numout,"(14x,'gphit maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") zgpmax, imap(1), imap(2)
-         WRITE(numout,"(14x,'  e1t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1min, imi1(1), imi1(2)
-         WRITE(numout,"(14x,'  e1t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze1max, ima1(1), ima1(2)
-         WRITE(numout,"(14x,'  e2t mini: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2min, imi2(1), imi2(2)
-         WRITE(numout,"(14x,'  e2t maxi: ',1f10.2,' at i = ',i5,' j= ',i5)") ze2max, ima2(1), ima2(2)
-      ENDIF
-      !
-   END SUBROUTINE dom_ctl
-
-
-   SUBROUTINE domain_cfg( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dom_nam  ***
-      !!                    
-      !! ** Purpose :   read the domain size in domain configuration file
-      !!
-      !! ** Method  :   read the cn_domcfg NetCDF file
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*)              , INTENT(out) ::   cd_cfg          ! configuration name
-      INTEGER                       , INTENT(out) ::   kk_cfg          ! configuration resolution
-      INTEGER                       , INTENT(out) ::   kpi, kpj, kpk   ! global domain sizes 
-      INTEGER                       , INTENT(out) ::   kperio          ! lateral global domain b.c. 
-      !
-      INTEGER ::   inum   ! local integer
-      REAL(wp) ::   zorca_res                     ! local scalars
-      REAL(wp) ::   zperio                        !   -      -
-      INTEGER, DIMENSION(4) ::   idvar, idimsz    ! size   of dimensions
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*) '           '
-         WRITE(numout,*) 'domain_cfg : domain size read in ', TRIM( cn_domcfg ), ' file'
-         WRITE(numout,*) '~~~~~~~~~~ '
-      ENDIF
-      !
-      CALL iom_open( cn_domcfg, inum )
-      !
-      !                                   !- ORCA family specificity
-      IF(  iom_varid( inum, 'ORCA'       , ldstop = .FALSE. ) > 0  .AND.  &
-         & iom_varid( inum, 'ORCA_index' , ldstop = .FALSE. ) > 0    ) THEN
-         !
-         cd_cfg = 'ORCA'
-         CALL iom_get( inum, 'ORCA_index', zorca_res )   ;   kk_cfg = NINT( zorca_res )
-         !
-         IF(lwp) THEN
-            WRITE(numout,*) '   .'
-            WRITE(numout,*) '   ==>>>   ORCA configuration '
-            WRITE(numout,*) '   .'
-         ENDIF
-         !
-      ELSE                                !- cd_cfg & k_cfg are not used
-         cd_cfg = 'UNKNOWN'
-         kk_cfg = -9999999
-                                          !- or they may be present as global attributes 
-                                          !- (netcdf only)  
-         CALL iom_getatt( inum, 'cn_cfg', cd_cfg )  ! returns   !  if not found
-         CALL iom_getatt( inum, 'nn_cfg', kk_cfg )  ! returns -999 if not found
-         IF( TRIM(cd_cfg) == '!') cd_cfg = 'UNKNOWN'
-         IF( kk_cfg == -999     ) kk_cfg = -9999999
-         !
-      ENDIF
-       !
-      idvar = iom_varid( inum, 'e3t_0', kdimsz = idimsz )   ! use e3t_0, that must exist, to get jp(ijk)glo
-      kpi = idimsz(1)
-      kpj = idimsz(2)
-      kpk = idimsz(3)
-      CALL iom_get( inum, 'jperio', zperio )   ;   kperio = NINT( zperio )
-      CALL iom_close( inum )
-      !
-      IF(lwp) THEN
-         WRITE(numout,*) '      cn_cfg = ', TRIM(cd_cfg), '   nn_cfg = ', kk_cfg
-         WRITE(numout,*) '      Ni0glo = ', kpi
-         WRITE(numout,*) '      Nj0glo = ', kpj
-         WRITE(numout,*) '      jpkglo = ', kpk
-         WRITE(numout,*) '      type of global domain lateral boundary   jperio = ', kperio
-      ENDIF
-      !        
-   END SUBROUTINE domain_cfg
-   
-   
-   SUBROUTINE cfg_write
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE cfg_write  ***
-      !!                   
-      !! ** Purpose :   Create the "cn_domcfg_out" file, a NetCDF file which 
-      !!              contains all the ocean domain informations required to 
-      !!              define an ocean configuration.
-      !!
-      !! ** Method  :   Write in a file all the arrays required to set up an
-      !!              ocean configuration.
-      !!
-      !! ** output file :   domcfg_out.nc : domain size, characteristics, horizontal 
-      !!                       mesh, Coriolis parameter, and vertical scale factors
-      !!                    NB: also contain ORCA family information
-      !!----------------------------------------------------------------------
-      INTEGER           ::   ji, jj, jk   ! dummy loop indices
-      INTEGER           ::   izco, izps, isco, icav
-      INTEGER           ::   inum     ! local units
-      CHARACTER(len=21) ::   clnam    ! filename (mesh and mask informations)
-      REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! workspace
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'cfg_write : create the domain configuration file (', TRIM(cn_domcfg_out),'.nc)'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~'
-      !
-      !                       ! ============================= !
-      !                       !  create 'domcfg_out.nc' file  !
-      !                       ! ============================= !
-      !         
-      clnam = cn_domcfg_out  ! filename (configuration information)
-      CALL iom_open( TRIM(clnam), inum, ldwrt = .TRUE. )     
-      !
-      !                             !==  ORCA family specificities  ==!
-      IF( TRIM(cn_cfg) == "orca" .OR. TRIM(cn_cfg) == "ORCA" ) THEN
-         CALL iom_rstput( 0, 0, inum, 'ORCA'      , 1._wp            , ktype = jp_i4 )
-         CALL iom_rstput( 0, 0, inum, 'ORCA_index', REAL( nn_cfg, wp), ktype = jp_i4 )         
-      ENDIF
-      !
-      !                             !==  domain characteristics  ==!
-      !
-      !                                   ! lateral boundary of the global domain
-      CALL iom_rstput( 0, 0, inum, 'jperio', REAL( jperio, wp), ktype = jp_i4 )
-      !
-      !                                   ! type of vertical coordinate
-      CALL iom_rstput( 0, 0, inum, 'ln_zco', REAL(COUNT((/ln_zco/)), wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'ln_zps', REAL(COUNT((/ln_zps/)), wp), ktype = jp_i4 )
-      CALL iom_rstput( 0, 0, inum, 'ln_sco', REAL(COUNT((/ln_sco/)), wp), ktype = jp_i4 )
-      !
-      !                                   ! ocean cavities under iceshelves
-      CALL iom_rstput( 0, 0, inum, 'ln_isfcav', REAL(COUNT((/ln_isfcav/)), wp), ktype = jp_i4 )
-      !
-      !                             !==  horizontal mesh  !
-      !
-      CALL iom_rstput( 0, 0, inum, 'glamt', glamt, ktype = jp_r8 )   ! latitude
-      CALL iom_rstput( 0, 0, inum, 'glamu', glamu, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'glamv', glamv, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'glamf', glamf, ktype = jp_r8 )
-      !                                
-      CALL iom_rstput( 0, 0, inum, 'gphit', gphit, ktype = jp_r8 )   ! longitude
-      CALL iom_rstput( 0, 0, inum, 'gphiu', gphiu, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'gphiv', gphiv, ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'gphif', gphif, ktype = jp_r8 )
-      !                                
-      CALL iom_rstput( 0, 0, inum, 'e1t'  , e1t  , ktype = jp_r8 )   ! i-scale factors (e1.)
-      CALL iom_rstput( 0, 0, inum, 'e1u'  , e1u  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e1v'  , e1v  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e1f'  , e1f  , ktype = jp_r8 )
-      !
-      CALL iom_rstput( 0, 0, inum, 'e2t'  , e2t  , ktype = jp_r8 )   ! j-scale factors (e2.)
-      CALL iom_rstput( 0, 0, inum, 'e2u'  , e2u  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e2v'  , e2v  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e2f'  , e2f  , ktype = jp_r8 )
-      !
-      CALL iom_rstput( 0, 0, inum, 'ff_f' , ff_f , ktype = jp_r8 )   ! coriolis factor
-      CALL iom_rstput( 0, 0, inum, 'ff_t' , ff_t , ktype = jp_r8 )
-      !
-      !                             !==  vertical mesh  ==!
-      !                                                     
-      CALL iom_rstput( 0, 0, inum, 'e3t_1d'  , e3t_1d , ktype = jp_r8 )   ! reference 1D-coordinate
-      CALL iom_rstput( 0, 0, inum, 'e3w_1d'  , e3w_1d , ktype = jp_r8 )
-      !
-      CALL iom_rstput( 0, 0, inum, 'e3t_0'   , e3t_0  , ktype = jp_r8 )   ! vertical scale factors
-      CALL iom_rstput( 0, 0, inum, 'e3u_0'   , e3u_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3v_0'   , e3v_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3f_0'   , e3f_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3w_0'   , e3w_0  , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3uw_0'  , e3uw_0 , ktype = jp_r8 )
-      CALL iom_rstput( 0, 0, inum, 'e3vw_0'  , e3vw_0 , ktype = jp_r8 )
-      !                                         
-      !                             !==  wet top and bottom level  ==!   (caution: multiplied by ssmask)
-      !
-      CALL iom_rstput( 0, 0, inum, 'top_level'    , REAL( mikt, wp )*ssmask , ktype = jp_i4 )   ! nb of ocean T-points (ISF)
-      CALL iom_rstput( 0, 0, inum, 'bottom_level' , REAL( mbkt, wp )*ssmask , ktype = jp_i4 )   ! nb of ocean T-points
-      !
-      IF( ln_sco ) THEN             ! s-coordinate: store grid stiffness ratio  (Not required anyway)
-         CALL dom_stiff( z2d )
-         CALL iom_rstput( 0, 0, inum, 'stiffness', z2d )        !    ! Max. grid stiffness ratio
-      ENDIF
-      !
-      IF( ll_wd ) THEN              ! wetting and drying domain
-         CALL iom_rstput( 0, 0, inum, 'ht_0'   , ht_0   , ktype = jp_r8 )
-      ENDIF
-      !
-      ! Add some global attributes ( netcdf only )
-      CALL iom_putatt( inum, 'nn_cfg', nn_cfg )
-      CALL iom_putatt( inum, 'cn_cfg', TRIM(cn_cfg) )
-      !
-      !                                ! ============================
-      !                                !        close the files 
-      !                                ! ============================
-      CALL iom_close( inum )
-      !
-   END SUBROUTINE cfg_write
-
-   !!======================================================================
-END MODULE domain
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dommsk.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dommsk.F90	(revision 14059)
+++ 	(revision )
@@ -1,295 +1,0 @@
-MODULE dommsk
-   !!======================================================================
-   !!                       ***  MODULE dommsk   ***
-   !! Ocean initialization : domain land/sea mask 
-   !!======================================================================
-   !! History :  OPA  ! 1987-07  (G. Madec)  Original code
-   !!            6.0  ! 1993-03  (M. Guyon)  symetrical conditions (M. Guyon)
-   !!            7.0  ! 1996-01  (G. Madec)  suppression of common work arrays
-   !!             -   ! 1996-05  (G. Madec)  mask computed from tmask
-   !!            8.0  ! 1997-02  (G. Madec)  mesh information put in domhgr.F
-   !!            8.1  ! 1997-07  (G. Madec)  modification of kbat and fmask
-   !!             -   ! 1998-05  (G. Roullet)  free surface
-   !!            8.2  ! 2000-03  (G. Madec)  no slip accurate
-   !!             -   ! 2001-09  (J.-M. Molines)  Open boundaries
-   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and module
-   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.2  ! 2009-07  (R. Benshila) Suppression of rigid-lid option
-   !!            3.6  ! 2015-05  (P. Mathiot) ISF: add wmask,wumask and wvmask
-   !!            4.0  ! 2016-06  (G. Madec, S. Flavoni)  domain configuration / user defined interface
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dom_msk       : compute land/ocean mask
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE usrdef_fmask   ! user defined fmask
-   USE bdy_oce        ! open boundary
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! IOM library
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp        ! Massively Parallel Processing library
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dom_msk    ! routine called by inidom.F90
-
-   !                            !!* Namelist namlbc : lateral boundary condition *
-   REAL(wp)        :: rn_shlat   ! type of lateral boundary condition on velocity
-   LOGICAL, PUBLIC :: ln_vorlat  !  consistency of vorticity boundary condition 
-   !                                            with analytical eqs.
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dommsk.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dom_msk( k_top, k_bot )
-      !!---------------------------------------------------------------------
-      !!                 ***  ROUTINE dom_msk  ***
-      !!
-      !! ** Purpose :   Compute land/ocean mask arrays at tracer points, hori-
-      !!      zontal velocity points (u & v), vorticity points (f) points.
-      !!
-      !! ** Method  :   The ocean/land mask  at t-point is deduced from ko_top 
-      !!      and ko_bot, the indices of the fist and last ocean t-levels which 
-      !!      are either defined in usrdef_zgr or read in zgr_read.
-      !!                The velocity masks (umask, vmask, wmask, wumask, wvmask) 
-      !!      are deduced from a product of the two neighboring tmask.
-      !!                The vorticity mask (fmask) is deduced from tmask taking
-      !!      into account the choice of lateral boundary condition (rn_shlat) :
-      !!         rn_shlat = 0, free slip  (no shear along the coast)
-      !!         rn_shlat = 2, no slip  (specified zero velocity at the coast)
-      !!         0 < rn_shlat < 2, partial slip   | non-linear velocity profile
-      !!         2 < rn_shlat, strong slip        | in the lateral boundary layer
-      !!
-      !!      tmask_i : interior ocean mask at t-point, i.e. excluding duplicated
-      !!                rows/lines due to cyclic or North Fold boundaries as well
-      !!                as MPP halos.
-      !!      tmask_h : halo mask at t-point, i.e. excluding duplicated rows/lines
-      !!                due to cyclic or North Fold boundaries as well as MPP halos.
-      !!
-      !! ** Action :   tmask, umask, vmask, wmask, wumask, wvmask : land/ocean mask 
-      !!                         at t-, u-, v- w, wu-, and wv-points (=0. or 1.)
-      !!               fmask   : land/ocean mask at f-point (=0., or =1., or 
-      !!                         =rn_shlat along lateral boundaries)
-      !!               tmask_i : interior ocean mask 
-      !!               tmask_h : halo mask
-      !!               ssmask , ssumask, ssvmask, ssfmask : 2D ocean mask
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(:,:), INTENT(in) ::   k_top, k_bot   ! first and last ocean level
-      !
-      INTEGER  ::   ji, jj, jk     ! dummy loop indices
-      INTEGER  ::   iif, iil       ! local integers
-      INTEGER  ::   ijf, ijl       !   -       -
-      INTEGER  ::   iktop, ikbot   !   -       -
-      INTEGER  ::   ios, inum
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zwf   ! 2D workspace
-      !!
-      NAMELIST/namlbc/ rn_shlat, ln_vorlat
-      NAMELIST/nambdy/ ln_bdy ,nb_bdy, ln_coords_file, cn_coords_file,         &
-         &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
-         &             cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta,             &
-         &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
-         &             cn_ice, nn_ice_dta,                                     &
-         &             ln_vol, nn_volctl, nn_rimwidth
-      !!---------------------------------------------------------------------
-      !
-      READ  ( numnam_ref, namlbc, IOSTAT = ios, ERR = 901 )
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namlbc in reference namelist' )
-      READ  ( numnam_cfg, namlbc, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namlbc in configuration namelist' )
-      IF(lwm) WRITE ( numond, namlbc )
-      
-      IF(lwp) THEN                  ! control print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dommsk : ocean mask '
-         WRITE(numout,*) '~~~~~~'
-         WRITE(numout,*) '   Namelist namlbc'
-         WRITE(numout,*) '      lateral momentum boundary cond.    rn_shlat  = ',rn_shlat
-         WRITE(numout,*) '      consistency with analytical form   ln_vorlat = ',ln_vorlat 
-      ENDIF
-      !
-      IF(lwp) WRITE(numout,*)
-      IF     (      rn_shlat == 0.               ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  free-slip'
-      ELSEIF (      rn_shlat == 2.               ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  no-slip'
-      ELSEIF ( 0. < rn_shlat .AND. rn_shlat < 2. ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  partial-slip'
-      ELSEIF ( 2. < rn_shlat                     ) THEN   ;   IF(lwp) WRITE(numout,*) '   ==>>>   ocean lateral  strong-slip'
-      ELSE
-         CALL ctl_stop( 'dom_msk: wrong value for rn_shlat (i.e. a negalive value). We stop.' )
-      ENDIF
-
-      !  Ocean/land mask at t-point  (computed from ko_top and ko_bot)
-      ! ----------------------------
-      !
-      tmask(:,:,:) = 0._wp
-      DO_2D( 1, 1, 1, 1 )
-         iktop = k_top(ji,jj)
-         ikbot = k_bot(ji,jj)
-         IF( iktop /= 0 ) THEN       ! water in the column
-            tmask(ji,jj,iktop:ikbot  ) = 1._wp
-         ENDIF
-      END_2D
-      !
-      ! the following call is mandatory
-      ! it masks boundaries (bathy=0) where needed depending on the configuration (closed, periodic...)  
-      CALL lbc_lnk( 'dommsk', tmask  , 'T', 1._wp )      ! Lateral boundary conditions
-
-     ! Mask corrections for bdy (read in mppini2)
-      READ  ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
-903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nambdy in reference namelist' )
-      READ  ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
-904   IF( ios >  0 )   CALL ctl_nam ( ios , 'nambdy in configuration namelist' )
-      ! ------------------------
-      IF ( ln_bdy .AND. ln_mask_file ) THEN
-         CALL iom_open( cn_mask_file, inum )
-         CALL iom_get ( inum, jpdom_data, 'bdy_msk', bdytmask(:,:) )
-         CALL iom_close( inum )
-         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-            tmask(ji,jj,jk) = tmask(ji,jj,jk) * bdytmask(ji,jj)
-         END_3D
-      ENDIF
-         
-      !  Ocean/land mask at u-, v-, and f-points   (computed from tmask)
-      ! ----------------------------------------
-      ! NB: at this point, fmask is designed for free slip lateral boundary condition
-      DO jk = 1, jpk
-         DO jj = 1, jpjm1
-            DO ji = 1, jpim1   ! vector loop
-               umask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)
-               vmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji  ,jj+1,jk)
-            END DO
-            DO ji = 1, jpim1      ! NO vector opt.
-               fmask(ji,jj,jk) = tmask(ji,jj  ,jk) * tmask(ji+1,jj  ,jk)   &
-                  &            * tmask(ji,jj+1,jk) * tmask(ji+1,jj+1,jk)
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk_multi( 'dommsk', umask, 'U', 1., vmask, 'V', 1., fmask, 'F', 1. )      ! Lateral boundary conditions
- 
-      ! Ocean/land mask at wu-, wv- and w points    (computed from tmask)
-      !-----------------------------------------
-      wmask (:,:,1) = tmask(:,:,1)     ! surface
-      wumask(:,:,1) = umask(:,:,1)
-      wvmask(:,:,1) = vmask(:,:,1)
-      DO jk = 2, jpk                   ! interior values
-         wmask (:,:,jk) = tmask(:,:,jk) * tmask(:,:,jk-1)
-         wumask(:,:,jk) = umask(:,:,jk) * umask(:,:,jk-1)   
-         wvmask(:,:,jk) = vmask(:,:,jk) * vmask(:,:,jk-1)
-      END DO
-
-
-      ! Ocean/land column mask at t-, u-, and v-points   (i.e. at least 1 wet cell in the vertical)
-      ! ----------------------------------------------
-      ssmask (:,:) = MAXVAL( tmask(:,:,:), DIM=3 )
-      ssumask(:,:) = MAXVAL( umask(:,:,:), DIM=3 )
-      ssvmask(:,:) = MAXVAL( vmask(:,:,:), DIM=3 )
-!!an 
-      ! ssfmask(:,:) = MAXVAL( fmask(:,:,:), DIM=3 )
-      DO_2D( 1, 0, 1, 0 )
-         ssfmask(ji,jj) = MAX(  tmask(ji,jj+1,1), tmask(ji+1,jj+1,1),  & 
-            &                   tmask(ji,jj  ,1), tmask(ji+1,jj  ,1)   )
-      END_2D
-      CALL lbc_lnk( 'dommsk', ssfmask, 'F', 1._wp )   
-
-!!an
-
-      ! Interior domain mask  (used for global sum)
-      ! --------------------
-      !
-      iif = nn_hls   ;   iil = nlci - nn_hls + 1
-      ijf = nn_hls   ;   ijl = nlcj - nn_hls + 1
-      !
-      !                          ! halo mask : 0 on the halo and 1 elsewhere
-      tmask_h(:,:) = 1._wp                  
-      tmask_h( 1 :iif,   :   ) = 0._wp      ! first columns
-      tmask_h(iil:jpi,   :   ) = 0._wp      ! last  columns (including mpp extra columns)
-      tmask_h(   :   , 1 :ijf) = 0._wp      ! first rows
-      tmask_h(   :   ,ijl:jpj) = 0._wp      ! last  rows (including mpp extra rows)
-      !
-      !                          ! north fold mask
-      tpol(1:jpiglo) = 1._wp 
-      fpol(1:jpiglo) = 1._wp
-      IF( jperio == 3 .OR. jperio == 4 ) THEN      ! T-point pivot
-         tpol(jpiglo/2+1:jpiglo) = 0._wp
-         fpol(     1    :jpiglo) = 0._wp
-         IF( mjg(nlej) == jpjglo ) THEN                  ! only half of the nlcj-1 row for tmask_h
-            DO ji = iif+1, iil-1
-               tmask_h(ji,nlej-1) = tmask_h(ji,nlej-1) * tpol(mig(ji))
-            END DO
-         ENDIF
-      ENDIF
-      !
-      IF( jperio == 5 .OR. jperio == 6 ) THEN      ! F-point pivot
-         tpol(     1    :jpiglo) = 0._wp
-         fpol(jpiglo/2+1:jpiglo) = 0._wp
-      ENDIF
-      !
-      !                          ! interior mask : 2D ocean mask x halo mask 
-      tmask_i(:,:) = ssmask(:,:) * tmask_h(:,:)
-
-
-      ! Lateral boundary conditions on velocity (modify fmask)
-      ! ---------------------------------------  
-      IF( rn_shlat /= 0 ) THEN      ! Not free-slip lateral boundary condition
-         !
-         ALLOCATE( zwf(jpi,jpj) )
-         !
-         DO jk = 1, jpk
-            zwf(:,:) = fmask(:,:,jk)         
-            DO_2D( 0, 0, 0, 0 )
-               IF( fmask(ji,jj,jk) == 0._wp ) THEN
-                  fmask(ji,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jj), zwf(ji,jj+1),   &
-                     &                                           zwf(ji-1,jj), zwf(ji,jj-1)  )  )
-               ENDIF
-            END_2D
-            DO jj = 2, jpjm1
-               IF( fmask(1,jj,jk) == 0._wp ) THEN
-                  fmask(1  ,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(2,jj), zwf(1,jj+1), zwf(1,jj-1) ) )
-               ENDIF
-               IF( fmask(jpi,jj,jk) == 0._wp ) THEN
-                  fmask(jpi,jj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(jpi,jj+1), zwf(jpim1,jj), zwf(jpi,jj-1) ) )
-               ENDIF
-            END DO         
-            DO ji = 2, jpim1
-               IF( fmask(ji,1,jk) == 0._wp ) THEN
-                  fmask(ji, 1 ,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,1), zwf(ji,2), zwf(ji-1,1) ) )
-               ENDIF
-               IF( fmask(ji,jpj,jk) == 0._wp ) THEN
-                  fmask(ji,jpj,jk) = rn_shlat * MIN( 1._wp , MAX( zwf(ji+1,jpj), zwf(ji-1,jpj), zwf(ji,jpjm1) ) )
-               ENDIF
-            END DO
-#if defined key_agrif 
-            IF( .NOT. AGRIF_Root() ) THEN 
-               IF ((nbondi ==  1).OR.(nbondi == 2)) fmask(nlci-1 , :     ,jk) = 0.e0      ! east 
-               IF ((nbondi == -1).OR.(nbondi == 2)) fmask(1      , :     ,jk) = 0.e0      ! west 
-               IF ((nbondj ==  1).OR.(nbondj == 2)) fmask(:      ,nlcj-1 ,jk) = 0.e0      ! north 
-               IF ((nbondj == -1).OR.(nbondj == 2)) fmask(:      ,1      ,jk) = 0.e0      ! south 
-            ENDIF 
-#endif 
-         END DO
-         !
-         DEALLOCATE( zwf )
-         !
-         CALL lbc_lnk( 'dommsk', fmask, 'F', 1._wp )      ! Lateral boundary conditions on fmask
-         !
-         ! CAUTION : The fmask may be further modified in dyn_vor_init ( dynvor.F90 ) depending on ln_vorlat
-         !
-      ENDIF
-      
-      ! User defined alteration of fmask (use to reduce ocean transport in specified straits)
-      ! -------------------------------- 
-      !
-      CALL usr_def_fmask( cn_cfg, nn_cfg, fmask )
-      !
-   END SUBROUTINE dom_msk
-   
-   !!======================================================================
-END MODULE dommsk
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/domvvl.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/domvvl.F90	(revision 14059)
+++ 	(revision )
@@ -1,1348 +1,0 @@
-
-MODULE domvvl
-   !!======================================================================
-   !!                       ***  MODULE domvvl   ***
-   !! Ocean : 
-   !!======================================================================
-   !! History :  2.0  !  2006-06  (B. Levier, L. Marie)  original code
-   !!            3.1  !  2009-02  (G. Madec, M. Leclair, R. Benshila)  pure z* coordinate
-   !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl: vvl option includes z_star and z_tilde coordinates
-   !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
-   !!----------------------------------------------------------------------
-
-   USE oce             ! ocean dynamics and tracers
-   USE phycst          ! physical constant
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! ocean surface boundary condition
-   USE wet_dry         ! wetting and drying
-   USE usrdef_istate   ! user defined initial state (wad only)
-   USE restart         ! ocean restart
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE lib_mpp         ! distributed memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   !                                                      !!* Namelist nam_vvl
-   LOGICAL , PUBLIC :: ln_vvl_zstar           = .FALSE.    ! zstar  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde          = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_layer           = .FALSE.    ! level  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde_as_zstar = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_zstar_at_eqtor  = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_kepe            = .FALSE.    ! kinetic/potential energy transfer
-   !                                                       ! conservation: not used yet
-   REAL(wp)         :: rn_ahe3                             ! thickness diffusion coefficient
-   REAL(wp)         :: rn_rst_e3t                          ! ztilde to zstar restoration timescale [days]
-   REAL(wp)         :: rn_lf_cutoff                        ! cutoff frequency for low-pass filter  [days]
-   REAL(wp)         :: rn_zdef_max                         ! maximum fractional e3t deformation
-   LOGICAL , PUBLIC :: ln_vvl_dbg = .FALSE.                ! debug control prints
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: un_td, vn_td                ! thickness diffusion transport
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: hdiv_lf                     ! low frequency part of hz divergence
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_b, tilde_e3t_n    ! baroclinic scale factors
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_a, dtilde_e3t_a   ! baroclinic scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_e3t                 ! retoring period for scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                 ! retoring period for low freq. divergence
-!!stoops
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-#else
-   !!----------------------------------------------------------------------
-   !!   Default key      Old management of time varying vertical coordinate
-   !!----------------------------------------------------------------------
-!!st
-   !!----------------------------------------------------------------------
-   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
-   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
-   !!   dom_vvl_sf_update   : Swap vertical scale factors and update the vertical grid
-   !!   dom_vvl_interpol : Interpolate vertical scale factors from one grid point to another
-   !!   dom_vvl_rst      : read/write restart file
-   !!   dom_vvl_ctl      : Check the vvl options
-   !!----------------------------------------------------------------------
-  
-   PUBLIC  dom_vvl_init       ! called by domain.F90
-   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
-   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
-   PUBLIC  dom_vvl_sf_update  ! called by step.F90
-   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
-   PUBLIC  dom_vvl_interpol_st! called by dynnxt.F90
-   PUBLIC  dom_vvl_sf_nxt_st  ! called by step.F90
-   PUBLIC  dom_vvl_sf_update_st
-!!st
-   
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: domvvl.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION dom_vvl_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION dom_vvl_alloc  ***
-      !!----------------------------------------------------------------------
-      IF( ln_vvl_zstar )   dom_vvl_alloc = 0
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         ALLOCATE( tilde_e3t_b(jpi,jpj,jpk)  , tilde_e3t_n(jpi,jpj,jpk) , tilde_e3t_a(jpi,jpj,jpk) ,   &
-            &      dtilde_e3t_a(jpi,jpj,jpk) , un_td  (jpi,jpj,jpk)     , vn_td  (jpi,jpj,jpk)     ,   &
-            &      STAT = dom_vvl_alloc        )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-         un_td = 0._wp
-         vn_td = 0._wp
-      ENDIF
-      IF( ln_vvl_ztilde ) THEN
-         ALLOCATE( frq_rst_e3t(jpi,jpj) , frq_rst_hdv(jpi,jpj) , hdiv_lf(jpi,jpj,jpk) , STAT= dom_vvl_alloc )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-      ENDIF
-      !
-   END FUNCTION dom_vvl_alloc
-
-
-   SUBROUTINE dom_vvl_init( Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Initialization of all scale factors, depths
-      !!               and water column heights
-      !!
-      !! ** Method  :  - use restart file and/or initialize
-      !!               - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3[u/v](:,:,:,Kmm)
-      !!                        e3[u/v](:,:,:,Kmm)       
-      !!                        e3w(:,:,:,Kmm)           
-      !!                        e3[u/v]w_b
-      !!                        e3[u/v]w_n      
-      !!                        gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm) and gde3w
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dom_vvl_init : Variable volume activated'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      !
-      CALL dom_vvl_ctl     ! choose vertical coordinate (z_star, z_tilde or layer)
-      !
-      !                    ! Allocate module arrays
-      IF( dom_vvl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_init : unable to allocate arrays' )
-      !
-      !                    ! Read or initialize e3t_(b/n), tilde_e3t_(b/n) and hdiv_lf
-      CALL dom_vvl_rst( nit000, Kbb, Kmm, 'READ' )
-      e3t(:,:,jpk,Kaa) = e3t_0(:,:,jpk)  ! last level always inside the sea floor set one for all
-      !
-      CALL dom_vvl_zgr_st(Kbb, Kmm, Kaa) ! interpolation scale factor, depth and water column
-      !
-   END SUBROUTINE dom_vvl_init
-   !
-   SUBROUTINE dom_vvl_zgr(Kbb, Kmm, Kaa)
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Interpolation of all scale factors, 
-      !!               depths and water column heights
-      !!
-      !! ** Method  :  - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3(u/v)_n
-      !!                        e3(u/v)_b       
-      !!                        e3w_n           
-      !!                        e3(u/v)w_b      
-      !!                        e3(u/v)w_n      
-      !!                        gdept_n, gdepw_n and gde3w_n
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   ii0, ii1, ij0, ij1
-      REAL(wp)::   zcoef
-      !!----------------------------------------------------------------------
-      !
-      !                    !== Set of all other vertical scale factors  ==!  (now and before)
-      !                                ! Horizontal interpolation of e3t
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3u(:,:,:,Kbb), 'U' )    ! from T to U
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3v(:,:,:,Kbb), 'V' )    ! from T to V 
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3f(:,:,:), 'F' )    ! from U to F
-      !                                ! Vertical interpolation of e3t,u,v 
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )  ! from T to W
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3w (:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )  ! from U to UW
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )  ! from V to UW
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! We need to define e3[tuv]_a for AGRIF initialisation (should not be a problem for the restartability...)
-      e3t(:,:,:,Kaa) = e3t(:,:,:,Kmm)
-      e3u(:,:,:,Kaa) = e3u(:,:,:,Kmm)
-      e3v(:,:,:,Kaa) = e3v(:,:,:,Kmm)
-      !
-      !                    !==  depth of t and w-point  ==!   (set the isf depth as it is in the initial timestep)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)       ! reference to the ocean surface (used for MLD and light penetration)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)  ! reference to a common level z=0 for hpg
-      gdept(:,:,1,Kbb) = 0.5_wp * e3w(:,:,1,Kbb)
-      gdepw(:,:,1,Kbb) = 0.0_wp
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-         !    zcoef = tmask - wmask    ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-         !                             ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
-         !                             ! 0.5 where jk = mikt     
-!!gm ???????   BUG ?  gdept(:,:,:,Kmm) as well as gde3w  does not include the thickness of ISF ??
-         zcoef = ( tmask(ji,jj,jk) - wmask(ji,jj,jk) )
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm)) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-         gdepw(ji,jj,jk,Kbb) = gdepw(ji,jj,jk-1,Kbb) + e3t(ji,jj,jk-1,Kbb)
-         gdept(ji,jj,jk,Kbb) =      zcoef  * ( gdepw(ji,jj,jk  ,Kbb) + 0.5 * e3w(ji,jj,jk,Kbb))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kbb) +       e3w(ji,jj,jk,Kbb)) 
-      END_3D
-      !
-      !                    !==  thickness of the water column  !!   (ocean portion only)
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)   !!gm  BUG  :  this should be 1/2 * e3w(k=1) ....
-      hu(:,:,Kbb) = e3u(:,:,1,Kbb) * umask(:,:,1)
-      hu(:,:,Kmm) = e3u(:,:,1,Kmm) * umask(:,:,1)
-      hv(:,:,Kbb) = e3v(:,:,1,Kbb) * vmask(:,:,1)
-      hv(:,:,Kmm) = e3v(:,:,1,Kmm) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         hu(:,:,Kbb) = hu(:,:,Kbb) + e3u(:,:,jk,Kbb) * umask(:,:,jk)
-         hu(:,:,Kmm) = hu(:,:,Kmm) + e3u(:,:,jk,Kmm) * umask(:,:,jk)
-         hv(:,:,Kbb) = hv(:,:,Kbb) + e3v(:,:,jk,Kbb) * vmask(:,:,jk)
-         hv(:,:,Kmm) = hv(:,:,Kmm) + e3v(:,:,jk,Kmm) * vmask(:,:,jk)
-      END DO
-      !
-      !                    !==  inverse of water column thickness   ==!   (u- and v- points)
-      r1_hu(:,:,Kbb) = ssumask(:,:) / ( hu(:,:,Kbb) + 1._wp - ssumask(:,:) )    ! _i mask due to ISF
-      r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kbb) = ssvmask(:,:) / ( hv(:,:,Kbb) + 1._wp - ssvmask(:,:) )
-      r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) )
-
-      !                    !==   z_tilde coordinate case  ==!   (Restoring frequencies)
-      IF( ln_vvl_ztilde ) THEN
-!!gm : idea: add here a READ in a file of custumized restoring frequency
-         !                                   ! Values in days provided via the namelist
-         !                                   ! use rsmall to avoid possible division by zero errors with faulty settings
-         frq_rst_e3t(:,:) = 2._wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.0_wp )
-         frq_rst_hdv(:,:) = 2._wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.0_wp )
-         !
-         IF( ln_vvl_ztilde_as_zstar ) THEN   ! z-star emulation using z-tile
-            frq_rst_e3t(:,:) = 0._wp               !Ignore namelist settings
-            frq_rst_hdv(:,:) = 1._wp / rn_Dt
-         ENDIF
-         IF ( ln_vvl_zstar_at_eqtor ) THEN   ! use z-star in vicinity of the Equator
-            DO_2D( 1, 1, 1, 1 )
-!!gm  case |gphi| >= 6 degrees is useless   initialized just above by default
-               IF( ABS(gphit(ji,jj)) >= 6.) THEN
-                  ! values outside the equatorial band and transition zone (ztilde)
-                  frq_rst_e3t(ji,jj) =  2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.e0_wp )
-                  frq_rst_hdv(ji,jj) =  2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.e0_wp )
-               ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN    ! Equator strip ==> z-star
-                  ! values inside the equatorial band (ztilde as zstar)
-                  frq_rst_e3t(ji,jj) =  0.0_wp
-                  frq_rst_hdv(ji,jj) =  1.0_wp / rn_Dt
-               ELSE                                      ! transition band (2.5 to 6 degrees N/S)
-                  !                                      ! (linearly transition from z-tilde to z-star)
-                  frq_rst_e3t(ji,jj) = 0.0_wp + (frq_rst_e3t(ji,jj)-0.0_wp)*0.5_wp   &
-                     &            * (  1.0_wp - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-                  frq_rst_hdv(ji,jj) = (1.0_wp / rn_Dt)                                &
-                     &            + (  frq_rst_hdv(ji,jj)-(1.e0_wp / rn_Dt) )*0.5_wp   &
-                     &            * (  1._wp  - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-               ENDIF
-            END_2D
-            IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
-               IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-                  ii0 = 103 + nn_hls - 1   ;   ii1 = 111 + nn_hls - 1      
-                  ij0 = 128 + nn_hls       ;   ij1 = 135 + nn_hls
-                  frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
-                  frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rn_Dt
-               ENDIF
-            ENDIF
-         ENDIF
-      ENDIF
-      !
-      IF(lwxios) THEN
-! define variables in restart file when writing with XIOS
-         CALL iom_set_rstw_var_active('e3t_b')
-         CALL iom_set_rstw_var_active('e3t_n')
-         !                                           ! ----------------------- !
-         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
-            !                                        ! ----------------------- !
-            CALL iom_set_rstw_var_active('tilde_e3t_b')
-            CALL iom_set_rstw_var_active('tilde_e3t_n')
-         END IF
-         !                                           ! -------------!    
-         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
-            !                                        ! ------------ !
-            CALL iom_set_rstw_var_active('hdiv_lf')
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_zgr
-
-   
-   SUBROUTINE dom_vvl_zgr_st(Kbb, Kmm, Kaa)
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Interpolation of all scale factors, 
-      !!               depths and water column heights
-      !!
-      !! ** Method  :  - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3(u/v)_n
-      !!                        e3(u/v)_b       
-      !!                        e3w_n           
-      !!                        e3(u/v)w_b      
-      !!                        e3(u/v)w_n      
-      !!                        gdept_n, gdepw_n and gde3w_n
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   ii0, ii1, ij0, ij1
-      REAL(wp)::   zcoef
-      !!----------------------------------------------------------------------
-      !
-      !                    !== Set of all other vertical scale factors  ==!  (now and before)
-      !                                ! Horizontal interpolation of e3t
-      CALL dom_vvl_interpol_st( r3u(:,:,Kbb), e3u(:,:,:,Kbb), 'U' )    ! from T to U
-      CALL dom_vvl_interpol_st( r3u(:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kbb), e3v(:,:,:,Kbb), 'V' )    ! from T to V 
-      CALL dom_vvl_interpol_st( r3v(:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-      CALL dom_vvl_interpol_st( r3f(:,:), e3f(:,:,:), 'F' )    ! from U to F
-      !                                ! Vertical interpolation of e3t,u,v 
-      CALL dom_vvl_interpol_st( r3t(:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )  ! from T to W
-      CALL dom_vvl_interpol_st( r3t(:,:,Kbb), e3w (:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol_st( r3u(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )  ! from U to UW
-      CALL dom_vvl_interpol_st( r3u(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )  ! from V to UW
-      CALL dom_vvl_interpol_st( r3v(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! We need to define e3[tuv]_a for AGRIF initialisation (should not be a problem for the restartability...)
-      e3t(:,:,:,Kaa) = e3t(:,:,:,Kmm)
-      e3u(:,:,:,Kaa) = e3u(:,:,:,Kmm)
-      e3v(:,:,:,Kaa) = e3v(:,:,:,Kmm)
-      !
-      DO_3D( 1, 1, 1, 1, 1, jpk )
-         gdepw(ji,jj,jk,Kmm) =  gdepw_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm))
-         gdept(ji,jj,jk,Kmm) =  gdept_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm)) 
-         gde3w(ji,jj,jk    ) =  gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-         gdepw(ji,jj,jk,Kbb) =  gdepw_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kbb))
-         gdept(ji,jj,jk,Kbb) =  gdept_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kbb)) 
-      END_3D     
-      !
-      !                    !==  thickness of the water column  !!   (ocean portion only)
-      ht(:,:) = ht_0(:,:) + ssh(:,:,Kmm)
-      hu(:,:,Kbb) = (hu_0(:,:)*(1._wp+r3u(:,:,Kbb)))
-      hv(:,:,Kbb) = (hv_0(:,:)*(1._wp+r3v(:,:,Kbb)))
-      hu(:,:,Kbb) = (hu_0(:,:)*(1._wp+r3u(:,:,Kmm)))
-      hv(:,:,Kbb) = (hv_0(:,:)*(1._wp+r3v(:,:,Kmm)))
-      !                    !==  inverse of water column thickness   ==!   (u- and v- points)
-      r1_hu(:,:,Kbb) = ssumask(:,:) / ( hu(:,:,Kbb) + 1._wp - ssumask(:,:) )    ! _i mask due to ISF
-      r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kbb) = ssvmask(:,:) / ( hv(:,:,Kbb) + 1._wp - ssvmask(:,:) )
-      r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) ) 
-      !
-      IF(lwxios) THEN
-! define variables in restart file when writing with XIOS
-         CALL iom_set_rstw_var_active('e3t_b')
-         CALL iom_set_rstw_var_active('e3t_n')
-         !
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_zgr_st
-   
-
-   SUBROUTINE dom_vvl_sf_nxt( kt, Kbb, Kmm, Kaa, kcall ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_nxt  ***
-      !!                   
-      !! ** Purpose :  - compute the after scale factors used in tra_zdf, dynnxt,
-      !!                 tranxt and dynspg routines
-      !!
-      !! ** Method  :  - z_star case:  Repartition of ssh INCREMENT proportionnaly to the level thickness.
-      !!               - z_tilde_case: after scale factor increment = 
-      !!                                    high frequency part of horizontal divergence
-      !!                                  + retsoring towards the background grid
-      !!                                  + thickness difusion
-      !!                               Then repartition of ssh INCREMENT proportionnaly
-      !!                               to the "baroclinic" level thickness.
-      !!
-      !! ** Action  :  - hdiv_lf    : restoring towards full baroclinic divergence in z_tilde case
-      !!               - tilde_e3t_a: after increment of vertical scale factor 
-      !!                              in z_tilde case
-      !!               - e3(t/u/v)_a
-      !!
-      !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )           ::   kt             ! time step
-      INTEGER, INTENT( in )           ::   Kbb, Kmm, Kaa  ! time step
-      INTEGER, INTENT( in ), OPTIONAL ::   kcall          ! optional argument indicating call sequence
-      !
-      INTEGER                ::   ji, jj, jk            ! dummy loop indices
-      INTEGER , DIMENSION(3) ::   ijk_max, ijk_min      ! temporary integers
-      REAL(wp)               ::   z_tmin, z_tmax        ! local scalars
-      LOGICAL                ::   ll_do_bclinic         ! local logical
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3t
-      LOGICAL , DIMENSION(:,:,:), ALLOCATABLE ::   llmsk
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_nxt')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
-      ENDIF
-
-      ll_do_bclinic = .TRUE.
-      IF( PRESENT(kcall) ) THEN
-         IF( kcall == 2 .AND. ln_vvl_ztilde )   ll_do_bclinic = .FALSE.
-      ENDIF
-
-      ! ******************************* !
-      ! After acale factors at t-points !
-      ! ******************************* !
-      !                                                ! --------------------------------------------- !
-      !                                                ! z_star coordinate and barotropic z-tilde part !
-      !                                                ! --------------------------------------------- !
-      !
-      z_scale(:,:) = ( ssh(:,:,Kaa) - ssh(:,:,Kbb) ) * ssmask(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-      DO jk = 1, jpkm1
-         ! formally this is the same as e3t(:,:,:,Kaa) = e3t_0*(1+ssha/ht_0)
-         e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kbb) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-      END DO
-      !
-      IF( (ln_vvl_ztilde .OR. ln_vvl_layer) .AND. ll_do_bclinic ) THEN   ! z_tilde or layer coordinate !
-         !                                                               ! ------baroclinic part------ !
-         ! I - initialization
-         ! ==================
-
-         ! 1 - barotropic divergence
-         ! -------------------------
-         zhdiv(:,:) = 0._wp
-         zht(:,:)   = 0._wp
-         DO jk = 1, jpkm1
-            zhdiv(:,:) = zhdiv(:,:) + e3t(:,:,jk,Kmm) * hdiv(:,:,jk)
-            zht  (:,:) = zht  (:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         zhdiv(:,:) = zhdiv(:,:) / ( zht(:,:) + 1. - tmask_i(:,:) )
-
-         ! 2 - Low frequency baroclinic horizontal divergence  (z-tilde case only)
-         ! --------------------------------------------------
-         IF( ln_vvl_ztilde ) THEN
-            IF( kt > nit000 ) THEN
-               DO jk = 1, jpkm1
-                  hdiv_lf(:,:,jk) = hdiv_lf(:,:,jk) - rn_Dt * frq_rst_hdv(:,:)   &
-                     &          * ( hdiv_lf(:,:,jk) - e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) )
-               END DO
-            ENDIF
-         ENDIF
-
-         ! II - after z_tilde increments of vertical scale factors
-         ! =======================================================
-         tilde_e3t_a(:,:,:) = 0._wp  ! tilde_e3t_a used to store tendency terms
-
-         ! 1 - High frequency divergence term
-         ! ----------------------------------
-         IF( ln_vvl_ztilde ) THEN     ! z_tilde case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - ( e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) - hdiv_lf(:,:,jk) )
-            END DO
-         ELSE                         ! layer case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) -   e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) * tmask(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 2 - Restoring term (z-tilde case only)
-         ! ------------------
-         IF( ln_vvl_ztilde ) THEN
-            DO jk = 1, jpk
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - frq_rst_e3t(:,:) * tilde_e3t_b(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 3 - Thickness diffusion term
-         ! ----------------------------
-         zwu(:,:) = 0._wp
-         zwv(:,:) = 0._wp
-         DO_3D( 1, 0, 1, 0, 1, jpkm1 )
-            un_td(ji,jj,jk) = rn_ahe3 * umask(ji,jj,jk) * e2_e1u(ji,jj)           &
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji+1,jj  ,jk) )
-            vn_td(ji,jj,jk) = rn_ahe3 * vmask(ji,jj,jk) * e1_e2v(ji,jj)           & 
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji  ,jj+1,jk) )
-            zwu(ji,jj) = zwu(ji,jj) + un_td(ji,jj,jk)
-            zwv(ji,jj) = zwv(ji,jj) + vn_td(ji,jj,jk)
-         END_3D
-         DO_2D( 1, 1, 1, 1 )
-            un_td(ji,jj,mbku(ji,jj)) = un_td(ji,jj,mbku(ji,jj)) - zwu(ji,jj)
-            vn_td(ji,jj,mbkv(ji,jj)) = vn_td(ji,jj,mbkv(ji,jj)) - zwv(ji,jj)
-         END_2D
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            tilde_e3t_a(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) + (   un_td(ji-1,jj  ,jk) - un_td(ji,jj,jk)    &
-               &                                          +     vn_td(ji  ,jj-1,jk) - vn_td(ji,jj,jk)    &
-               &                                            ) * r1_e1e2t(ji,jj)
-         END_3D
-         !                       ! d - thickness diffusion transport: boundary conditions
-         !                             (stored for tracer advction and continuity equation)
-         CALL lbc_lnk_multi( 'domvvl', un_td , 'U' , -1._wp, vn_td , 'V' , -1._wp)
-
-         ! 4 - Time stepping of baroclinic scale factors
-         ! ---------------------------------------------
-         CALL lbc_lnk( 'domvvl', tilde_e3t_a(:,:,:), 'T', 1._wp )
-         tilde_e3t_a(:,:,:) = tilde_e3t_b(:,:,:) + rDt * tmask(:,:,:) * tilde_e3t_a(:,:,:)
-
-         ! Maximum deformation control
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ALLOCATE( ze3t(jpi,jpj,jpk), llmsk(jpi,jpj,jpk) )
-         ze3t(:,:,jpk) = 0._wp
-         DO jk = 1, jpkm1
-            ze3t(:,:,jk) = tilde_e3t_a(:,:,jk) / e3t_0(:,:,jk) * tmask(:,:,jk) * tmask_i(:,:)
-         END DO
-         !
-         llmsk(   1:Nis1,:,:) = .FALSE.   ! exclude halos from the checked region
-         llmsk(Nie1: jpi,:,:) = .FALSE.
-         llmsk(:,   1:Njs1,:) = .FALSE.
-         llmsk(:,Nje1: jpj,:) = .FALSE.
-         !
-         llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp                  ! define only the inner domain
-         z_tmax = MAXVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_max( 'domvvl', z_tmax )   ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_min( 'domvvl', z_tmin )   ! min over the global domain
-         ! - ML - test: for the moment, stop simulation for too large e3_t variations
-         IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            CALL mpp_maxloc( 'domvvl', ze3t, llmsk, z_tmax, ijk_max )
-            CALL mpp_minloc( 'domvvl', ze3t, llmsk, z_tmin, ijk_min )
-            IF (lwp) THEN
-               WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
-               WRITE(numout, *) 'at i, j, k=', ijk_max
-               WRITE(numout, *) 'MIN( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmin
-               WRITE(numout, *) 'at i, j, k=', ijk_min            
-               CALL ctl_stop( 'STOP', 'MAX( ABS( tilde_e3t_a(:,:,: ) ) / e3t_0(:,:,:) ) too high')
-            ENDIF
-         ENDIF
-         DEALLOCATE( ze3t, llmsk )
-         ! - ML - end test
-         ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
-         tilde_e3t_a(:,:,:) = MIN( tilde_e3t_a(:,:,:),   rn_zdef_max * e3t_0(:,:,:) )
-         tilde_e3t_a(:,:,:) = MAX( tilde_e3t_a(:,:,:), - rn_zdef_max * e3t_0(:,:,:) )
-
-         !
-         ! "tilda" change in the after scale factor
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - tilde_e3t_b(:,:,jk)
-         END DO
-         ! III - Barotropic repartition of the sea surface height over the baroclinic profile
-         ! ==================================================================================
-         ! add ( ssh increment + "baroclinicity error" ) proportionly to e3t(n)
-         ! - ML - baroclinicity error should be better treated in the future
-         !        i.e. locally and not spread over the water column.
-         !        (keep in mind that the idea is to reduce Eulerian velocity as much as possible)
-         zht(:,:) = 0.
-         DO jk = 1, jpkm1
-            zht(:,:)  = zht(:,:) + tilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-         z_scale(:,:) =  - zht(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = dtilde_e3t_a(:,:,jk) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-         END DO
-
-      ENDIF
-
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer )  THEN   ! z_tilde or layer coordinate !
-      !                                           ! ---baroclinic part--------- !
-         DO jk = 1, jpkm1
-            e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kaa) + dtilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-      ENDIF
-
-      IF( ln_vvl_dbg .AND. .NOT. ll_do_bclinic ) THEN   ! - ML - test: control prints for debuging
-         !
-         IF( lwp ) WRITE(numout, *) 'kt =', kt
-         IF ( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-            z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( zht(:,:) ) )
-            CALL mpp_max( 'domvvl', z_tmax )                             ! max over the global domain
-            IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(SUM(tilde_e3t_a))) =', z_tmax
-         END IF
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kmm) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshn-SUM(e3t(:,:,:,Kmm)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kaa) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kaa) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+ssha-SUM(e3t(:,:,:,Kaa)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kbb) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kbb) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshb-SUM(e3t(:,:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kbb) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kmm) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kmm)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kaa) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kaa)))) =', z_tmax
-      END IF
-
-      ! *********************************** !
-      ! After scale factors at u- v- points !
-      ! *********************************** !
-
-      CALL dom_vvl_interpol( ssh(:,:,Kaa), e3u(:,:,:,Kaa), 'U' )
-      CALL dom_vvl_interpol( ssh(:,:,Kaa), e3v(:,:,:,Kaa), 'V' )
-
-      ! *********************************** !
-      ! After depths at u- v points         !
-      ! *********************************** !
-
-      hu(:,:,Kaa) = e3u(:,:,1,Kaa) * umask(:,:,1)
-      hv(:,:,Kaa) = e3v(:,:,1,Kaa) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         hu(:,:,Kaa) = hu(:,:,Kaa) + e3u(:,:,jk,Kaa) * umask(:,:,jk)
-         hv(:,:,Kaa) = hv(:,:,Kaa) + e3v(:,:,jk,Kaa) * vmask(:,:,jk)
-      END DO
-      !                                        ! Inverse of the local depth
-!!gm BUG ?  don't understand the use of umask_i here .....
-      r1_hu(:,:,Kaa) = ssumask(:,:) / ( hu(:,:,Kaa) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kaa) = ssvmask(:,:) / ( hv(:,:,Kaa) + 1._wp - ssvmask(:,:) )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_nxt')
-      !
-   END SUBROUTINE dom_vvl_sf_nxt
-
-
-
-   SUBROUTINE dom_vvl_sf_nxt_st( kt, Kbb, Kmm, Kaa, kcall ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_nxt  ***
-      !!                   
-      !! ** Purpose :  - compute the after scale factors used in tra_zdf, dynnxt,
-      !!                 tranxt and dynspg routines
-      !!
-      !! ** Method  :  - z_star case:  Repartition of ssh INCREMENT proportionnaly to the level thickness.
-      !!               - z_tilde_case: after scale factor increment = 
-      !!                                    high frequency part of horizontal divergence
-      !!                                  + retsoring towards the background grid
-      !!                                  + thickness difusion
-      !!                               Then repartition of ssh INCREMENT proportionnaly
-      !!                               to the "baroclinic" level thickness.
-      !!
-      !! ** Action  :  - hdiv_lf    : restoring towards full baroclinic divergence in z_tilde case
-      !!               - tilde_e3t_a: after increment of vertical scale factor 
-      !!                              in z_tilde case
-      !!               - e3(t/u/v)_a
-      !!
-      !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )           ::   kt             ! time step
-      INTEGER, INTENT( in )           ::   Kbb, Kmm, Kaa  ! time step
-      INTEGER, INTENT( in ), OPTIONAL ::   kcall          ! optional argument indicating call sequence
-      !
-      INTEGER                ::   ji, jj, jk            ! dummy loop indices
-      INTEGER , DIMENSION(3) ::   ijk_max, ijk_min      ! temporary integers
-      REAL(wp)               ::   z_tmin, z_tmax        ! local scalars
-      LOGICAL                ::   ll_do_bclinic         ! local logical
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_nxt')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
-      ENDIF
-
-      ll_do_bclinic = .TRUE.
-      IF( PRESENT(kcall) ) THEN
-         IF( kcall == 2 .AND. ln_vvl_ztilde )   ll_do_bclinic = .FALSE.
-      ENDIF
-
-      ! ******************************* !
-      ! After acale factors at t-points !
-      ! ******************************* !
-      !
-      DO jk = 1, jpkm1
-         e3t(:,:,jk,Kaa) = e3t_0(:,:,jk) * ( 1._wp + r3t(:,:,Kaa) )
-         e3u(:,:,jk,Kaa) = e3u_0(:,:,jk) * ( 1._wp + r3u(:,:,Kaa) )
-         e3v(:,:,jk,Kaa) = e3v_0(:,:,jk) * ( 1._wp + r3v(:,:,Kaa) )
-      END DO
-      !
-      ! *********************************** !
-      ! After scale factors at u- v- points !
-      ! *********************************** !
-      
-      !!st CALL dom_vvl_interpol_st( r3u(:,:,Kaa), e3u(:,:,:,Kaa), 'U' )
-      !!st CALL dom_vvl_interpol_st( r3v(:,:,Kaa), e3v(:,:,:,Kaa), 'V' )
-
-      ! *********************************** !
-      ! After depths at u- v points         !
-      ! *********************************** !
-
-      !!st hu(:,:,Kaa) = e3u(:,:,1,Kaa) * umask(:,:,1)
-      !!st hv(:,:,Kaa) = e3v(:,:,1,Kaa) * vmask(:,:,1)
-      !!st DO jk = 2, jpkm1
-      !!st    hu(:,:,Kaa) = hu(:,:,Kaa) + e3u(:,:,jk,Kaa) * umask(:,:,jk)
-      !!st    hv(:,:,Kaa) = hv(:,:,Kaa) + e3v(:,:,jk,Kaa) * vmask(:,:,jk)
-      !!st    
-      !!st END DO
-      hu(:,:,Kaa) = (hu_0(:,:)*(1._wp+r3u(:,:,Kaa)))
-      hv(:,:,Kaa) = (hv_0(:,:)*(1._wp+r3v(:,:,Kaa)))
-      !                                        ! Inverse of the local depth
-!!gm BUG ?  don't understand the use of umask_i here .....
-      r1_hu(:,:,Kaa) = ssumask(:,:) / ( hu(:,:,Kaa) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kaa) = ssvmask(:,:) / ( hv(:,:,Kaa) + 1._wp - ssvmask(:,:) )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_nxt')
-      !
-   END SUBROUTINE dom_vvl_sf_nxt_st
-   
-
-
-   SUBROUTINE dom_vvl_sf_update( kt, Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_update  ***
-      !!                   
-      !! ** Purpose :  for z tilde case: compute time filter and swap of scale factors 
-      !!               compute all depths and related variables for next time step
-      !!               write outputs and restart file
-      !!
-      !! ** Method  :  - swap of e3t with trick for volume/tracer conservation (ONLY FOR Z TILDE CASE)
-      !!               - reconstruct scale factor at other grid points (interpolate)
-      !!               - recompute depths and water height fields
-      !!
-      !! ** Action  :  - tilde_e3t_(b/n) ready for next time step
-      !!               - Recompute:
-      !!                    e3(u/v)_b       
-      !!                    e3w(:,:,:,Kmm)           
-      !!                    e3(u/v)w_b      
-      !!                    e3(u/v)w_n      
-      !!                    gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm)  and gde3w
-      !!                    h(u/v) and h(u/v)r
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
-      !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt              ! time step
-      INTEGER, INTENT( in ) ::   Kbb, Kmm, Kaa   ! time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoef        ! local scalar
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_update')
-      !
-      IF( kt == nit000 )   THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_update : - interpolate scale factors and compute depths for next time step'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
-      ENDIF
-      !
-      ! Time filter and swap of scale factors
-      ! =====================================
-      ! - ML - e3(t/u/v)_b are allready computed in dynnxt.
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         IF( l_1st_euler ) THEN
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:)
-         ELSE
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:) & 
-            &         + rn_atfp * ( tilde_e3t_b(:,:,:) - 2.0_wp * tilde_e3t_n(:,:,:) + tilde_e3t_a(:,:,:) )
-         ENDIF
-         tilde_e3t_n(:,:,:) = tilde_e3t_a(:,:,:)
-      ENDIF
-
-      ! Compute all missing vertical scale factor and depths
-      ! ====================================================
-      ! Horizontal scale factor interpolations
-      ! --------------------------------------
-      ! - ML - e3u(:,:,:,Kbb) and e3v(:,:,:,Kbb) are already computed in dynnxt
-      ! - JC - hu(:,:,:,Kbb), hv(:,:,:,:,Kbb), hur_b, hvr_b also
-      
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3f(:,:,:), 'F'  )
-      
-      ! Vertical scale factor interpolations
-      CALL dom_vvl_interpol( ssh(:,:,Kmm),  e3w(:,:,:,Kmm), 'W'  )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb),  e3w(:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( ssh(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! t- and w- points depth (set the isf depth as it is in the initial step)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-        !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-                                                           ! 1 for jk = mikt
-         zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =    zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm) )  &
-             &             + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm) ) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-      END_3D
-
-      ! Local depth and Inverse of the local depth of the water
-      ! -------------------------------------------------------
-      !
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-      END DO
-
-      ! write restart file
-      ! ==================
-      IF( lrst_oce  )   CALL dom_vvl_rst( kt, Kbb, Kmm, 'WRITE' )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_update')
-      !
-   END SUBROUTINE dom_vvl_sf_update
-   
-
-   SUBROUTINE dom_vvl_sf_update_st( kt, Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_update  ***
-      !!                   
-      !! ** Purpose :  for z tilde case: compute time filter and swap of scale factors 
-      !!               compute all depths and related variables for next time step
-      !!               write outputs and restart file
-      !!
-      !! ** Method  :  - swap of e3t with trick for volume/tracer conservation (ONLY FOR Z TILDE CASE)
-      !!               - reconstruct scale factor at other grid points (interpolate)
-      !!               - recompute depths and water height fields
-      !!
-      !! ** Action  :  - tilde_e3t_(b/n) ready for next time step
-      !!               - Recompute:
-      !!                    e3(u/v)_b       
-      !!                    e3w(:,:,:,Kmm)           
-      !!                    e3(u/v)w_b      
-      !!                    e3(u/v)w_n      
-      !!                    gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm)  and gde3w
-      !!                    h(u/v) and h(u/v)r
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
-      !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt              ! time step
-      INTEGER, INTENT( in ) ::   Kbb, Kmm, Kaa   ! time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoef        ! local scalar
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_update')
-      !
-      IF( kt == nit000 )   THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_update : - interpolate scale factors and compute depths for next time step'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
-      ENDIF
-      !
-
-      ! Compute all missing vertical scale factor and depths
-      ! ====================================================
-      ! Horizontal scale factor interpolations
-      ! --------------------------------------
-      ! - ML - e3u(:,:,:,Kbb) and e3v(:,:,:,Kbb) are already computed in dynnxt
-      ! - JC - hu(:,:,:,Kbb), hv(:,:,:,:,Kbb), hur_b, hvr_b also
-      
-      CALL dom_vvl_interpol_st( r3f(:,:), e3f(:,:,:), 'F'  )
-
-      ! Vertical scale factor interpolations
-      CALL dom_vvl_interpol_st( r3t(:,:,Kmm),  e3w(:,:,:,Kmm), 'W'  )
-      CALL dom_vvl_interpol_st( r3u(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-      CALL dom_vvl_interpol_st( r3t(:,:,Kbb),  e3w(:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol_st( r3u(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol_st( r3v(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! t- and w- points depth (set the isf depth as it is in the initial step)
-      DO_3D( 1, 1, 1, 1, 1, jpk )
-         gdepw(ji,jj,jk,Kmm) =  gdepw_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm))
-         gdept(ji,jj,jk,Kmm) =  gdept_0(ji,jj,jk) * (1._wp + r3t(ji,jj,Kmm)) 
-         gde3w(ji,jj,jk    ) =  gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-      END_3D
-
-      ! Local depth and Inverse of the local depth of the water
-      ! -------------------------------------------------------
-      !
-      ht(:,:) = ht_0(:,:) + ssh(:,:,Kmm)
-
-      ! write restart file
-      ! ==================
-      IF( lrst_oce  )   CALL dom_vvl_rst( kt, Kbb, Kmm, 'WRITE' )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_update')
-      !
-   END SUBROUTINE dom_vvl_sf_update_st
-   
-
-    
-   SUBROUTINE dom_vvl_interpol_st( rc3, pe3, cdp )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl__interpol  ***
-      !!
-      !! ** Purpose :   interpolate scale factors from one grid point to another
-      !!
-      !! ** Method  :   e3_out = e3_0 + interpolation(e3_in - e3_0)
-      !!                - horizontal interpolation: grid cell surface averaging
-      !!                - vertical interpolation: simple averaging
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   rc3     ! input e3   NOT used here (ssh is used instead)
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pe3     ! scale factor e3 to be updated   [m]
-      CHARACTER(LEN=*)          , INTENT(in   ) ::   cdp     ! grid point of the scale factor ( 'U', 'V', 'W, 'F', 'UW' or 'VW' )
-      !
-      INTEGER ::   ji, jj, jk                 ! dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj) ::   zc3   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      SELECT CASE ( cdp )     !==  type of interpolation  ==!
-         !
-      CASE( 'U' )                   !* from T- to U-point : hor. surface weighted mean
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3u_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'V' )                   !* from T- to V-point : hor. surface weighted mean
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3v_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'F' )                   !* from U-point to F-point : hor. surface weighted mean
-         DO jk = 1, jpkm1                    ! Horizontal interpolation of e3f from ssh
-            e3f(:,:,jk) = e3f_0(:,:,jk) * ( 1._wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'W' )                   !* from T- to W-point : vertical simple mean
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3w_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      CASE( 'UW' )                  !* from U- to UW-point
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3uw_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-      CASE( 'VW' )                  !* from U- to UW-point : vertical simple mean
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3vw_0(:,:,jk) * ( 1.0_wp + rc3(:,:) )
-         END DO
-         !
-      END SELECT
-      !
-   END SUBROUTINE dom_vvl_interpol_st
-   
-
-   SUBROUTINE dom_vvl_interpol( pssh, pe3, cdp )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl__interpol  ***
-      !!
-      !! ** Purpose :   interpolate scale factors from one grid point to another
-      !!
-      !! ** Method  :   e3_out = e3_0 + interpolation(e3_in - e3_0)
-      !!                - horizontal interpolation: grid cell surface averaging
-      !!                - vertical interpolation: simple averaging
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:)  , INTENT(in   ) ::   pssh    ! input e3   NOT used here (ssh is used instead)
-      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pe3     ! scale factor e3 to be updated   [m]
-      CHARACTER(LEN=*)          , INTENT(in   ) ::   cdp     ! grid point of the scale factor ( 'U', 'V', 'W, 'F', 'UW' or 'VW' )
-      !
-      INTEGER ::   ji, jj, jk                 ! dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj) ::   zc3   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      SELECT CASE ( cdp )     !==  type of interpolation  ==!
-         !
-      CASE( 'U' )                   !* from T- to U-point : hor. surface weighted mean
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji  ,jj) * pssh(ji  ,jj)  &
-               &                   + e1e2t(ji+1,jj) * pssh(ji+1,jj)  ) * r1_hu_0(ji,jj) * r1_e1e2u(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'U', 1._wp )
-         !
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3u_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'V' )                   !* from T- to V-point : hor. surface weighted mean
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji,jj  ) * pssh(ji,jj  )  &
-               &                   + e1e2t(ji,jj+1) * pssh(ji,jj+1)  ) * r1_hv_0(ji,jj) * r1_e1e2v(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'V', 1._wp )
-         !
-         DO jk = 1, jpkm1
-            pe3(:,:,jk) = e3v_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'F' )                   !* from U-point to F-point : hor. surface weighted mean
-         DO_2D( 1, 0, 1, 0 )
-            zc3(ji,jj) = 0.25_wp * (  e1e2t(ji  ,jj  ) * pssh(ji  ,jj  )  &
-               &                    + e1e2t(ji+1,jj  ) * pssh(ji+1,jj  )  &
-               &                    + e1e2t(ji  ,jj+1) * pssh(ji  ,jj+1)  &
-               &                    + e1e2t(ji+1,jj+1) * pssh(ji+1,jj+1)  ) * r1_hf_0(ji,jj) * r1_e1e2f(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'F', 1._wp )
-         !
-         DO jk = 1, jpkm1                    ! Horizontal interpolation of e3f from ssh
-            e3f(:,:,jk)     = e3f_0(:,:,jk) * ( 1._wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'W' )                   !* from T- to W-point : vertical simple mean
-         zc3(:,:) = pssh(:,:) * r1_ht_0(:,:)
-         !
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3w_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      CASE( 'UW' )                  !* from U- to UW-point
-         !
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji  ,jj) * pssh(ji  ,jj)  &
-               &                   + e1e2t(ji+1,jj) * pssh(ji+1,jj)  ) * r1_hu_0(ji,jj) * r1_e1e2u(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'U', 1._wp )
-         !
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3uw_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-      CASE( 'VW' )                  !* from U- to UW-point : vertical simple mean
-         !
-         DO_2D( 0, 0, 0, 0 )
-            zc3(ji,jj) = 0.5_wp * (  e1e2t(ji,jj  ) * pssh(ji,jj  )  &
-               &                   + e1e2t(ji,jj+1) * pssh(ji,jj+1)  ) * r1_hv_0(ji,jj) * r1_e1e2v(ji,jj)
-         END_2D
-         CALL lbc_lnk( 'domvvl', zc3(:,:), 'V', 1._wp )
-          !
-         DO jk = 1, jpk
-            pe3(:,:,jk) = e3vw_0(:,:,jk) * ( 1.0_wp + zc3(:,:) )
-         END DO
-         !
-      END SELECT
-      !
-   END SUBROUTINE dom_vvl_interpol
-   
-
-   SUBROUTINE dom_vvl_rst( kt, Kbb, Kmm, cdrw )
-      !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE dom_vvl_rst  ***
-      !!                     
-      !! ** Purpose :   Read or write VVL file in restart file
-      !!
-      !! ** Method  :   use of IOM library
-      !!                if the restart does not contain vertical scale factors,
-      !!                they are set to the _0 values
-      !!                if the restart does not contain vertical scale factors increments (z_tilde),
-      !!                they are set to 0.
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt        ! ocean time-step
-      INTEGER         , INTENT(in) ::   Kbb, Kmm  ! ocean time level indices
-      CHARACTER(len=*), INTENT(in) ::   cdrw      ! "READ"/"WRITE" flag
-      !
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   id1, id2, id3, id4, id5     ! local integers
-      !!----------------------------------------------------------------------
-      !
-      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-         !                                   ! ===============
-         IF( ln_rstart ) THEN                   !* Read the restart file
-            CALL rst_read_open                  !  open the restart file if necessary
-            CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm)    )
-            !
-            id1 = iom_varid( numror, 'e3t_b', ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'e3t_n', ldstop = .FALSE. )
-            id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
-            id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
-            id5 = iom_varid( numror, 'hdiv_lf', ldstop = .FALSE. )
-            !
-            !                             ! --------- !
-            !                             ! all cases !
-            !                             ! --------- !
-            !
-            IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               ! needed to restart if land processor not computed 
-               IF(lwp) write(numout,*) 'dom_vvl_rst : e3t(:,:,:,Kbb) and e3t(:,:,:,Kmm) found in restart files'
-               WHERE ( tmask(:,:,:) == 0.0_wp ) 
-                  e3t(:,:,:,Kmm) = e3t_0(:,:,:)
-                  e3t(:,:,:,Kbb) = e3t_0(:,:,:)
-               END WHERE
-               IF( l_1st_euler ) THEN
-                  e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               ENDIF
-            ELSE IF( id1 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_n set equal to e3t_b.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               l_1st_euler = .true.
-            ELSE IF( id2 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kbb) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_b set equal to e3t_n.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ELSE
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart file'
-               IF(lwp) write(numout,*) 'Compute scale factor from sshn'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm) ) &
-                      &                          / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                      &          + e3t_0(:,:,jk)                               * (1._wp -tmask(:,:,jk))
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ENDIF
-            !                             ! ----------- !
-            IF( ln_vvl_zstar ) THEN       ! z_star case !
-               !                          ! ----------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN
-                  CALL ctl_stop( 'dom_vvl_rst: z_star cannot restart from a z_tilde or layer run' )
-               ENDIF
-               !                          ! ----------------------- !
-            ELSE                          ! z_tilde and layer cases !
-               !                          ! ----------------------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN  ! all required arrays exist
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
-               ELSE                            ! one at least array is missing
-                  tilde_e3t_b(:,:,:) = 0.0_wp
-                  tilde_e3t_n(:,:,:) = 0.0_wp
-               ENDIF
-               !                          ! ------------ !
-               IF( ln_vvl_ztilde ) THEN   ! z_tilde case !
-                  !                       ! ------------ !
-                  IF( id5 > 0 ) THEN  ! required array exists
-                     CALL iom_get( numror, jpdom_auto, 'hdiv_lf', hdiv_lf(:,:,:) )
-                  ELSE                ! array is missing
-                     hdiv_lf(:,:,:) = 0.0_wp
-                  ENDIF
-               ENDIF
-            ENDIF
-            !
-         ELSE                                   !* Initialize at "rest"
-            !
-
-            IF( ll_wd ) THEN   ! MJB ll_wd edits start here - these are essential 
-               !
-               IF( cn_cfg == 'wad' ) THEN
-                  ! Wetting and drying test case
-                  CALL usr_def_istate( gdept(:,:,:,Kbb), tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-!!an                  ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-                  ssh (:,:,Kmm)     = ssh(:,:,Kbb)
-                  uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
-                  vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
-               ELSE
-                  ! if not test case
-                  ssh(:,:,Kmm) = -ssh_ref
-                  ssh(:,:,Kbb) = -ssh_ref
-
-                  DO_2D( 1, 1, 1, 1 )
-                     IF( ht_0(ji,jj)-ssh_ref <  rn_wdmin1 ) THEN ! if total depth is less than min depth
-                        ssh(ji,jj,Kbb) = rn_wdmin1 - (ht_0(ji,jj) )
-                        ssh(ji,jj,Kmm) = rn_wdmin1 - (ht_0(ji,jj) )
-                     ENDIF
-                  END_2D
-               ENDIF !If test case else
-
-               ! Adjust vertical metrics for all wad
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm)  ) &
-                    &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-
-               DO ji = 1, jpi
-                  DO jj = 1, jpj
-                     IF ( ht_0(ji,jj) .LE. 0.0 .AND. NINT( ssmask(ji,jj) ) .EQ. 1) THEN
-                       CALL ctl_stop( 'dom_vvl_rst: ht_0 must be positive at potentially wet points' )
-                     ENDIF
-                  END DO 
-               END DO 
-               !
-            ELSE
-               !
-               ! Just to read set ssh in fact, called latter once vertical grid
-               ! is set up:
-!               CALL usr_def_istate( gdept_0, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-!               !
-!               DO jk=1,jpk
-!                  e3t(:,:,jk,Kbb) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kbb) ) &
-!                     &            / ( ht_0(:,:) + 1._wp -ssmask(:,:) ) * tmask(:,:,jk)
-!               END DO
-!               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-                ssh(:,:,Kmm)=0._wp
-                ssh(:,:,Kbb)=0._wp
-                e3t(:,:,:,Kmm)=e3t_0(:,:,:)
-                e3t(:,:,:,Kbb)=e3t_0(:,:,:)
-               !
-            END IF           ! end of ll_wd edits
-
-            IF( ln_vvl_ztilde .OR. ln_vvl_layer) THEN
-               tilde_e3t_b(:,:,:) = 0._wp
-               tilde_e3t_n(:,:,:) = 0._wp
-               IF( ln_vvl_ztilde ) hdiv_lf(:,:,:) = 0._wp
-            END IF
-         ENDIF
-         !
-      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-         !                                   ! ===================
-         IF(lwp) WRITE(numout,*) '---- dom_vvl_rst ----'
-         !                                           ! --------- !
-         !                                           ! all cases !
-         !                                           ! --------- !
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_b', e3t(:,:,:,Kbb) )
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t(:,:,:,Kmm) )
-         !                                           ! ----------------------- !
-         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
-            !                                        ! ----------------------- !
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_b', tilde_e3t_b(:,:,:))
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_n', tilde_e3t_n(:,:,:))
-         END IF
-         !                                           ! -------------!    
-         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
-            !                                        ! ------------ !
-            CALL iom_rstput( kt, nitrst, numrow, 'hdiv_lf', hdiv_lf(:,:,:))
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_rst
-
-
-   SUBROUTINE dom_vvl_ctl
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl_ctl  ***
-      !!                
-      !! ** Purpose :   Control the consistency between namelist options
-      !!                for vertical coordinate
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios
-      !!
-      NAMELIST/nam_vvl/ ln_vvl_zstar, ln_vvl_ztilde, ln_vvl_layer, ln_vvl_ztilde_as_zstar, &
-         &              ln_vvl_zstar_at_eqtor      , rn_ahe3     , rn_rst_e3t            , &
-         &              rn_lf_cutoff               , rn_zdef_max , ln_vvl_dbg                ! not yet implemented: ln_vvl_kepe
-      !!---------------------------------------------------------------------- 
-      !
-      READ  ( numnam_ref, nam_vvl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist' )
-      READ  ( numnam_cfg, nam_vvl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist' )
-      IF(lwm) WRITE ( numond, nam_vvl )
-      !
-      IF(lwp) THEN                    ! Namelist print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_vvl_ctl : choice/control of the variable vertical coordinate'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist nam_vvl : chose a vertical coordinate'
-         WRITE(numout,*) '      zstar                      ln_vvl_zstar   = ', ln_vvl_zstar
-         WRITE(numout,*) '      ztilde                     ln_vvl_ztilde  = ', ln_vvl_ztilde
-         WRITE(numout,*) '      layer                      ln_vvl_layer   = ', ln_vvl_layer
-         WRITE(numout,*) '      ztilde as zstar   ln_vvl_ztilde_as_zstar  = ', ln_vvl_ztilde_as_zstar
-         WRITE(numout,*) '      ztilde near the equator    ln_vvl_zstar_at_eqtor  = ', ln_vvl_zstar_at_eqtor
-         WRITE(numout,*) '      !'
-         WRITE(numout,*) '      thickness diffusion coefficient                      rn_ahe3      = ', rn_ahe3
-         WRITE(numout,*) '      maximum e3t deformation fractional change            rn_zdef_max  = ', rn_zdef_max
-         IF( ln_vvl_ztilde_as_zstar ) THEN
-            WRITE(numout,*) '      ztilde running in zstar emulation mode (ln_vvl_ztilde_as_zstar=T) '
-            WRITE(numout,*) '         ignoring namelist timescale parameters and using:'
-            WRITE(numout,*) '            hard-wired : z-tilde to zstar restoration timescale (days)'
-            WRITE(numout,*) '                         rn_rst_e3t     = 0.e0'
-            WRITE(numout,*) '            hard-wired : z-tilde cutoff frequency of low-pass filter (days)'
-            WRITE(numout,*) '                         rn_lf_cutoff   = 1.0/rn_Dt'
-         ELSE
-            WRITE(numout,*) '      z-tilde to zstar restoration timescale (days)        rn_rst_e3t   = ', rn_rst_e3t
-            WRITE(numout,*) '      z-tilde cutoff frequency of low-pass filter (days)   rn_lf_cutoff = ', rn_lf_cutoff
-         ENDIF
-         WRITE(numout,*) '         debug prints flag                                 ln_vvl_dbg   = ', ln_vvl_dbg
-      ENDIF
-      !
-      ioptio = 0                      ! Parameter control
-      IF( ln_vvl_ztilde_as_zstar )   ln_vvl_ztilde = .true.
-      IF( ln_vvl_zstar           )   ioptio = ioptio + 1
-      IF( ln_vvl_ztilde          )   ioptio = ioptio + 1
-      IF( ln_vvl_layer           )   ioptio = ioptio + 1
-      !
-      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE vertical coordinate in namelist nam_vvl' )
-      !
-      IF(lwp) THEN                   ! Print the choice
-         WRITE(numout,*)
-         IF( ln_vvl_zstar           ) WRITE(numout,*) '      ==>>>   zstar vertical coordinate is used'
-         IF( ln_vvl_ztilde          ) WRITE(numout,*) '      ==>>>   ztilde vertical coordinate is used'
-         IF( ln_vvl_layer           ) WRITE(numout,*) '      ==>>>   layer vertical coordinate is used'
-         IF( ln_vvl_ztilde_as_zstar ) WRITE(numout,*) '      ==>>>   to emulate a zstar coordinate'
-      ENDIF
-      !
-#if defined key_agrif
-      IF( (.NOT.Agrif_Root()).AND.(.NOT.ln_vvl_zstar) )   CALL ctl_stop( 'AGRIF is implemented with zstar coordinate only' )
-#endif
-      !
-   END SUBROUTINE dom_vvl_ctl
-
-#endif
-!!stoops
-
-   !!======================================================================
-END MODULE domvvl
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/domzgr_substitute.h90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/domzgr_substitute.h90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/domzgr_substitute.h90	(revision 14062)
@@ -16,4 +16,5 @@
 #   define  e3v(i,j,k,t)   (e3v_0(i,j,k)*(1._wp+r3v(i,j,t)))
 #   define  e3f(i,j,k)     (e3f_0(i,j,k)*(1._wp+r3f(i,j)))
+#   define  e3f_vor(i,j,k) (e3f_0vor(i,j,k)*(1._wp+r3f(i,j)))
 #   define  e3w(i,j,k,t)   (e3w_0(i,j,k)*(1._wp+r3t(i,j,t)))
 #   define  e3uw(i,j,k,t)  (e3uw_0(i,j,k)*(1._wp+r3u(i,j,t)))
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynadv.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynadv.F90	(revision 14059)
+++ 	(revision )
@@ -1,153 +1,0 @@
-MODULE dynadv
-   !!==============================================================================
-   !!                       ***  MODULE  dynadv  ***
-   !! Ocean active tracers:  advection scheme control
-   !!==============================================================================
-   !! History :  1.0  !  2006-11  (G. Madec)  Original code
-   !!            3.3  !  2010-10  (C. Ethe, G. Madec)  reorganisation of initialisation phase
-   !!            3.6  !  2015-05  (N. Ducousso, G. Madec)  add Hollingsworth scheme as an option 
-   !!            4.0  !  2017-07  (G. Madec)  add a linear dynamics option
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_adv      : compute the momentum advection trend 
-   !!   dyn_adv_init : control the different options of advection scheme
-   !!----------------------------------------------------------------------
-   USE dom_oce         ! ocean space and time domain
-   USE dynadv_cen2     ! centred flux form advection      (dyn_adv_cen2 routine)
-   USE dynadv_ubs      ! UBS flux form advection          (dyn_adv_ubs  routine)
-   USE dynkeg          ! kinetic energy gradient          (dyn_keg      routine)
-   USE dynzad          ! vertical advection               (dyn_zad      routine)
-   !
-   USE in_out_manager  ! I/O manager
-   USE lib_mpp         ! MPP library
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC dyn_adv       ! routine called by step module
-   PUBLIC dyn_adv_init  ! routine called by opa  module
- 
-   !                                   !!* namdyn_adv namelist *
-   LOGICAL, PUBLIC ::   ln_dynadv_OFF   !: linear dynamics (no momentum advection)
-   LOGICAL, PUBLIC ::   ln_dynadv_vec   !: vector form
-   INTEGER, PUBLIC ::      nn_dynkeg       !: scheme of grad(KE): =0 C2 ; =1 Hollingsworth
-   LOGICAL, PUBLIC ::   ln_dynadv_cen2  !: flux form - 2nd order centered scheme flag
-   LOGICAL, PUBLIC ::   ln_dynadv_ubs   !: flux form - 3rd order UBS scheme flag
-   
-   INTEGER, PUBLIC ::   n_dynadv   !: choice of the formulation and scheme for momentum advection
-   !                               !  associated indices:
-   INTEGER, PUBLIC, PARAMETER ::   np_LIN_dyn = 0   ! no advection: linear dynamics
-   INTEGER, PUBLIC, PARAMETER ::   np_VEC_c2  = 1   ! vector form : 2nd order centered scheme
-   INTEGER, PUBLIC, PARAMETER ::   np_FLX_c2  = 2   ! flux   form : 2nd order centered scheme
-   INTEGER, PUBLIC, PARAMETER ::   np_FLX_ubs = 3   ! flux   form : 3rd order Upstream Biased Scheme
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynadv.F90 12822 2020-04-28 09:10:38Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_adv( kt, Kbb, Kmm, puu, pvv, Krhs )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_adv  ***
-      !!                
-      !! ** Purpose :   compute the ocean momentum advection trend.
-      !!
-      !! ** Method  : - Update (puu(:,:,:,Krhs),pvv(:,:,:,Krhs)) with the advection term following n_dynadv
-      !!
-      !!      NB: in flux form advection (ln_dynadv_cen2 or ln_dynadv_ubs=T) 
-      !!      a metric term is add to the coriolis term while in vector form 
-      !!      it is the relative vorticity which is added to coriolis term
-      !!      (see dynvor module).
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT( in )  ::  kt               ! ocean time-step index
-      INTEGER                             , INTENT( in )  ::  Kbb, Kmm, Krhs   ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv         ! ocean velocities and RHS of momentum equation
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start( 'dyn_adv' )
-      !
-      SELECT CASE( n_dynadv )    !==  compute advection trend and add it to general trend  ==!
-      CASE( np_VEC_c2  )     
-         CALL dyn_keg     ( kt, nn_dynkeg,      Kmm, puu, pvv, Krhs )    ! vector form : horizontal gradient of kinetic energy
-         CALL dyn_zad     ( kt,                 Kmm, puu, pvv, Krhs )    ! vector form : vertical advection
-      CASE( np_FLX_c2  ) 
-         CALL dyn_adv_cen2( kt,                 Kmm, puu, pvv, Krhs )    ! 2nd order centered scheme
-      CASE( np_FLX_ubs )   
-         CALL dyn_adv_ubs ( kt,            Kbb, Kmm, puu, pvv, Krhs )    ! 3rd order UBS      scheme (UP3)
-      END SELECT
-      !
-      IF( ln_timing )   CALL timing_stop( 'dyn_adv' )
-      !
-   END SUBROUTINE dyn_adv
-
-   
-   SUBROUTINE dyn_adv_init
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_adv_init  ***
-      !!                
-      !! ** Purpose :   Control the consistency between namelist options for 
-      !!              momentum advection formulation & scheme and set n_dynadv
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios   ! Local integer
-      !
-      NAMELIST/namdyn_adv/ ln_dynadv_OFF, ln_dynadv_vec, nn_dynkeg, ln_dynadv_cen2, ln_dynadv_ubs
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dyn_adv_init : choice/control of the momentum advection scheme'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      !
-      READ  ( numnam_ref, namdyn_adv, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_adv in reference namelist' )
-      READ  ( numnam_cfg, namdyn_adv, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_adv in configuration namelist' )
-      IF(lwm) WRITE ( numond, namdyn_adv )
-
-      IF(lwp) THEN                    ! Namelist print
-         WRITE(numout,*) '   Namelist namdyn_adv : chose a advection formulation & scheme for momentum'
-         WRITE(numout,*) '      linear dynamics : no momentum advection          ln_dynadv_OFF  = ', ln_dynadv_OFF
-         WRITE(numout,*) '      Vector form: 2nd order centered scheme           ln_dynadv_vec  = ', ln_dynadv_vec
-!!an45
-         WRITE(numout,*) '         with Hollingsworth scheme (=1) or not (=0,2)      nn_dynkeg  = ', nn_dynkeg
-!!an45
-         WRITE(numout,*) '      flux form: 2nd order centred scheme              ln_dynadv_cen2 = ', ln_dynadv_cen2
-         WRITE(numout,*) '                 3rd order UBS scheme                  ln_dynadv_ubs  = ', ln_dynadv_ubs
-      ENDIF
-
-      ioptio = 0                      ! parameter control and set n_dynadv
-      IF( ln_dynadv_OFF  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_LIN_dyn   ;   ENDIF
-      IF( ln_dynadv_vec  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_VEC_c2    ;   ENDIF
-      IF( ln_dynadv_cen2 ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_FLX_c2    ;   ENDIF
-      IF( ln_dynadv_ubs  ) THEN   ;   ioptio = ioptio + 1   ;   n_dynadv = np_FLX_ubs   ;   ENDIF
-
-      IF( ioptio /= 1 )   CALL ctl_stop( 'choose ONE and only ONE advection scheme' )
-!!an45
-      IF( nn_dynkeg /= nkeg_C2 .AND. nn_dynkeg /= nkeg_C2_wpo .AND. nn_dynkeg /= nkeg_HW )   & 
-         &   CALL ctl_stop( 'KEG scheme wrong value of nn_dynkeg' )
-!!an45
-
-      IF(lwp) THEN                    ! Print the choice
-         WRITE(numout,*)
-         SELECT CASE( n_dynadv )
-         CASE( np_LIN_dyn )   ;   WRITE(numout,*) '   ==>>>   linear dynamics : no momentum advection used'
-         CASE( np_VEC_c2  )   ;   WRITE(numout,*) '   ==>>>   vector form : keg + zad + vor is used' 
-            IF( nn_dynkeg == nkeg_C2     )   WRITE(numout,*) '              with Centered standard keg scheme'
-!!an45
-            IF( nn_dynkeg == nkeg_C2_wpo )   WRITE(numout,*) '              with Centered standard keg scheme (wet point only)'
-!!an45
-            IF( nn_dynkeg == nkeg_HW     )   WRITE(numout,*) '              with Hollingsworth keg scheme'
-         CASE( np_FLX_c2  )   ;   WRITE(numout,*) '   ==>>>   flux form   : 2nd order scheme is used'
-         CASE( np_FLX_ubs )   ;   WRITE(numout,*) '   ==>>>   flux form   : UBS       scheme is used'
-         END SELECT
-      ENDIF
-      !
-   END SUBROUTINE dyn_adv_init
-
-  !!======================================================================
-END MODULE dynadv
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynatf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynatf.F90	(revision 14059)
+++ 	(revision )
@@ -1,334 +1,0 @@
-MODULE dynatf
-   !!=========================================================================
-   !!                       ***  MODULE  dynatf  ***
-   !! Ocean dynamics: time filtering
-   !!=========================================================================
-   !! History :  OPA  !  1987-02  (P. Andrich, D. L Hostis)  Original code
-   !!                 !  1990-10  (C. Levy, G. Madec)
-   !!            7.0  !  1993-03  (M. Guyon)  symetrical conditions
-   !!            8.0  !  1997-02  (G. Madec & M. Imbard)  opa, release 8.0
-   !!            8.2  !  1997-04  (A. Weaver)  Euler forward step
-   !!             -   !  1997-06  (G. Madec)  lateral boudary cond., lbc routine
-   !!    NEMO    1.0  !  2002-08  (G. Madec)  F90: Free form and module
-   !!             -   !  2002-10  (C. Talandier, A-M. Treguier) Open boundary cond.
-   !!            2.0  !  2005-11  (V. Garnier) Surface pressure gradient organization
-   !!            2.3  !  2007-07  (D. Storkey) Calls to BDY routines. 
-   !!            3.2  !  2009-06  (G. Madec, R.Benshila)  re-introduce the vvl option
-   !!            3.3  !  2010-09  (D. Storkey, E.O'Dea) Bug fix for BDY module
-   !!            3.3  !  2011-03  (P. Oddo) Bug fix for time-splitting+(BDY-OBC) and not VVL
-   !!            3.5  !  2013-07  (J. Chanut) Compliant with time splitting changes
-   !!            3.6  !  2014-04  (G. Madec) add the diagnostic of the time filter trends
-   !!            3.7  !  2015-11  (J. Chanut) Free surface simplification
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) Rename dynnxt.F90 -> dynatf.F90. Now just does time filtering.
-   !!-------------------------------------------------------------------------
-  
-   !!----------------------------------------------------------------------------------------------
-   !!   dyn_atf       : apply Asselin time filtering to "now" velocities and vertical scale factors
-   !!----------------------------------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE sbc_oce        ! Surface boundary condition: ocean fields
-   USE sbcrnf         ! river runoffs
-   USE phycst         ! physical constants
-   USE dynadv         ! dynamics: vector invariant versus flux form
-   USE dynspg_ts      ! surface pressure gradient: split-explicit scheme
-   USE domvvl         ! variable volume
-   USE bdy_oce   , ONLY: ln_bdy
-   USE bdydta         ! ocean open boundary conditions
-   USE bdydyn         ! ocean open boundary conditions
-   USE bdyvol         ! ocean open boundary condition (bdy_vol routines)
-   USE trd_oce        ! trends: ocean variables
-   USE trddyn         ! trend manager: dynamics
-   USE trdken         ! trend manager: kinetic energy
-   USE isf_oce   , ONLY: ln_isf     ! ice shelf
-   USE isfdynatf , ONLY: isf_dynatf ! ice shelf volume filter correction subroutine 
-   !
-   USE in_out_manager ! I/O manager
-   USE iom            ! I/O manager library
-   USE lbclnk         ! lateral boundary condition (or mpp link)
-   USE lib_mpp        ! MPP library
-   USE prtctl         ! Print control
-   USE timing         ! Timing
-#if defined key_agrif
-   USE agrif_oce_interp
-#endif
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC    dyn_atf   ! routine called by step.F90
-!!st22
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY ROUTINE     Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_atf ( kt, Kbb, Kmm, Kaa, puu, pvv, pe3t, pe3u, pe3v )
-      INTEGER                             , INTENT(in   ) :: kt               ! ocean time-step index
-      INTEGER                             , INTENT(in   ) :: Kbb, Kmm, Kaa    ! before and after time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: puu, pvv         ! velocities to be time filtered
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: pe3t, pe3u, pe3v ! scale factors to be time filtered
-
-      WRITE(*,*) 'dyn_atf: You should not have seen this print! error?', kt
-   END SUBROUTINE dyn_atf
-
-#else
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynatf.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_atf ( kt, Kbb, Kmm, Kaa, puu, pvv, pe3t, pe3u, pe3v )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_atf  ***
-      !!                   
-      !! ** Purpose :   Finalize after horizontal velocity. Apply the boundary 
-      !!             condition on the after velocity and apply the Asselin time
-      !!             filter to the now fields.
-      !!
-      !! ** Method  : * Ensure after velocities transport matches time splitting
-      !!             estimate (ln_dynspg_ts=T)
-      !!
-      !!              * Apply lateral boundary conditions on after velocity 
-      !!             at the local domain boundaries through lbc_lnk call,
-      !!             at the one-way open boundaries (ln_bdy=T),
-      !!             at the AGRIF zoom   boundaries (lk_agrif=T)
-      !!
-      !!              * Apply the Asselin time filter to the now fields
-      !!             arrays to start the next time step:
-      !!                (puu(Kmm),pvv(Kmm)) = (puu(Kmm),pvv(Kmm)) 
-      !!                                    + rn_atfp [ (puu(Kbb),pvv(Kbb)) + (puu(Kaa),pvv(Kaa)) - 2 (puu(Kmm),pvv(Kmm)) ]
-      !!             Note that with flux form advection and non linear free surface,
-      !!             the time filter is applied on thickness weighted velocity.
-      !!             As a result, dyn_atf MUST be called after tra_atf.
-      !!
-      !! ** Action :   puu(Kmm),pvv(Kmm)   filtered now horizontal velocity 
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT(in   ) :: kt               ! ocean time-step index
-      INTEGER                             , INTENT(in   ) :: Kbb, Kmm, Kaa    ! before and after time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: puu, pvv         ! velocities to be time filtered
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) :: pe3t, pe3u, pe3v ! scale factors to be time filtered
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zue3a, zue3n, zue3b, zcoef    ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b, z1_2dt   !   -      -
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:)   ::   zue, zve, zwfld
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ze3t_f, ze3u_f, ze3v_f, zua, zva 
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing    )   CALL timing_start('dyn_atf')
-      IF( ln_dynspg_ts )   ALLOCATE( zue(jpi,jpj)     , zve(jpi,jpj)     )
-      IF( l_trddyn     )   ALLOCATE( zua(jpi,jpj,jpk) , zva(jpi,jpj,jpk) )
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn_atf : Asselin time filtering'
-         IF(lwp) WRITE(numout,*) '~~~~~~~'
-      ENDIF
-
-      IF ( ln_dynspg_ts ) THEN
-         ! Ensure below that barotropic velocities match time splitting estimate
-         ! Compute actual transport and replace it with ts estimate at "after" time step
-         zue(:,:) = pe3u(:,:,1,Kaa) * puu(:,:,1,Kaa) * umask(:,:,1)
-         zve(:,:) = pe3v(:,:,1,Kaa) * pvv(:,:,1,Kaa) * vmask(:,:,1)
-         DO jk = 2, jpkm1
-            zue(:,:) = zue(:,:) + pe3u(:,:,jk,Kaa) * puu(:,:,jk,Kaa) * umask(:,:,jk)
-            zve(:,:) = zve(:,:) + pe3v(:,:,jk,Kaa) * pvv(:,:,jk,Kaa) * vmask(:,:,jk)
-         END DO
-         DO jk = 1, jpkm1
-            puu(:,:,jk,Kaa) = ( puu(:,:,jk,Kaa) - zue(:,:) * r1_hu(:,:,Kaa) + uu_b(:,:,Kaa) ) * umask(:,:,jk)
-            pvv(:,:,jk,Kaa) = ( pvv(:,:,jk,Kaa) - zve(:,:) * r1_hv(:,:,Kaa) + vv_b(:,:,Kaa) ) * vmask(:,:,jk)
-         END DO
-         !
-         IF( .NOT.ln_bt_fw ) THEN
-            ! Remove advective velocity from "now velocities" 
-            ! prior to asselin filtering     
-            ! In the forward case, this is done below after asselin filtering   
-            ! so that asselin contribution is removed at the same time 
-            DO jk = 1, jpkm1
-               puu(:,:,jk,Kmm) = ( puu(:,:,jk,Kmm) - un_adv(:,:)*r1_hu(:,:,Kmm) + uu_b(:,:,Kmm) )*umask(:,:,jk)
-               pvv(:,:,jk,Kmm) = ( pvv(:,:,jk,Kmm) - vn_adv(:,:)*r1_hv(:,:,Kmm) + vv_b(:,:,Kmm) )*vmask(:,:,jk)
-            END DO  
-         ENDIF
-      ENDIF
-
-      ! Update after velocity on domain lateral boundaries
-      ! --------------------------------------------------      
-# if defined key_agrif
-      CALL Agrif_dyn( kt )             !* AGRIF zoom boundaries
-# endif
-      !
-      CALL lbc_lnk_multi( 'dynatf', puu(:,:,:,Kaa), 'U', -1., pvv(:,:,:,Kaa), 'V', -1. )     !* local domain boundaries
-      !
-      !                                !* BDY open boundaries
-      IF( ln_bdy .AND. ln_dynspg_exp )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa )
-      IF( ln_bdy .AND. ln_dynspg_ts  )   CALL bdy_dyn( kt, Kbb, puu, pvv, Kaa, dyn3d_only=.true. )
-
-!!$   Do we need a call to bdy_vol here??
-      !
-      IF( l_trddyn ) THEN             ! prepare the atf trend computation + some diagnostics
-         !
-         !                                  ! Kinetic energy and Conversion
-         IF( ln_KE_trd  )   CALL trd_dyn( puu(:,:,:,Kaa), pvv(:,:,:,Kaa), jpdyn_ken, kt, Kmm )
-         !
-         IF( ln_dyn_trd ) THEN              ! 3D output: total momentum trends
-            zua(:,:,:) = ( puu(:,:,:,Kaa) - puu(:,:,:,Kbb) ) * r1_Dt
-            zva(:,:,:) = ( pvv(:,:,:,Kaa) - pvv(:,:,:,Kbb) ) * r1_Dt
-            CALL iom_put( "utrd_tot", zua )        ! total momentum trends, except the asselin time filter
-            CALL iom_put( "vtrd_tot", zva )
-         ENDIF
-         !
-         zua(:,:,:) = puu(:,:,:,Kmm)             ! save the now velocity before the asselin filter
-         zva(:,:,:) = pvv(:,:,:,Kmm)             ! (caution: there will be a shift by 1 timestep in the
-         !                                  !  computation of the asselin filter trends)
-      ENDIF
-
-      ! Time filter and swap of dynamics arrays
-      ! ------------------------------------------
-         
-      IF( .NOT. l_1st_euler ) THEN    !* Leap-Frog : Asselin time filter 
-         !                                ! =============!
-         IF( ln_linssh ) THEN             ! Fixed volume !
-            !                             ! =============!
-            DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-               puu(ji,jj,jk,Kmm) = puu(ji,jj,jk,Kmm) + rn_atfp * ( puu(ji,jj,jk,Kbb) - 2._wp * puu(ji,jj,jk,Kmm) + puu(ji,jj,jk,Kaa) )
-               pvv(ji,jj,jk,Kmm) = pvv(ji,jj,jk,Kmm) + rn_atfp * ( pvv(ji,jj,jk,Kbb) - 2._wp * pvv(ji,jj,jk,Kmm) + pvv(ji,jj,jk,Kaa) )
-            END_3D
-            !                             ! ================!
-         ELSE                             ! Variable volume !
-            !                             ! ================!
-            ! Time-filtered scale factor at t-points
-            ! ----------------------------------------------------
-            ALLOCATE( ze3t_f(jpi,jpj,jpk), zwfld(jpi,jpj) )
-            DO jk = 1, jpkm1
-               ze3t_f(:,:,jk) = pe3t(:,:,jk,Kmm) + rn_atfp * ( pe3t(:,:,jk,Kbb) - 2._wp * pe3t(:,:,jk,Kmm) + pe3t(:,:,jk,Kaa) )
-            END DO
-            ! Add volume filter correction: compatibility with tracer advection scheme
-            ! => time filter + conservation correction
-            zcoef = rn_atfp * rn_Dt * r1_rho0
-            zwfld(:,:) = emp_b(:,:) - emp(:,:)
-            IF ( ln_rnf ) zwfld(:,:) =  zwfld(:,:) - ( rnf_b(:,:) - rnf(:,:) )
-            DO jk = 1, jpkm1
-               ze3t_f(:,:,jk) = ze3t_f(:,:,jk) - zcoef * zwfld(:,:) * tmask(:,:,jk) &
-                              &                        * pe3t(:,:,jk,Kmm) / ( ht(:,:) + 1._wp - ssmask(:,:) ) 
-            END DO
-            !
-            ! ice shelf melting (deal separately as it can be in depth)
-            ! PM: we could probably define a generic subroutine to do the in depth correction
-            !     to manage rnf, isf and possibly in the futur icb, tide water glacier (...)
-            !     ...(kt, coef, ktop, kbot, hz, fwf_b, fwf)
-            IF ( ln_isf ) CALL isf_dynatf( kt, Kmm, ze3t_f, rn_atfp * rn_Dt )
-            !
-            pe3t(:,:,1:jpkm1,Kmm) = ze3t_f(:,:,1:jpkm1)        ! filtered scale factor at T-points
-            !
-            IF( ln_dynadv_vec ) THEN      ! Asselin filter applied on velocity
-               ! Before filtered scale factor at (u/v)-points
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), pe3u(:,:,:,Kmm), 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), pe3v(:,:,:,Kmm), 'V' )
-               DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-                  puu(ji,jj,jk,Kmm) = puu(ji,jj,jk,Kmm) + rn_atfp * ( puu(ji,jj,jk,Kbb) - 2._wp * puu(ji,jj,jk,Kmm) + puu(ji,jj,jk,Kaa) )
-                  pvv(ji,jj,jk,Kmm) = pvv(ji,jj,jk,Kmm) + rn_atfp * ( pvv(ji,jj,jk,Kbb) - 2._wp * pvv(ji,jj,jk,Kmm) + pvv(ji,jj,jk,Kaa) )
-               END_3D
-               !
-            ELSE                          ! Asselin filter applied on thickness weighted velocity
-               !
-               ALLOCATE( ze3u_f(jpi,jpj,jpk) , ze3v_f(jpi,jpj,jpk) )
-               ! Now filtered scale factor at (u/v)-points stored in ze3u_f, ze3v_f
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), ze3u_f, 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), ze3v_f, 'V' )
-               DO_3D( 1, 1, 1, 1, 1, jpkm1 )
-                  zue3a = pe3u(ji,jj,jk,Kaa) * puu(ji,jj,jk,Kaa)
-                  zve3a = pe3v(ji,jj,jk,Kaa) * pvv(ji,jj,jk,Kaa)
-                  zue3n = pe3u(ji,jj,jk,Kmm) * puu(ji,jj,jk,Kmm)
-                  zve3n = pe3v(ji,jj,jk,Kmm) * pvv(ji,jj,jk,Kmm)
-                  zue3b = pe3u(ji,jj,jk,Kbb) * puu(ji,jj,jk,Kbb)
-                  zve3b = pe3v(ji,jj,jk,Kbb) * pvv(ji,jj,jk,Kbb)
-                  !
-                  puu(ji,jj,jk,Kmm) = ( zue3n + rn_atfp * ( zue3b - 2._wp * zue3n  + zue3a ) ) / ze3u_f(ji,jj,jk)
-                  pvv(ji,jj,jk,Kmm) = ( zve3n + rn_atfp * ( zve3b - 2._wp * zve3n  + zve3a ) ) / ze3v_f(ji,jj,jk)
-               END_3D
-               pe3u(:,:,1:jpkm1,Kmm) = ze3u_f(:,:,1:jpkm1)  
-               pe3v(:,:,1:jpkm1,Kmm) = ze3v_f(:,:,1:jpkm1)
-               !
-               DEALLOCATE( ze3u_f , ze3v_f )
-            ENDIF
-            !
-            DEALLOCATE( ze3t_f, zwfld )
-         ENDIF
-         !
-         IF( ln_dynspg_ts .AND. ln_bt_fw ) THEN
-            ! Revert filtered "now" velocities to time split estimate
-            ! Doing it here also means that asselin filter contribution is removed  
-            zue(:,:) = pe3u(:,:,1,Kmm) * puu(:,:,1,Kmm) * umask(:,:,1)
-            zve(:,:) = pe3v(:,:,1,Kmm) * pvv(:,:,1,Kmm) * vmask(:,:,1)    
-            DO jk = 2, jpkm1
-               zue(:,:) = zue(:,:) + pe3u(:,:,jk,Kmm) * puu(:,:,jk,Kmm) * umask(:,:,jk)
-               zve(:,:) = zve(:,:) + pe3v(:,:,jk,Kmm) * pvv(:,:,jk,Kmm) * vmask(:,:,jk)    
-            END DO
-            DO jk = 1, jpkm1
-               puu(:,:,jk,Kmm) = puu(:,:,jk,Kmm) - (zue(:,:) * r1_hu(:,:,Kmm) - uu_b(:,:,Kmm)) * umask(:,:,jk)
-               pvv(:,:,jk,Kmm) = pvv(:,:,jk,Kmm) - (zve(:,:) * r1_hv(:,:,Kmm) - vv_b(:,:,Kmm)) * vmask(:,:,jk)
-            END DO
-         ENDIF
-         !
-      ENDIF ! .NOT. l_1st_euler
-      !
-      ! Set "now" and "before" barotropic velocities for next time step:
-      ! JC: Would be more clever to swap variables than to make a full vertical
-      ! integration
-      !
-      IF(.NOT.ln_linssh ) THEN
-         hu(:,:,Kmm) = pe3u(:,:,1,Kmm ) * umask(:,:,1)
-         hv(:,:,Kmm) = pe3v(:,:,1,Kmm ) * vmask(:,:,1)
-         DO jk = 2, jpkm1
-            hu(:,:,Kmm) = hu(:,:,Kmm) + pe3u(:,:,jk,Kmm ) * umask(:,:,jk)
-            hv(:,:,Kmm) = hv(:,:,Kmm) + pe3v(:,:,jk,Kmm ) * vmask(:,:,jk)
-         END DO
-         r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-         r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) )
-      ENDIF
-      !
-      uu_b(:,:,Kaa) = pe3u(:,:,1,Kaa) * puu(:,:,1,Kaa) * umask(:,:,1)
-      uu_b(:,:,Kmm) = pe3u(:,:,1,Kmm) * puu(:,:,1,Kmm) * umask(:,:,1)
-      vv_b(:,:,Kaa) = pe3v(:,:,1,Kaa) * pvv(:,:,1,Kaa) * vmask(:,:,1)
-      vv_b(:,:,Kmm) = pe3v(:,:,1,Kmm) * pvv(:,:,1,Kmm) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         uu_b(:,:,Kaa) = uu_b(:,:,Kaa) + pe3u(:,:,jk,Kaa) * puu(:,:,jk,Kaa) * umask(:,:,jk)
-         uu_b(:,:,Kmm) = uu_b(:,:,Kmm) + pe3u(:,:,jk,Kmm) * puu(:,:,jk,Kmm) * umask(:,:,jk)
-         vv_b(:,:,Kaa) = vv_b(:,:,Kaa) + pe3v(:,:,jk,Kaa) * pvv(:,:,jk,Kaa) * vmask(:,:,jk)
-         vv_b(:,:,Kmm) = vv_b(:,:,Kmm) + pe3v(:,:,jk,Kmm) * pvv(:,:,jk,Kmm) * vmask(:,:,jk)
-      END DO
-      uu_b(:,:,Kaa) = uu_b(:,:,Kaa) * r1_hu(:,:,Kaa)
-      vv_b(:,:,Kaa) = vv_b(:,:,Kaa) * r1_hv(:,:,Kaa)
-      uu_b(:,:,Kmm) = uu_b(:,:,Kmm) * r1_hu(:,:,Kmm)
-      vv_b(:,:,Kmm) = vv_b(:,:,Kmm) * r1_hv(:,:,Kmm)
-      !
-      IF( .NOT.ln_dynspg_ts ) THEN        ! output the barotropic currents
-         CALL iom_put(  "ubar", uu_b(:,:,Kmm) )
-         CALL iom_put(  "vbar", vv_b(:,:,Kmm) )
-      ENDIF
-      IF( l_trddyn ) THEN                ! 3D output: asselin filter trends on momentum
-         zua(:,:,:) = ( puu(:,:,:,Kmm) - zua(:,:,:) ) * z1_2dt
-         zva(:,:,:) = ( pvv(:,:,:,Kmm) - zva(:,:,:) ) * z1_2dt
-         CALL trd_dyn( zua, zva, jpdyn_atf, kt, Kmm )
-      ENDIF
-      !
-      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab3d_1=puu(:,:,:,Kaa), clinfo1=' nxt  - puu(:,:,:,Kaa): ', mask1=umask,   &
-         &                                  tab3d_2=pvv(:,:,:,Kaa), clinfo2=' pvv(:,:,:,Kaa): '       , mask2=vmask )
-      ! 
-      IF( ln_dynspg_ts )   DEALLOCATE( zue, zve )
-      IF( l_trddyn     )   DEALLOCATE( zua, zva )
-      IF( ln_timing    )   CALL timing_stop('dyn_atf')
-      !
-   END SUBROUTINE dyn_atf
-
-#endif
-!!st22
-   !!=========================================================================
-END MODULE dynatf
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynkeg.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynkeg.F90	(revision 14059)
+++ 	(revision )
@@ -1,159 +1,0 @@
-MODULE dynkeg
-   !!======================================================================
-   !!                       ***  MODULE  dynkeg  ***
-   !! Ocean dynamics:  kinetic energy gradient trend
-   !!======================================================================
-   !! History :  1.0  !  1987-09  (P. Andrich, M.-A. Foujols)  Original code
-   !!            7.0  !  1997-05  (G. Madec)  Split dynber into dynkeg and dynhpg
-   !!  NEMO      1.0  !  2002-07  (G. Madec)  F90: Free form and module
-   !!            3.6  !  2015-05  (N. Ducousso, G. Madec)  add Hollingsworth scheme as an option 
-   !!----------------------------------------------------------------------
-   
-   !!----------------------------------------------------------------------
-   !!   dyn_keg      : update the momentum trend with the horizontal tke
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE trd_oce         ! trends: ocean variables
-   USE trddyn          ! trend manager: dynamics
-   !
-   USE in_out_manager  ! I/O manager
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE lib_mpp         ! MPP library
-   USE prtctl          ! Print control
-   USE timing          ! Timing
-   USE bdy_oce         ! ocean open boundary conditions
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dyn_keg    ! routine called by step module
-   
-   INTEGER, PARAMETER, PUBLIC  ::   nkeg_C2     = 0   !: 2nd order centered scheme (standard scheme)
-!!an45
-   INTEGER, PARAMETER, PUBLIC  ::   nkeg_C2_wpo = 2   !: 2nd order centered scheme (wet point only : coastline at 45 degrees)
-   INTEGER, PARAMETER, PUBLIC  ::   nkeg_HW     = 1   !: Hollingsworth et al., QJRMS, 1983
-   !
-   REAL(wp) ::   r1_48 = 1._wp / 48._wp   !: =1/(4*2*6)
-   
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynkeg.F90 12377 2020-02-12 14:39:06Z acc $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_keg( kt, kscheme, Kmm, puu, pvv, Krhs )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_keg  ***
-      !!
-      !! ** Purpose :   Compute the now momentum trend due to the horizontal
-      !!      gradient of the horizontal kinetic energy and add it to the 
-      !!      general momentum trend.
-      !!
-      !! ** Method  : * kscheme = nkeg_C2 : 2nd order centered scheme that 
-      !!      conserve kinetic energy. Compute the now horizontal kinetic energy 
-      !!         zhke = 1/2 [ mi-1( un^2 ) + mj-1( vn^2 ) ]
-      !!              * kscheme = nkeg_HW : Hollingsworth correction following
-      !!      Arakawa (2001). The now horizontal kinetic energy is given by:
-      !!         zhke = 1/6 [ mi-1(  2 * un^2 + ((u(j+1)+u(j-1))/2)^2  )
-      !!                    + mj-1(  2 * vn^2 + ((v(i+1)+v(i-1))/2)^2  ) ]
-      !!      
-      !!      Take its horizontal gradient and add it to the general momentum
-      !!      trend.
-      !!         u(rhs) = u(rhs) - 1/e1u di[ zhke ]
-      !!         v(rhs) = v(rhs) - 1/e2v dj[ zhke ]
-      !!
-      !! ** Action : - Update the (puu(:,:,:,Krhs), pvv(:,:,:,Krhs)) with the hor. ke gradient trend
-      !!             - send this trends to trd_dyn (l_trddyn=T) for post-processing
-      !!
-      !! ** References : Arakawa, A., International Geophysics 2001.
-      !!                 Hollingsworth et al., Quart. J. Roy. Meteor. Soc., 1983.
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT( in )  ::  kt               ! ocean time-step index
-      INTEGER                             , INTENT( in )  ::  kscheme          ! =0/1/2   type of KEG scheme 
-      INTEGER                             , INTENT( in )  ::  Kmm, Krhs        ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::  puu, pvv         ! ocean velocities and RHS of momentum equation
-      !
-      INTEGER  ::   ji, jj, jk             ! dummy loop indices
-      REAL(wp) ::   zu, zv                   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj,jpk)        ::   zhke
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv 
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('dyn_keg')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn_keg : kinetic energy gradient trend, scheme number=', kscheme
-         IF(lwp) WRITE(numout,*) '~~~~~~~'
-      ENDIF
-
-      IF( l_trddyn ) THEN           ! Save the input trends
-         ALLOCATE( ztrdu(jpi,jpj,jpk) , ztrdv(jpi,jpj,jpk) )
-         ztrdu(:,:,:) = puu(:,:,:,Krhs) 
-         ztrdv(:,:,:) = pvv(:,:,:,Krhs) 
-      ENDIF
-      
-      zhke(:,:,jpk) = 0._wp
-
-      SELECT CASE ( kscheme )             !== Horizontal kinetic energy at T-point  ==!
-!!an45 to be ADDED : que cas C2 - "wet points only" il suffit de x2 le terme quadratic a la coast (nn_dynkeg_adv = 2)
-      CASE ( nkeg_C2_wpo )                          !--  Standard scheme  --!
-         DO_3D( 0, 1, 0, 1, 1, jpkm1 )
-            zu =  (   puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)   &
-               &    + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm)   ) * ( 2._wp - umask(ji-1,jj,jk) * umask(ji,jj,jk) )
-            zv =  (   pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)   &
-               &    + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm)   ) * ( 2._wp - vmask(ji,jj-1,jk) * vmask(ji,jj,jk) )
-            zhke(ji,jj,jk) = 0.25_wp * ( zv + zu )
-         END_3D
-!!an45         
-      !
-      CASE ( nkeg_C2 )                          !--  Standard scheme  --!
-         DO_3D( 0, 1, 0, 1, 1, jpkm1 )
-            zu =    puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)   &
-               &  + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm)
-            zv =    pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)   &
-               &  + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm)
-            zhke(ji,jj,jk) = 0.25_wp * ( zv + zu )
-         END_3D
-      CASE ( nkeg_HW )                          !--  Hollingsworth scheme  --!
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            zu = 8._wp * ( puu(ji-1,jj  ,jk,Kmm) * puu(ji-1,jj  ,jk,Kmm)    &
-               &         + puu(ji  ,jj  ,jk,Kmm) * puu(ji  ,jj  ,jk,Kmm) )  &
-               &   +     ( puu(ji-1,jj-1,jk,Kmm) + puu(ji-1,jj+1,jk,Kmm) ) * ( puu(ji-1,jj-1,jk,Kmm) + puu(ji-1,jj+1,jk,Kmm) )   &
-               &   +     ( puu(ji  ,jj-1,jk,Kmm) + puu(ji  ,jj+1,jk,Kmm) ) * ( puu(ji  ,jj-1,jk,Kmm) + puu(ji  ,jj+1,jk,Kmm) )
-               !
-            zv = 8._wp * ( pvv(ji  ,jj-1,jk,Kmm) * pvv(ji  ,jj-1,jk,Kmm)    &
-               &         + pvv(ji  ,jj  ,jk,Kmm) * pvv(ji  ,jj  ,jk,Kmm) )  &
-               &  +      ( pvv(ji-1,jj-1,jk,Kmm) + pvv(ji+1,jj-1,jk,Kmm) ) * ( pvv(ji-1,jj-1,jk,Kmm) + pvv(ji+1,jj-1,jk,Kmm) )   &
-               &  +      ( pvv(ji-1,jj  ,jk,Kmm) + pvv(ji+1,jj  ,jk,Kmm) ) * ( pvv(ji-1,jj  ,jk,Kmm) + pvv(ji+1,jj  ,jk,Kmm) )
-            zhke(ji,jj,jk) = r1_48 * ( zv + zu )
-         END_3D
-         CALL lbc_lnk( 'dynkeg', zhke, 'T', 1. )
-         !
-      END SELECT 
-      !
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         puu(ji,jj,jk,Krhs) = puu(ji,jj,jk,Krhs) - ( zhke(ji+1,jj  ,jk) - zhke(ji,jj,jk) ) / e1u(ji,jj)
-         pvv(ji,jj,jk,Krhs) = pvv(ji,jj,jk,Krhs) - ( zhke(ji  ,jj+1,jk) - zhke(ji,jj,jk) ) / e2v(ji,jj)
-      END_3D
-      !
-      IF( l_trddyn ) THEN                 ! save the Kinetic Energy trends for diagnostic
-         ztrdu(:,:,:) = puu(:,:,:,Krhs) - ztrdu(:,:,:)
-         ztrdv(:,:,:) = pvv(:,:,:,Krhs) - ztrdv(:,:,:)
-         CALL trd_dyn( ztrdu, ztrdv, jpdyn_keg, kt, Kmm )
-         DEALLOCATE( ztrdu , ztrdv )
-      ENDIF
-      !
-      IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab3d_1=puu(:,:,:,Krhs), clinfo1=' keg  - Ua: ', mask1=umask,   &
-         &                                  tab3d_2=pvv(:,:,:,Krhs), clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-      !
-      IF( ln_timing )   CALL timing_stop('dyn_keg')
-      !
-   END SUBROUTINE dyn_keg
-
-   !!======================================================================
-END MODULE dynkeg
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynldf_lap_blp.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynldf_lap_blp.F90	(revision 14059)
+++ 	(revision )
@@ -1,241 +1,0 @@
-MODULE dynldf_lap_blp
-   !!======================================================================
-   !!                   ***  MODULE  dynldf_lap_blp  ***
-   !! Ocean dynamics:  lateral viscosity trend (laplacian and bilaplacian)
-   !!======================================================================
-   !! History : 3.7  ! 2014-01  (G. Madec, S. Masson)  Original code, re-entrant laplacian
-   !!           4.0  ! 2020-04  (A. Nasser, G. Madec)  Add symmetric mixing tensor 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_ldf_lap   : update the momentum trend with the lateral viscosity using an iso-level   laplacian operator
-   !!   dyn_ldf_blp   : update the momentum trend with the lateral viscosity using an iso-level bilaplacian operator
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE ldfdyn         ! lateral diffusion: eddy viscosity coef.
-   USE ldfslp         ! iso-neutral slopes 
-   USE zdf_oce        ! ocean vertical physics
-   !
-   USE in_out_manager ! I/O manager
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC dyn_ldf_lap  ! called by dynldf.F90
-   PUBLIC dyn_ldf_blp  ! called by dynldf.F90
-!!anSYM  
-   INTEGER, PUBLIC, PARAMETER ::   np_dynldf_lap_rot  = 1         ! div-rot   laplacian 
-   INTEGER, PUBLIC, PARAMETER ::   np_dynldf_lap_sym  = 2         ! symmetric laplacian (Griffies&Hallberg 2000)
-   INTEGER, PUBLIC, PARAMETER ::   np_dynldf_lap_symN = 3         ! symmetric laplacian (cartesian)
-   
-   INTEGER, PUBLIC, PARAMETER ::   ln_dynldf_lap_typ = 1         ! choose type of laplacian (ideally from namelist)
-!!anSYM
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-!!st21
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynldf_lap_blp.F90 12822 2020-04-28 09:10:38Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_ldf_lap( kt, Kbb, Kmm, pu, pv, pu_rhs, pv_rhs, kpass )
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE dyn_ldf_lap  ***
-      !!                       
-      !! ** Purpose :   Compute the before horizontal momentum diffusive 
-      !!      trend and add it to the general trend of momentum equation.
-      !!
-      !! ** Method  :   The Laplacian operator apply on horizontal velocity is 
-      !!      writen as :   grad_h( ahmt div_h(U )) - curl_h( ahmf curl_z(U) ) 
-      !!      writen as :   grad_h( ahmt div_h(U )) - curl_h( ahmf curl_z(U) ) 
-      !!
-      !! ** Action : - pu_rhs, pv_rhs increased by the harmonic operator applied on pu, pv.
-      !!
-      !! Reference : S.Griffies, R.Hallberg 2000 Mon.Wea.Rev., DOI:/ 
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt         ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kbb, Kmm   ! ocean time level indices
-      INTEGER                         , INTENT(in   ) ::   kpass      ! =1/2 first or second passage
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pu, pv     ! before velocity  [m/s]
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs   ! velocity trend   [m/s2]
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zsign        ! local scalars
-      REAL(wp) ::   zua, zva     ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   zcur, zdiv
-      REAL(wp), DIMENSION(jpi,jpj) ::   zten, zshe   ! tension (diagonal) and shearing (anti-diagonal) terms
-      !!----------------------------------------------------------------------
-      !
-!!anSYM TO BE ADDED : reading of laplacian operator (ln_dynldf_lap_typ -> to be written nn_) shall be added in dyn_ldf_init 
-!!                 as the writing   
-!!                 and an integer as np_dynldf_lap for instance taken as argument by dyn_ldf_lap call in dyn_ldf
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dyn_ldf : iso-level harmonic (laplacian) operator, pass=', kpass
-         WRITE(numout,*) '~~~~~~~ '
-         WRITE(numout,*) '                  ln_dynldf_lap_typ = ', ln_dynldf_lap_typ
-         SELECT CASE( ln_dynldf_lap_typ )             ! print the choice of operator
-         CASE( np_dynldf_lap_rot )   ;   WRITE(numout,*) '   ==>>>   div-rot   laplacian'
-         CASE( np_dynldf_lap_sym )   ;   WRITE(numout,*) '   ==>>>   symmetric laplacian (covariant form)'
-         CASE( np_dynldf_lap_symN)   ;   WRITE(numout,*) '   ==>>>   symmetric laplacian (simple form)'
-         END SELECT
-      ENDIF
-      !
-      IF( kpass == 1 ) THEN   ;   zsign =  1._wp      ! bilaplacian operator require a minus sign
-      ELSE                    ;   zsign = -1._wp      !  (eddy viscosity coef. >0)
-      ENDIF
-      !
-      SELECT CASE( ln_dynldf_lap_typ )  
-         !              
-         CASE ( np_dynldf_lap_rot )       !==  Vorticity-Divergence form  ==!
-            !   
-            DO jk = 1, jpkm1                                 ! Horizontal slab
-               !                                             
-               DO_2D( 0, 1, 0, 1 )
-               !                                      ! ahm * e3 * curl  (computed from 1 to jpim1/jpjm1)
-!!gm open question here : e3f  at before or now ?    probably now... 
-!!gm note that ahmf has already been multiplied by fmask
-            zcur(ji-1,jj-1) =  &
-               &      ahmf(ji-1,jj-1,jk) * e3f(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)      &
-               &  * (  e2v(ji  ,jj-1) * pv(ji  ,jj-1,jk) - e2v(ji-1,jj-1) * pv(ji-1,jj-1,jk)  &
-               &     - e1u(ji-1,jj  ) * pu(ji-1,jj  ,jk) + e1u(ji-1,jj-1) * pu(ji-1,jj-1,jk)  )
-            !                                      ! ahm * div        (computed from 2 to jpi/jpj)
-!!gm note that ahmt has already been multiplied by tmask
-                  zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / e3t(ji,jj,jk,Kbb)                                         &
-                     &     * (  e2u(ji,jj)*e3u(ji,jj,jk,Kbb) * pu(ji,jj,jk) - e2u(ji-1,jj)*e3u(ji-1,jj,jk,Kbb) * pu(ji-1,jj,jk)  &
-                     &        + e1v(ji,jj)*e3v(ji,jj,jk,Kbb) * pv(ji,jj,jk) - e1v(ji,jj-1)*e3v(ji,jj-1,jk,Kbb) * pv(ji,jj-1,jk)  )
-               END_2D
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * (                                             &
-                     &              - ( zcur(ji  ,jj) - zcur(ji,jj-1) ) * r1_e2u(ji,jj) / e3u(ji,jj,jk,Kmm)   &
-                     &              + ( zdiv(ji+1,jj) - zdiv(ji,jj  ) ) * r1_e1u(ji,jj)                       )
-                     !
-                  pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * (                                             &
-                     &                ( zcur(ji,jj  ) - zcur(ji-1,jj) ) * r1_e1v(ji,jj) / e3v(ji,jj,jk,Kmm)   &
-                     &              + ( zdiv(ji,jj+1) - zdiv(ji  ,jj) ) * r1_e2v(ji,jj)                       )
-               END_2D
-               !
-            END DO                                           !   End of slab
-            !
-         CASE ( np_dynldf_lap_sym )       !==  Symmetric form  ==!   (Griffies&Hallberg 2000)
-            !
-            DO jk = 1, jpkm1                                 ! Horizontal slab
-               !
-               DO_2D( 0, 1, 0, 1 )
-                  !                                      ! shearing stress component (F-point)   NB : ahmf has already been multiplied by fmask
-                  zshe(ji-1,jj-1) = ahmf(ji-1,jj-1,jk)                                                              &
-                     &     * (    e1f(ji-1,jj-1)    * r1_e2f(ji-1,jj-1)                                             &
-                     &         * ( pu(ji-1,jj  ,jk) * r1_e1u(ji-1,jj  )  - pu(ji-1,jj-1,jk) * r1_e1u(ji-1,jj-1) )   &
-                     &         +  e2f(ji-1,jj-1)    * r1_e1f(ji-1,jj-1)                                             &
-                     &         * ( pv(ji  ,jj-1,jk) * r1_e2v(ji  ,jj-1)  - pv(ji-1,jj-1,jk) * r1_e2v(ji-1,jj-1) )   ) 
-                  !                                      ! tension stress component (T-point)   NB : ahmt has already been multiplied by tmask
-                  zten(ji,jj)    = ahmt(ji,jj,jk)                                                       &
-                     &     * (    e2t(ji,jj)    * r1_e1t(ji,jj)                                         &
-                     &         * ( pu(ji,jj,jk) * r1_e2u(ji,jj)  - pu(ji-1,jj,jk) * r1_e2u(ji-1,jj) )   &
-                     &         -  e1t(ji,jj)    * r1_e2t(ji,jj)                                         &
-                     &         * ( pv(ji,jj,jk) * r1_e1v(ji,jj)  - pv(ji,jj-1,jk) * r1_e1v(ji,jj-1) )   )   
-               END_2D
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * r1_e1e2u(ji,jj) / e3u(ji,jj,jk,Kmm)                               &
-                     &    * (   (   zten(ji+1,jj  ) * e2t(ji+1,jj  )*e2t(ji+1,jj  ) * e3t(ji+1,jj  ,jk,Kmm)                       &
-                     &            - zten(ji  ,jj  ) * e2t(ji  ,jj  )*e2t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm) ) * r1_e2u(ji,jj)     &                                                    
-                     &        + (   zshe(ji  ,jj  ) * e1f(ji  ,jj  )*e1f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                           &
-                     &            - zshe(ji  ,jj-1) * e1f(ji  ,jj-1)*e1f(ji  ,jj-1) * e3f(ji  ,jj-1,jk)     ) * r1_e1u(ji,jj) )   
-                  !
-                  pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * r1_e1e2v(ji,jj) / e3v(ji,jj,jk,Kmm)                               &
-                     &    * (   (   zshe(ji  ,jj  ) * e2f(ji  ,jj  )*e2f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                           &
-                     &            - zshe(ji-1,jj  ) * e2f(ji-1,jj  )*e2f(ji-1,jj  ) * e3f(ji-1,jj  ,jk)     ) * r1_e2v(ji,jj)     &
-                     &        - (   zten(ji  ,jj+1) * e1t(ji  ,jj+1)*e1t(ji  ,jj+1) * e3t(ji  ,jj+1,jk,Kmm)                       &
-                     &            - zten(ji  ,jj  ) * e1t(ji  ,jj  )*e1t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm) ) * r1_e1v(ji,jj) )
-                   !
-               END_2D
-               !
-            END DO                                           !   End of slab
-            !
-         CASE ( np_dynldf_lap_symN )       !==  Symmetric form  ==!   (naive way)
-            !
-            DO jk = 1, jpkm1                                 ! Horizontal slab
-               !
-               DO_2D( 0, 1, 0, 1 )
-                  !                                      ! shearing stress component (F-point)   NB : ahmf has already been multiplied by fmask
-                  zshe(ji-1,jj-1) = ahmf(ji-1,jj-1,jk)                                           &
-                     &     * (   r1_e2f(ji-1,jj-1) * ( pu(ji-1,jj  ,jk) - pu(ji-1,jj-1,jk)  )   &
-                     &         + r1_e1f(ji-1,jj-1) * ( pv(ji  ,jj-1,jk) - pv(ji-1,jj-1,jk)  )   ) 
-                  !                                      ! tension stress component (T-point)   NB : ahmt has already been multiplied by tmask
-                  zten(ji,jj)    = ahmt(ji,jj,jk)                                       &
-                     &     * (   r1_e1t(ji,jj) * ( pu(ji,jj,jk) - pu(ji-1,jj  ,jk)  )   &
-                     &         - r1_e2t(ji,jj) * ( pv(ji,jj,jk) - pv(ji  ,jj-1,jk)  )   )   
-               END_2D
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zsign * r1_e1e2u(ji,jj) / e3u(ji,jj,jk,Kmm)   &
-                     &    * (   zten(ji+1,jj  ) * e2t(ji+1,jj  ) * e3t(ji+1,jj  ,jk,Kmm)              &
-                     &        - zten(ji  ,jj  ) * e2t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm)              &
-                     &        + zshe(ji  ,jj  ) * e1f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                  &
-                     &        - zshe(ji  ,jj-1) * e1f(ji  ,jj-1) * e3f(ji  ,jj-1,jk)                  )    
-                  !
-                  pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zsign * r1_e1e2v(ji,jj) / e3v(ji,jj,jk,Kmm)   &
-                     &    * (   zshe(ji  ,jj  ) * e2f(ji  ,jj  ) * e3f(ji  ,jj  ,jk)                  &
-                     &        - zshe(ji-1,jj  ) * e2f(ji-1,jj  ) * e3f(ji-1,jj  ,jk)                  &
-                     &        - zten(ji  ,jj+1) * e1t(ji  ,jj+1) * e3t(ji  ,jj+1,jk,Kmm)              &
-                     &        + zten(ji  ,jj  ) * e1t(ji  ,jj  ) * e3t(ji  ,jj  ,jk,Kmm)              )
-                   !
-               END_2D
-               !
-            END DO                                           !   End of slab
-            !  
-         CASE DEFAULT                                     ! error
-            CALL ctl_stop('STOP','dyn_ldf_lap: wrong value for ln_dynldf_lap_typ'  )
-         END SELECT
-         !
-      !
-   END SUBROUTINE dyn_ldf_lap
-
-
-   SUBROUTINE dyn_ldf_blp( kt, Kbb, Kmm, pu, pv, pu_rhs, pv_rhs )
-      !!----------------------------------------------------------------------
-      !!                 ***  ROUTINE dyn_ldf_blp  ***
-      !!                    
-      !! ** Purpose :   Compute the before lateral momentum viscous trend 
-      !!              and add it to the general trend of momentum equation.
-      !!
-      !! ** Method  :   The lateral viscous trends is provided by a bilaplacian
-      !!      operator applied to before field (forward in time).
-      !!      It is computed by two successive calls to dyn_ldf_lap routine
-      !!
-      !! ** Action :   pt(:,:,:,:,Krhs)   updated with the before rotated bilaplacian diffusion
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt         ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kbb, Kmm   ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pu, pv     ! before velocity fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs   ! momentum trend
-      !
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zulap, zvlap   ! laplacian at u- and v-point
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn_ldf_blp : bilaplacian operator momentum '
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      !
-      zulap(:,:,:) = 0._wp
-      zvlap(:,:,:) = 0._wp
-      !
-      CALL dyn_ldf_lap( kt, Kbb, Kmm, pu, pv, zulap, zvlap, 1 )   ! rotated laplacian applied to pt (output in zlap,Kbb)
-      !
-      CALL lbc_lnk_multi( 'dynldf_lap_blp', zulap, 'U', -1., zvlap, 'V', -1. )             ! Lateral boundary conditions
-      !
-      CALL dyn_ldf_lap( kt, Kbb, Kmm, zulap, zvlap, pu_rhs, pv_rhs, 2 )   ! rotated laplacian applied to zlap (output in pt(:,:,:,:,Krhs))
-      !
-   END SUBROUTINE dyn_ldf_blp
-
-   !!======================================================================
-END MODULE dynldf_lap_blp
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynvor.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/dynvor.F90	(revision 14059)
+++ 	(revision )
@@ -1,880 +1,0 @@
-MODULE dynvor
-   !!======================================================================
-   !!                       ***  MODULE  dynvor  ***
-   !! Ocean dynamics: Update the momentum trend with the relative and
-   !!                 planetary vorticity trends
-   !!======================================================================
-   !! History :  OPA  ! 1989-12  (P. Andrich)  vor_ens: Original code
-   !!            5.0  ! 1991-11  (G. Madec)  vor_ene, vor_mix: Original code
-   !!            6.0  ! 1996-01  (G. Madec)  s-coord, suppress work arrays
-   !!   NEMO     0.5  ! 2002-08  (G. Madec)  F90: Free form and module
-   !!            1.0  ! 2004-02  (G. Madec)  vor_een: Original code
-   !!             -   ! 2003-08  (G. Madec)  add vor_ctl
-   !!             -   ! 2005-11  (G. Madec)  add dyn_vor (new step architecture)
-   !!            2.0  ! 2006-11  (G. Madec)  flux form advection: add metric term
-   !!            3.2  ! 2009-04  (R. Benshila)  vvl: correction of een scheme
-   !!            3.3  ! 2010-10  (C. Ethe, G. Madec)  reorganisation of initialisation phase
-   !!            3.7  ! 2014-04  (G. Madec)  trend simplification: suppress jpdyn_trd_dat vorticity 
-   !!             -   ! 2014-06  (G. Madec)  suppression of velocity curl from in-core memory
-   !!             -   ! 2016-12  (G. Madec, E. Clementi) add Stokes-Coriolis trends (ln_stcor=T)
-   !!            4.0  ! 2017-07  (G. Madec)  linear dynamics + trends diag. with Stokes-Coriolis
-   !!             -   ! 2018-03  (G. Madec)  add two new schemes (ln_dynvor_enT and ln_dynvor_eet)
-   !!             -   ! 2018-04  (G. Madec)  add pre-computed gradient for metric term calculation
-   !!            4.x  ! 2020-03  (G. Madec, A. Nasser)  make ln_dynvor_msk truly efficient on relative vorticity
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dyn_vor       : Update the momentum trend with the vorticity trend
-   !!       vor_ens   : enstrophy conserving scheme       (ln_dynvor_ens=T)
-   !!       vor_ene   : energy conserving scheme          (ln_dynvor_ene=T)
-   !!       vor_een   : energy and enstrophy conserving   (ln_dynvor_een=T)
-   !!   dyn_vor_init  : set and control of the different vorticity option
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and tracers
-   USE dom_oce        ! ocean space and time domain
-   USE dommsk         ! ocean mask
-   USE dynadv         ! momentum advection
-   USE trd_oce        ! trends: ocean variables
-   USE trddyn         ! trend manager: dynamics
-   USE sbcwave        ! Surface Waves (add Stokes-Coriolis force)
-   USE sbc_oce , ONLY : ln_stcor    ! use Stoke-Coriolis force
-   !
-   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
-   USE prtctl         ! Print control
-   USE in_out_manager ! I/O manager
-   USE lib_mpp        ! MPP library
-   USE timing         ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dyn_vor        ! routine called by step.F90
-   PUBLIC   dyn_vor_init   ! routine called by nemogcm.F90
-
-   !                                   !!* Namelist namdyn_vor: vorticity term
-   LOGICAL, PUBLIC ::   ln_dynvor_ens   !: enstrophy conserving scheme          (ENS)
-   LOGICAL, PUBLIC ::   ln_dynvor_ene   !: f-point energy conserving scheme     (ENE)
-   LOGICAL, PUBLIC ::   ln_dynvor_enT   !: t-point energy conserving scheme     (ENT)
-   LOGICAL, PUBLIC ::   ln_dynvor_eeT   !: t-point energy conserving scheme     (EET)
-   LOGICAL, PUBLIC ::   ln_dynvor_een   !: energy & enstrophy conserving scheme (EEN)
-   INTEGER, PUBLIC ::      nn_een_e3f      !: e3f=masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
-   LOGICAL, PUBLIC ::   ln_dynvor_mix   !: mixed scheme                         (MIX)
-   LOGICAL, PUBLIC ::   ln_dynvor_msk   !: vorticity multiplied by fmask (=T) or not (=F) (all vorticity schemes)
-
-   INTEGER, PUBLIC ::   nvor_scheme     !: choice of the type of advection scheme
-   !                                       ! associated indices:
-   INTEGER, PUBLIC, PARAMETER ::   np_ENS = 0   ! ENS scheme
-   INTEGER, PUBLIC, PARAMETER ::   np_ENE = 1   ! ENE scheme
-   INTEGER, PUBLIC, PARAMETER ::   np_ENT = 2   ! ENT scheme (t-point vorticity)
-   INTEGER, PUBLIC, PARAMETER ::   np_EET = 3   ! EET scheme (EEN using e3t)
-   INTEGER, PUBLIC, PARAMETER ::   np_EEN = 4   ! EEN scheme
-   INTEGER, PUBLIC, PARAMETER ::   np_MIX = 5   ! MIX scheme
-
-   INTEGER ::   ncor, nrvm, ntot   ! choice of calculated vorticity 
-   !                               ! associated indices:
-   INTEGER, PUBLIC, PARAMETER ::   np_COR = 1         ! Coriolis (planetary)
-   INTEGER, PUBLIC, PARAMETER ::   np_RVO = 2         ! relative vorticity
-   INTEGER, PUBLIC, PARAMETER ::   np_MET = 3         ! metric term
-   INTEGER, PUBLIC, PARAMETER ::   np_CRV = 4         ! relative + planetary (total vorticity)
-   INTEGER, PUBLIC, PARAMETER ::   np_CME = 5         ! Coriolis + metric term
-
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   di_e2u_2        ! = di(e2u)/2          used in T-point metric term calculation
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   dj_e1v_2        ! = dj(e1v)/2           -        -      -       - 
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   di_e2v_2e1e2f   ! = di(e2u)/(2*e1e2f)  used in F-point metric term calculation
-   REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   dj_e1u_2e1e2f   ! = dj(e1v)/(2*e1e2f)   -        -      -       - 
-   
-   REAL(wp) ::   r1_4  = 0.250_wp         ! =1/4
-   REAL(wp) ::   r1_8  = 0.125_wp         ! =1/8
-   REAL(wp) ::   r1_12 = 1._wp / 12._wp   ! 1/12
-   
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-!!st23
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: dynvor.F90 12667 2020-04-03 14:22:29Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dyn_vor( kt, Kmm, puu, pvv, Krhs )
-      !!----------------------------------------------------------------------
-      !!
-      !! ** Purpose :   compute the lateral ocean tracer physics.
-      !!
-      !! ** Action : - Update (puu(:,:,:,Krhs),pvv(:,:,:,Krhs)) with the now vorticity term trend
-      !!             - save the trends in (ztrdu,ztrdv) in 2 parts (relative
-      !!               and planetary vorticity trends) and send them to trd_dyn 
-      !!               for futher diagnostics (l_trddyn=T)
-      !!----------------------------------------------------------------------
-      INTEGER                             , INTENT( in  ) ::   kt          ! ocean time-step index
-      INTEGER                             , INTENT( in  ) ::   Kmm, Krhs   ! ocean time level indices
-      REAL(wp), DIMENSION(jpi,jpj,jpk,jpt), INTENT(inout) ::   puu, pvv    ! ocean velocity field and RHS of momentum equation
-      !
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  ztrdu, ztrdv
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('dyn_vor')
-      !
-      IF( l_trddyn ) THEN     !==  trend diagnostics case : split the added trend in two parts  ==!
-         !
-         ALLOCATE( ztrdu(jpi,jpj,jpk), ztrdv(jpi,jpj,jpk) )
-         !
-         ztrdu(:,:,:) = puu(:,:,:,Krhs)            !* planetary vorticity trend (including Stokes-Coriolis force)
-         ztrdv(:,:,:) = pvv(:,:,:,Krhs)
-         SELECT CASE( nvor_scheme )
-         CASE( np_ENS )           ;   CALL vor_ens( kt, Kmm, ncor, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! enstrophy conserving scheme
-            IF( ln_stcor )            CALL vor_ens( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_ENE, np_MIX )   ;   CALL vor_ene( kt, Kmm, ncor, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! energy conserving scheme
-            IF( ln_stcor )            CALL vor_ene( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_ENT )           ;   CALL vor_enT( kt, Kmm, ncor, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! energy conserving scheme (T-pts)
-            IF( ln_stcor )            CALL vor_enT( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_EET )           ;   CALL vor_eeT( kt, Kmm, ncor, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! energy conserving scheme (een with e3t)
-            IF( ln_stcor )            CALL vor_eeT( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_EEN )           ;   CALL vor_een( kt, Kmm, ncor, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! energy & enstrophy scheme
-            IF( ln_stcor )            CALL vor_een( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         END SELECT
-         ztrdu(:,:,:) = puu(:,:,:,Krhs) - ztrdu(:,:,:)
-         ztrdv(:,:,:) = pvv(:,:,:,Krhs) - ztrdv(:,:,:)
-         CALL trd_dyn( ztrdu, ztrdv, jpdyn_pvo, kt, Kmm )
-         !
-         IF( n_dynadv /= np_LIN_dyn ) THEN   !* relative vorticity or metric trend (only in non-linear case)
-            ztrdu(:,:,:) = puu(:,:,:,Krhs)
-            ztrdv(:,:,:) = pvv(:,:,:,Krhs)
-            SELECT CASE( nvor_scheme )
-            CASE( np_ENT )           ;   CALL vor_enT( kt, Kmm, nrvm, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )  ! energy conserving scheme (T-pts)
-            CASE( np_EET )           ;   CALL vor_eeT( kt, Kmm, nrvm, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )  ! energy conserving scheme (een with e3t)
-            CASE( np_ENE )           ;   CALL vor_ene( kt, Kmm, nrvm, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )  ! energy conserving scheme
-            CASE( np_ENS, np_MIX )   ;   CALL vor_ens( kt, Kmm, nrvm, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )  ! enstrophy conserving scheme
-            CASE( np_EEN )           ;   CALL vor_een( kt, Kmm, nrvm, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )  ! energy & enstrophy scheme
-            END SELECT
-            ztrdu(:,:,:) = puu(:,:,:,Krhs) - ztrdu(:,:,:)
-            ztrdv(:,:,:) = pvv(:,:,:,Krhs) - ztrdv(:,:,:)
-            CALL trd_dyn( ztrdu, ztrdv, jpdyn_rvo, kt, Kmm )
-         ENDIF
-         !
-         DEALLOCATE( ztrdu, ztrdv )
-         !
-      ELSE              !==  total vorticity trend added to the general trend  ==!
-         !
-         SELECT CASE ( nvor_scheme )      !==  vorticity trend added to the general trend  ==!
-         CASE( np_ENT )                        !* energy conserving scheme  (T-pts)
-                             CALL vor_enT( kt, Kmm, ntot, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! total vorticity trend
-            IF( ln_stcor )   CALL vor_enT( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_EET )                        !* energy conserving scheme (een scheme using e3t)
-                             CALL vor_eeT( kt, Kmm, ntot, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! total vorticity trend
-            IF( ln_stcor )   CALL vor_eeT( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_ENE )                        !* energy conserving scheme
-                             CALL vor_ene( kt, Kmm, ntot, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! total vorticity trend
-            IF( ln_stcor )   CALL vor_ene( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_ENS )                        !* enstrophy conserving scheme
-                             CALL vor_ens( kt, Kmm, ntot, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )  ! total vorticity trend
-            IF( ln_stcor )   CALL vor_ens( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )  ! add the Stokes-Coriolis trend
-         CASE( np_MIX )                        !* mixed ene-ens scheme
-                             CALL vor_ens( kt, Kmm, nrvm, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! relative vorticity or metric trend (ens)
-                             CALL vor_ene( kt, Kmm, ncor, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! planetary vorticity trend (ene)
-            IF( ln_stcor )   CALL vor_ene( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         CASE( np_EEN )                        !* energy and enstrophy conserving scheme
-                             CALL vor_een( kt, Kmm, ntot, puu(:,:,:,Kmm) , pvv(:,:,:,Kmm) , puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! total vorticity trend
-            IF( ln_stcor )   CALL vor_een( kt, Kmm, ncor, usd, vsd, puu(:,:,:,Krhs), pvv(:,:,:,Krhs) )   ! add the Stokes-Coriolis trend
-         END SELECT
-         !
-      ENDIF
-      !
-      !                       ! print sum trends (used for debugging)
-      IF(sn_cfctl%l_prtctl) CALL prt_ctl( tab3d_1=puu(:,:,:,Krhs), clinfo1=' vor  - Ua: ', mask1=umask,               &
-         &                                tab3d_2=pvv(:,:,:,Krhs), clinfo2=       ' Va: ', mask2=vmask, clinfo3='dyn' )
-      !
-      IF( ln_timing )   CALL timing_stop('dyn_vor')
-      !
-   END SUBROUTINE dyn_vor
-
-
-   SUBROUTINE vor_enT( kt, Kmm, kvor, pu, pv, pu_rhs, pv_rhs )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE vor_enT  ***
-      !!
-      !! ** Purpose :   Compute the now total vorticity trend and add it to 
-      !!      the general trend of the momentum equation.
-      !!
-      !! ** Method  :   Trend evaluated using now fields (centered in time) 
-      !!       and t-point evaluation of vorticity (planetary and relative).
-      !!       conserves the horizontal kinetic energy.
-      !!         The general trend of momentum is increased due to the vorticity 
-      !!       term which is given by:
-      !!          voru = 1/bu  mj[ ( mi(mj(bf*rvor))+bt*f_t)/e3t  mj[vn] ]
-      !!          vorv = 1/bv  mi[ ( mi(mj(bf*rvor))+bt*f_t)/e3f  mj[un] ]
-      !!       where rvor is the relative vorticity at f-point
-      !!
-      !! ** Action : - Update (pu_rhs,pv_rhs) with the now vorticity term trend
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt               ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kmm              ! ocean time level index
-      INTEGER                         , INTENT(in   ) ::   kvor             ! total, planetary, relative, or metric
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu, pv           ! now velocities
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs   ! total v-trend
-      !
-      INTEGER  ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   zx1, zy1, zx2, zy2   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zwx, zwy, zwt   ! 2D workspace
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwz             ! 3D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:vor_enT : vorticity term: t-point energy conserving scheme'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-      !
-      !
-      SELECT CASE( kvor )                 !== relative vorticity considered  ==!
-      CASE ( np_RVO , np_CRV )                  !* relative vorticity at f-point is used
-         DO jk = 1, jpkm1                                ! Horizontal slab
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = (  e2v(ji+1,jj) * pv(ji+1,jj,jk) - e2v(ji,jj) * pv(ji,jj,jk)  &
-                  &             - e1u(ji,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
-            END_2D
-            IF( ln_dynvor_msk ) THEN                     ! mask relative vorticity 
-               DO_2D( 1, 0, 1, 0 )
-                  zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
-               END_2D
-            ENDIF
-         END DO
-         CALL lbc_lnk( 'dynvor', zwz, 'F', 1. )
-         !
-      END SELECT
-
-      !                                                ! ===============
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !                                             ! ===============
-         !
-         SELECT CASE( kvor )                 !==  volume weighted vorticity considered  ==!
-         !
-         CASE ( np_COR )                           !* Coriolis (planetary vorticity)
-            zwt(:,:) = ff_t(:,:) * e1e2t(:,:)*e3t(:,:,jk,Kmm)
-         CASE ( np_RVO )                           !* relative vorticity
-            DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = r1_4 * (   zwz(ji-1,jj  ,jk) + zwz(ji,jj  ,jk)   &
-                  &                  + zwz(ji-1,jj-1,jk) + zwz(ji,jj-1,jk) ) &
-                  &                * e1e2t(ji,jj)*e3t(ji,jj,jk,Kmm)
-            END_2D
-         CASE ( np_MET )                           !* metric term
-            DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = (   ( pv(ji,jj,jk) + pv(ji,jj-1,jk) ) * di_e2u_2(ji,jj)     &
-                  &           - ( pu(ji,jj,jk) + pu(ji-1,jj,jk) ) * dj_e1v_2(ji,jj)   ) &
-                  &         * e3t(ji,jj,jk,Kmm)
-            END_2D
-         CASE ( np_CRV )                           !* Coriolis + relative vorticity
-            DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = (  ff_t(ji,jj) + r1_4 * ( zwz(ji-1,jj  ,jk) + zwz(ji,jj  ,jk)      &
-                  &                                 + zwz(ji-1,jj-1,jk) + zwz(ji,jj-1,jk) )  ) &
-                  &         * e1e2t(ji,jj)*e3t(ji,jj,jk,Kmm)
-            END_2D
-         CASE ( np_CME )                           !* Coriolis + metric
-            DO_2D( 0, 1, 0, 1 )
-               zwt(ji,jj) = (  ff_t(ji,jj) * e1e2t(ji,jj)                             &
-                    &        + ( pv(ji,jj,jk) + pv(ji,jj-1,jk) ) * di_e2u_2(ji,jj)    &
-                    &        - ( pu(ji,jj,jk) + pu(ji-1,jj,jk) ) * dj_e1v_2(ji,jj)  ) &
-                    &       * e3t(ji,jj,jk,Kmm)
-            END_2D
-         CASE DEFAULT                                             ! error
-            CALL ctl_stop('STOP','dyn_vor: wrong value for kvor'  )
-         END SELECT
-         !
-         !                                   !==  compute and add the vorticity term trend  =!
-         DO_2D( 0, 0, 0, 0 )
-            pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + r1_4 * r1_e1e2u(ji,jj) / e3u(ji,jj,jk,Kmm)                    &
-               &                                * (  zwt(ji+1,jj) * ( pv(ji+1,jj,jk) + pv(ji+1,jj-1,jk) )   &
-               &                                   + zwt(ji  ,jj) * ( pv(ji  ,jj,jk) + pv(ji  ,jj-1,jk) )   )
-               !
-            pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) - r1_4 * r1_e1e2v(ji,jj) / e3v(ji,jj,jk,Kmm)                    &
-               &                                * (  zwt(ji,jj+1) * ( pu(ji,jj+1,jk) + pu(ji-1,jj+1,jk) )   & 
-               &                                   + zwt(ji,jj  ) * ( pu(ji,jj  ,jk) + pu(ji-1,jj  ,jk) )   ) 
-         END_2D
-         !                                             ! ===============
-      END DO                                           !   End of slab
-      !                                                ! ===============
-   END SUBROUTINE vor_enT
-
-
-   SUBROUTINE vor_ene( kt, Kmm, kvor, pu, pv, pu_rhs, pv_rhs )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE vor_ene  ***
-      !!
-      !! ** Purpose :   Compute the now total vorticity trend and add it to 
-      !!      the general trend of the momentum equation.
-      !!
-      !! ** Method  :   Trend evaluated using now fields (centered in time) 
-      !!       and the Sadourny (1975) flux form formulation : conserves the
-      !!       horizontal kinetic energy.
-      !!         The general trend of momentum is increased due to the vorticity 
-      !!       term which is given by:
-      !!          voru = 1/e1u  mj-1[ (rvor+f)/e3f  mi(e1v*e3v pvv(:,:,:,Kmm)) ]
-      !!          vorv = 1/e2v  mi-1[ (rvor+f)/e3f  mj(e2u*e3u puu(:,:,:,Kmm)) ]
-      !!       where rvor is the relative vorticity
-      !!
-      !! ** Action : - Update (pu_rhs,pv_rhs) with the now vorticity term trend
-      !!
-      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kmm              ! ocean time level index
-      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu, pv    ! now velocities
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs    ! total v-trend
-      !
-      INTEGER  ::   ji, jj, jk           ! dummy loop indices
-      REAL(wp) ::   zx1, zy1, zx2, zy2   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:vor_ene : vorticity term: energy conserving scheme'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-      !
-      !                                                ! ===============
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !                                             ! ===============
-         !
-         SELECT CASE( kvor )                 !==  vorticity considered  ==!
-         CASE ( np_COR )                           !* Coriolis (planetary vorticity)
-            zwz(:,:) = ff_f(:,:) 
-         CASE ( np_RVO )                           !* relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = (  e2v(ji+1,jj  ) * pv(ji+1,jj  ,jk) - e2v(ji,jj) * pv(ji,jj,jk)    &
-                  &          - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
-            END_2D
-            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
-               DO_2D( 1, 0, 1, 0 )
-                  zwz(ji,jj) = zwz(ji,jj) * fmask(ji,jj,jk)
-               END_2D
-            ENDIF
-         CASE ( np_MET )                           !* metric term
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = ( pv(ji+1,jj  ,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &       - ( pu(ji  ,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)
-            END_2D
-         CASE ( np_CRV )                           !* Coriolis + relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = ff_f(ji,jj) + (  e2v(ji+1,jj) * pv(ji+1,jj,jk) - e2v(ji,jj) * pv(ji,jj,jk)      &
-                  &                        - e1u(ji,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
-            END_2D
-            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity (NOT the Coriolis term)
-               DO_2D( 1, 0, 1, 0 )
-                  zwz(ji,jj) = ( zwz(ji,jj) - ff_f(ji,jj) ) * fmask(ji,jj,jk) + ff_f(ji,jj)
-               END_2D
-            ENDIF
-         CASE ( np_CME )                           !* Coriolis + metric
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = ff_f(ji,jj) + ( pv(ji+1,jj  ,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &                     - ( pu(ji  ,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)
-            END_2D
-         CASE DEFAULT                                             ! error
-            CALL ctl_stop('STOP','dyn_vor: wrong value for kvor'  )
-         END SELECT
-         !
-         !                                   !==  horizontal fluxes and potential vorticity ==!
-         zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
-         zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-         zwz(:,:) = zwz(:,:) / e3f(:,:,jk)
-         !
-         !                                   !==  compute and add the vorticity term trend  =!
-         DO_2D( 0, 0, 0, 0 )
-            zy1 = zwy(ji,jj-1) + zwy(ji+1,jj-1)
-            zy2 = zwy(ji,jj  ) + zwy(ji+1,jj  )
-            zx1 = zwx(ji-1,jj) + zwx(ji-1,jj+1)
-            zx2 = zwx(ji  ,jj) + zwx(ji  ,jj+1)
-            pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + r1_4 * r1_e1u(ji,jj) * ( zwz(ji  ,jj-1) * zy1 + zwz(ji,jj) * zy2 )
-            pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) - r1_4 * r1_e2v(ji,jj) * ( zwz(ji-1,jj  ) * zx1 + zwz(ji,jj) * zx2 ) 
-         END_2D
-         !                                             ! ===============
-      END DO                                           !   End of slab
-      !                                                ! ===============
-   END SUBROUTINE vor_ene
-
-
-   SUBROUTINE vor_ens( kt, Kmm, kvor, pu, pv, pu_rhs, pv_rhs )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE vor_ens  ***
-      !!
-      !! ** Purpose :   Compute the now total vorticity trend and add it to
-      !!      the general trend of the momentum equation.
-      !!
-      !! ** Method  :   Trend evaluated using now fields (centered in time)
-      !!      and the Sadourny (1975) flux FORM formulation : conserves the
-      !!      potential enstrophy of a horizontally non-divergent flow. the
-      !!      trend of the vorticity term is given by:
-      !!          voru = 1/e1u  mj-1[ (rvor+f)/e3f ]  mj-1[ mi(e1v*e3v pvv(:,:,:,Kmm)) ]
-      !!          vorv = 1/e2v  mi-1[ (rvor+f)/e3f ]  mi-1[ mj(e2u*e3u puu(:,:,:,Kmm)) ]
-      !!      Add this trend to the general momentum trend:
-      !!          (u(rhs),v(Krhs)) = (u(rhs),v(Krhs)) + ( voru , vorv )
-      !!
-      !! ** Action : - Update (pu_rhs,pv_rhs)) arrays with the now vorticity term trend
-      !!
-      !! References : Sadourny, r., 1975, j. atmos. sciences, 32, 680-689.
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kmm              ! ocean time level index
-      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu, pv    ! now velocities
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs    ! total v-trend
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zuav, zvau   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj) ::   zwx, zwy, zwz, zww   ! 2D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:vor_ens : vorticity term: enstrophy conserving scheme'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-      !                                                ! ===============
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !                                             ! ===============
-         !
-         SELECT CASE( kvor )                 !==  vorticity considered  ==!
-         CASE ( np_COR )                           !* Coriolis (planetary vorticity)
-            zwz(:,:) = ff_f(:,:) 
-         CASE ( np_RVO )                           !* relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = (  e2v(ji+1,jj  ) * pv(ji+1,jj  ,jk) - e2v(ji,jj) * pv(ji,jj,jk)    &
-                  &          - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
-            END_2D
-            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity
-               DO_2D( 1, 0, 1, 0 )
-                  zwz(ji,jj) = ff_f(ji,jj) * fmask(ji,jj,jk)
-               END_2D
-            ENDIF
-         CASE ( np_MET )                           !* metric term
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = ( pv(ji+1,jj  ,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &       - ( pu(ji  ,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)
-            END_2D
-         CASE ( np_CRV )                           !* Coriolis + relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = ff_f(ji,jj) + (  e2v(ji+1,jj  ) * pv(ji+1,jj  ,jk) - e2v(ji,jj) * pv(ji,jj,jk)  &
-                  &                        - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)
-            END_2D
-            IF( ln_dynvor_msk ) THEN                     ! mask the relative vorticity (NOT the Coriolis term)
-               DO_2D( 1, 0, 1, 0 )
-                  zwz(ji,jj) = ( zwz(ji,jj) - ff_f(ji,jj) ) * fmask(ji,jj,jk) + ff_f(ji,jj)
-               END_2D
-            ENDIF
-         CASE ( np_CME )                           !* Coriolis + metric
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj) = ff_f(ji,jj) + ( pv(ji+1,jj  ,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &                     - ( pu(ji  ,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)
-            END_2D
-         CASE DEFAULT                                             ! error
-            CALL ctl_stop('STOP','dyn_vor: wrong value for kvor'  )
-         END SELECT
-         !
-         !
-         !                                   !==  horizontal fluxes and potential vorticity ==!
-         zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
-         zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-         zwz(:,:) = zwz(:,:) / e3f(:,:,jk)
-         !
-         !                                   !==  compute and add the vorticity term trend  =!
-         DO_2D( 0, 0, 0, 0 )
-            zuav = r1_8 * r1_e1u(ji,jj) * (  zwy(ji  ,jj-1) + zwy(ji+1,jj-1)  &
-               &                           + zwy(ji  ,jj  ) + zwy(ji+1,jj  )  )
-            zvau =-r1_8 * r1_e2v(ji,jj) * (  zwx(ji-1,jj  ) + zwx(ji-1,jj+1)  &
-               &                           + zwx(ji  ,jj  ) + zwx(ji  ,jj+1)  )
-            pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zuav * ( zwz(ji  ,jj-1) + zwz(ji,jj) )
-            pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zvau * ( zwz(ji-1,jj  ) + zwz(ji,jj) )
-         END_2D
-         !                                             ! ===============
-      END DO                                           !   End of slab
-      !                                                ! ===============
-   END SUBROUTINE vor_ens
-
-
-   SUBROUTINE vor_een( kt, Kmm, kvor, pu, pv, pu_rhs, pv_rhs )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE vor_een  ***
-      !!
-      !! ** Purpose :   Compute the now total vorticity trend and add it to 
-      !!      the general trend of the momentum equation.
-      !!
-      !! ** Method  :   Trend evaluated using now fields (centered in time) 
-      !!      and the Arakawa and Lamb (1980) flux form formulation : conserves 
-      !!      both the horizontal kinetic energy and the potential enstrophy
-      !!      when horizontal divergence is zero (see the NEMO documentation)
-      !!      Add this trend to the general momentum trend (pu_rhs,pv_rhs).
-      !!
-      !! ** Action : - Update (pu_rhs,pv_rhs) with the now vorticity term trend
-      !!
-      !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kmm              ! ocean time level index
-      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu, pv    ! now velocities
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs    ! total v-trend
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   ierr         ! local integer
-      REAL(wp) ::   zua, zva     ! local scalars
-      REAL(wp) ::   zmsk, ze3f   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zwx , zwy , z1_e3f
-      REAL(wp), DIMENSION(jpi,jpj)     ::   ztnw, ztne, ztsw, ztse
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwz
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:vor_een : vorticity term: energy and enstrophy conserving scheme'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-      !
-      !                                                ! ===============
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !                                             ! ===============
-         !
-         SELECT CASE( nn_een_e3f )           ! == reciprocal of e3 at F-point
-         CASE ( 0 )                                   ! original formulation  (masked averaging of e3t divided by 4)
-            DO_2D( 1, 0, 1, 0 )
-               ze3f = (  e3t(ji  ,jj+1,jk,Kmm)*tmask(ji  ,jj+1,jk)   &
-                  &    + e3t(ji+1,jj+1,jk,Kmm)*tmask(ji+1,jj+1,jk)   &
-                  &    + e3t(ji  ,jj  ,jk,Kmm)*tmask(ji  ,jj  ,jk)   &
-                  &    + e3t(ji+1,jj  ,jk,Kmm)*tmask(ji+1,jj  ,jk)  )
-               IF( ze3f /= 0._wp ) THEN   ;   z1_e3f(ji,jj) = 4._wp / ze3f
-               ELSE                       ;   z1_e3f(ji,jj) = 0._wp
-               ENDIF
-            END_2D
-         CASE ( 1 )                                   ! new formulation  (masked averaging of e3t divided by the sum of mask)
-            DO_2D( 1, 0, 1, 0 )
-               ze3f = (  e3t(ji  ,jj+1,jk,Kmm)*tmask(ji  ,jj+1,jk)   &
-                  &    + e3t(ji+1,jj+1,jk,Kmm)*tmask(ji+1,jj+1,jk)   &
-                  &    + e3t(ji  ,jj  ,jk,Kmm)*tmask(ji  ,jj  ,jk)   &
-                  &    + e3t(ji+1,jj  ,jk,Kmm)*tmask(ji+1,jj  ,jk)  )
-               zmsk = (                    tmask(ji,jj+1,jk) +                     tmask(ji+1,jj+1,jk)   &
-                  &                      + tmask(ji,jj  ,jk) +                     tmask(ji+1,jj  ,jk)  )
-               IF( ze3f /= 0._wp ) THEN   ;   z1_e3f(ji,jj) = zmsk / ze3f
-               ELSE                       ;   z1_e3f(ji,jj) = 0._wp
-               ENDIF
-            END_2D
-         END SELECT
-         !
-         SELECT CASE( kvor )                 !==  vorticity considered  ==!
-         CASE ( np_COR )                           !* Coriolis (planetary vorticity)
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = ff_f(ji,jj) * z1_e3f(ji,jj)
-            END_2D
-         CASE ( np_RVO )                           !* relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = ( e2v(ji+1,jj  ) * pv(ji+1,jj,jk) - e2v(ji,jj) * pv(ji,jj,jk)  &
-                  &            - e1u(ji  ,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) * r1_e1e2f(ji,jj)*z1_e3f(ji,jj)
-            END_2D
-         CASE ( np_MET )                           !* metric term
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = (   ( pv(ji+1,jj,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &              - ( pu(ji,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)   ) * z1_e3f(ji,jj)
-            END_2D
-         CASE ( np_CRV )                           !* Coriolis + relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = (  ff_f(ji,jj) + (  e2v(ji+1,jj  ) * pv(ji+1,jj,jk) - e2v(ji,jj) * pv(ji,jj,jk)      &
-                  &                              - e1u(ji  ,jj+1) * pu(ji,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  )   &
-                  &                           * r1_e1e2f(ji,jj)   ) * z1_e3f(ji,jj)
-            END_2D
-         CASE ( np_CME )                           !* Coriolis + metric
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = (   ff_f(ji,jj) + ( pv(ji+1,jj  ,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &                            - ( pu(ji  ,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)   ) * z1_e3f(ji,jj)
-            END_2D
-         CASE DEFAULT                                             ! error
-            CALL ctl_stop('STOP','dyn_vor: wrong value for kvor'  )
-         END SELECT
-         !
-         IF( ln_dynvor_msk ) THEN          !==  mask/unmask vorticity ==!
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
-            END_2D
-         ENDIF
-      END DO                                           !   End of slab
-         !
-      CALL lbc_lnk( 'dynvor', zwz, 'F', 1. )
-
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !
-         !                                   !==  horizontal fluxes  ==!
-         zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
-         zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-
-         !                                   !==  compute and add the vorticity term trend  =!
-         jj = 2
-         ztne(1,:) = 0   ;   ztnw(1,:) = 0   ;   ztse(1,:) = 0   ;   ztsw(1,:) = 0
-         DO ji = 2, jpi          ! split in 2 parts due to vector opt.
-               ztne(ji,jj) = zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk)
-               ztnw(ji,jj) = zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk)
-               ztse(ji,jj) = zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk)
-               ztsw(ji,jj) = zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk)
-         END DO
-         DO jj = 3, jpj
-            DO ji = 2, jpi   ! vector opt. ok because we start at jj = 3
-               ztne(ji,jj) = zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk)
-               ztnw(ji,jj) = zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk)
-               ztse(ji,jj) = zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk)
-               ztsw(ji,jj) = zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk)
-            END DO
-         END DO
-         DO_2D( 0, 0, 0, 0 )
-            zua = + r1_12 * r1_e1u(ji,jj) * (  ztne(ji,jj  ) * zwy(ji  ,jj  ) + ztnw(ji+1,jj) * zwy(ji+1,jj  )   &
-               &                             + ztse(ji,jj  ) * zwy(ji  ,jj-1) + ztsw(ji+1,jj) * zwy(ji+1,jj-1) )
-            zva = - r1_12 * r1_e2v(ji,jj) * (  ztsw(ji,jj+1) * zwx(ji-1,jj+1) + ztse(ji,jj+1) * zwx(ji  ,jj+1)   &
-               &                             + ztnw(ji,jj  ) * zwx(ji-1,jj  ) + ztne(ji,jj  ) * zwx(ji  ,jj  ) )
-            pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zua
-            pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zva
-         END_2D
-         !                                             ! ===============
-      END DO                                           !   End of slab
-      !                                                ! ===============
-   END SUBROUTINE vor_een
-
-
-
-   SUBROUTINE vor_eeT( kt, Kmm, kvor, pu, pv, pu_rhs, pv_rhs )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE vor_eeT  ***
-      !!
-      !! ** Purpose :   Compute the now total vorticity trend and add it to 
-      !!      the general trend of the momentum equation.
-      !!
-      !! ** Method  :   Trend evaluated using now fields (centered in time) 
-      !!      and the Arakawa and Lamb (1980) vector form formulation using 
-      !!      a modified version of Arakawa and Lamb (1980) scheme (see vor_een).
-      !!      The change consists in 
-      !!      Add this trend to the general momentum trend (pu_rhs,pv_rhs).
-      !!
-      !! ** Action : - Update (pu_rhs,pv_rhs) with the now vorticity term trend
-      !!
-      !! References : Arakawa and Lamb 1980, Mon. Wea. Rev., 109, 18-36
-      !!----------------------------------------------------------------------
-      INTEGER                         , INTENT(in   ) ::   kt          ! ocean time-step index
-      INTEGER                         , INTENT(in   ) ::   Kmm              ! ocean time level index
-      INTEGER                         , INTENT(in   ) ::   kvor        ! total, planetary, relative, or metric
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu, pv    ! now velocities
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pu_rhs, pv_rhs    ! total v-trend
-      !
-      INTEGER  ::   ji, jj, jk     ! dummy loop indices
-      INTEGER  ::   ierr           ! local integer
-      REAL(wp) ::   zua, zva       ! local scalars
-      REAL(wp) ::   zmsk, z1_e3t   ! local scalars
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zwx , zwy 
-      REAL(wp), DIMENSION(jpi,jpj)     ::   ztnw, ztne, ztsw, ztse
-      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwz
-      !!----------------------------------------------------------------------
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dyn:vor_een : vorticity term: energy and enstrophy conserving scheme'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-      !
-      !                                                ! ===============
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !                                             ! ===============
-         !
-         !
-         SELECT CASE( kvor )                 !==  vorticity considered  ==!
-         CASE ( np_COR )                           !* Coriolis (planetary vorticity)
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = ff_f(ji,jj)
-            END_2D
-         CASE ( np_RVO )                           !* relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = (  e2v(ji+1,jj  ) * pv(ji+1,jj  ,jk) - e2v(ji,jj) * pv(ji,jj,jk)    &
-                  &             - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) &
-                  &          * r1_e1e2f(ji,jj)
-            END_2D
-         CASE ( np_MET )                           !* metric term
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = ( pv(ji+1,jj  ,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &          - ( pu(ji  ,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)
-            END_2D
-         CASE ( np_CRV )                           !* Coriolis + relative vorticity
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = (  ff_f(ji,jj) + (  e2v(ji+1,jj  ) * pv(ji+1,jj  ,jk) - e2v(ji,jj) * pv(ji,jj,jk)    &
-                  &                              - e1u(ji  ,jj+1) * pu(ji  ,jj+1,jk) + e1u(ji,jj) * pu(ji,jj,jk)  ) &
-                  &                         * r1_e1e2f(ji,jj)    )
-            END_2D
-         CASE ( np_CME )                           !* Coriolis + metric
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = ff_f(ji,jj) + ( pv(ji+1,jj  ,jk) + pv(ji,jj,jk) ) * di_e2v_2e1e2f(ji,jj)   &
-                  &                        - ( pu(ji  ,jj+1,jk) + pu(ji,jj,jk) ) * dj_e1u_2e1e2f(ji,jj)
-            END_2D
-         CASE DEFAULT                                             ! error
-            CALL ctl_stop('STOP','dyn_vor: wrong value for kvor'  )
-         END SELECT
-         !
-         IF( ln_dynvor_msk ) THEN          !==  mask/unmask vorticity ==!
-            DO_2D( 1, 0, 1, 0 )
-               zwz(ji,jj,jk) = zwz(ji,jj,jk) * fmask(ji,jj,jk)
-            END_2D
-         ENDIF
-      END DO
-      !
-      CALL lbc_lnk( 'dynvor', zwz, 'F', 1. )
-      !
-      DO jk = 1, jpkm1                                 ! Horizontal slab
-         !
-         !                                   !==  horizontal fluxes  ==!
-         zwx(:,:) = e2u(:,:) * e3u(:,:,jk,Kmm) * pu(:,:,jk)
-         zwy(:,:) = e1v(:,:) * e3v(:,:,jk,Kmm) * pv(:,:,jk)
-
-         !                                   !==  compute and add the vorticity term trend  =!
-         jj = 2
-         ztne(1,:) = 0   ;   ztnw(1,:) = 0   ;   ztse(1,:) = 0   ;   ztsw(1,:) = 0
-         DO ji = 2, jpi          ! split in 2 parts due to vector opt.
-               z1_e3t = 1._wp / e3t(ji,jj,jk,Kmm)
-               ztne(ji,jj) = ( zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) ) * z1_e3t
-               ztnw(ji,jj) = ( zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) ) * z1_e3t
-               ztse(ji,jj) = ( zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) ) * z1_e3t
-               ztsw(ji,jj) = ( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) ) * z1_e3t
-         END DO
-         DO jj = 3, jpj
-            DO ji = 2, jpi   ! vector opt. ok because we start at jj = 3
-               z1_e3t = 1._wp / e3t(ji,jj,jk,Kmm)
-               ztne(ji,jj) = ( zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) ) * z1_e3t
-               ztnw(ji,jj) = ( zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) + zwz(ji  ,jj  ,jk) ) * z1_e3t
-               ztse(ji,jj) = ( zwz(ji  ,jj  ,jk) + zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) ) * z1_e3t
-               ztsw(ji,jj) = ( zwz(ji  ,jj-1,jk) + zwz(ji-1,jj-1,jk) + zwz(ji-1,jj  ,jk) ) * z1_e3t
-            END DO
-         END DO
-         DO_2D( 0, 0, 0, 0 )
-            zua = + r1_12 * r1_e1u(ji,jj) * (  ztne(ji,jj  ) * zwy(ji  ,jj  ) + ztnw(ji+1,jj) * zwy(ji+1,jj  )   &
-               &                             + ztse(ji,jj  ) * zwy(ji  ,jj-1) + ztsw(ji+1,jj) * zwy(ji+1,jj-1) )
-            zva = - r1_12 * r1_e2v(ji,jj) * (  ztsw(ji,jj+1) * zwx(ji-1,jj+1) + ztse(ji,jj+1) * zwx(ji  ,jj+1)   &
-               &                             + ztnw(ji,jj  ) * zwx(ji-1,jj  ) + ztne(ji,jj  ) * zwx(ji  ,jj  ) )
-            pu_rhs(ji,jj,jk) = pu_rhs(ji,jj,jk) + zua
-            pv_rhs(ji,jj,jk) = pv_rhs(ji,jj,jk) + zva
-         END_2D
-         !                                             ! ===============
-      END DO                                           !   End of slab
-      !                                                ! ===============
-   END SUBROUTINE vor_eeT
-
-
-   SUBROUTINE dyn_vor_init
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dyn_vor_init  ***
-      !!
-      !! ** Purpose :   Control the consistency between cpp options for
-      !!              tracer advection schemes
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk    ! dummy loop indices
-      INTEGER ::   ioptio, ios   ! local integer
-      !!
-      NAMELIST/namdyn_vor/ ln_dynvor_ens, ln_dynvor_ene, ln_dynvor_enT, ln_dynvor_eeT,   &
-         &                 ln_dynvor_een, nn_een_e3f   , ln_dynvor_mix, ln_dynvor_msk
-      !!----------------------------------------------------------------------
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'dyn_vor_init : vorticity term : read namelist and control the consistency'
-         WRITE(numout,*) '~~~~~~~~~~~~'
-      ENDIF
-      !
-      READ  ( numnam_ref, namdyn_vor, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_vor in reference namelist' )
-      READ  ( numnam_cfg, namdyn_vor, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_vor in configuration namelist' )
-      IF(lwm) WRITE ( numond, namdyn_vor )
-      !
-      IF(lwp) THEN                    ! Namelist print
-         WRITE(numout,*) '   Namelist namdyn_vor : choice of the vorticity term scheme'
-         WRITE(numout,*) '      enstrophy conserving scheme                    ln_dynvor_ens = ', ln_dynvor_ens
-         WRITE(numout,*) '      f-point energy conserving scheme               ln_dynvor_ene = ', ln_dynvor_ene
-         WRITE(numout,*) '      t-point energy conserving scheme               ln_dynvor_enT = ', ln_dynvor_enT
-         WRITE(numout,*) '      energy conserving scheme  (een using e3t)      ln_dynvor_eeT = ', ln_dynvor_eeT
-         WRITE(numout,*) '      enstrophy and energy conserving scheme         ln_dynvor_een = ', ln_dynvor_een
-         WRITE(numout,*) '         e3f = averaging /4 (=0) or /sum(tmask) (=1)    nn_een_e3f = ', nn_een_e3f
-         WRITE(numout,*) '      mixed enstrophy/energy conserving scheme       ln_dynvor_mix = ', ln_dynvor_mix
-         WRITE(numout,*) '      masked (=T) or unmasked(=F) vorticity          ln_dynvor_msk = ', ln_dynvor_msk
-      ENDIF
-
-!!an      IF( ln_dynvor_msk )   CALL ctl_stop( 'dyn_vor_init:   masked vorticity is not currently not available')
-
-!!gm  this should be removed when choosing a unique strategy for fmask at the coast
-      ! If energy, enstrophy or mixed advection of momentum in vector form change the value for masks
-      ! at angles with three ocean points and one land point
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) '      change fmask value in the angles (T)           ln_vorlat = ', ln_vorlat
-      IF( ln_vorlat .AND. ( ln_dynvor_ene .OR. ln_dynvor_ens .OR. ln_dynvor_mix ) ) THEN
-         DO_3D( 1, 0, 1, 0, 1, jpk )
-            IF(    tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk)              &
-               & + tmask(ji,jj  ,jk) + tmask(ji+1,jj+1,jk) == 3._wp )   fmask(ji,jj,jk) = 1._wp
-         END_3D
-         !
-         CALL lbc_lnk( 'dynvor', fmask, 'F', 1._wp )      ! Lateral boundary conditions on fmask
-         !
-      ENDIF
-!!gm end
-
-      ioptio = 0                     ! type of scheme for vorticity (set nvor_scheme)
-      IF( ln_dynvor_ens ) THEN   ;   ioptio = ioptio + 1   ;   nvor_scheme = np_ENS   ;   ENDIF
-      IF( ln_dynvor_ene ) THEN   ;   ioptio = ioptio + 1   ;   nvor_scheme = np_ENE   ;   ENDIF
-      IF( ln_dynvor_enT ) THEN   ;   ioptio = ioptio + 1   ;   nvor_scheme = np_ENT   ;   ENDIF
-      IF( ln_dynvor_eeT ) THEN   ;   ioptio = ioptio + 1   ;   nvor_scheme = np_EET   ;   ENDIF
-      IF( ln_dynvor_een ) THEN   ;   ioptio = ioptio + 1   ;   nvor_scheme = np_EEN   ;   ENDIF
-      IF( ln_dynvor_mix ) THEN   ;   ioptio = ioptio + 1   ;   nvor_scheme = np_MIX   ;   ENDIF
-      !
-      IF( ioptio /= 1 ) CALL ctl_stop( ' use ONE and ONLY one vorticity scheme' )
-      !                      
-      IF(lwp) WRITE(numout,*)        ! type of calculated vorticity (set ncor, nrvm, ntot)
-      ncor = np_COR                       ! planetary vorticity
-      SELECT CASE( n_dynadv )
-      CASE( np_LIN_dyn )
-         IF(lwp) WRITE(numout,*) '   ==>>>   linear dynamics : total vorticity = Coriolis'
-         nrvm = np_COR        ! planetary vorticity
-         ntot = np_COR        !     -         -
-      CASE( np_VEC_c2  )
-         IF(lwp) WRITE(numout,*) '   ==>>>   vector form dynamics : total vorticity = Coriolis + relative vorticity' 
-         nrvm = np_RVO        ! relative vorticity
-         ntot = np_CRV        ! relative + planetary vorticity         
-      CASE( np_FLX_c2 , np_FLX_ubs  )
-         IF(lwp) WRITE(numout,*) '   ==>>>   flux form dynamics : total vorticity = Coriolis + metric term'
-         nrvm = np_MET        ! metric term
-         ntot = np_CME        ! Coriolis + metric term
-         !
-         SELECT CASE( nvor_scheme )    ! pre-computed gradients for the metric term:
-         CASE( np_ENT )                      !* T-point metric term :   pre-compute di(e2u)/2 and dj(e1v)/2
-            ALLOCATE( di_e2u_2(jpi,jpj), dj_e1v_2(jpi,jpj) )
-            DO_2D( 0, 0, 0, 0 )
-               di_e2u_2(ji,jj) = ( e2u(ji,jj) - e2u(ji-1,jj  ) ) * 0.5_wp
-               dj_e1v_2(ji,jj) = ( e1v(ji,jj) - e1v(ji  ,jj-1) ) * 0.5_wp
-            END_2D
-            CALL lbc_lnk_multi( 'dynvor', di_e2u_2, 'T', -1. , dj_e1v_2, 'T', -1. )   ! Lateral boundary conditions
-            !
-         CASE DEFAULT                        !* F-point metric term :   pre-compute di(e2u)/(2*e1e2f) and dj(e1v)/(2*e1e2f)
-            ALLOCATE( di_e2v_2e1e2f(jpi,jpj), dj_e1u_2e1e2f(jpi,jpj) )
-            DO_2D( 1, 0, 1, 0 )
-               di_e2v_2e1e2f(ji,jj) = ( e2v(ji+1,jj  ) - e2v(ji,jj) )  * 0.5 * r1_e1e2f(ji,jj)
-               dj_e1u_2e1e2f(ji,jj) = ( e1u(ji  ,jj+1) - e1u(ji,jj) )  * 0.5 * r1_e1e2f(ji,jj)
-            END_2D
-            CALL lbc_lnk_multi( 'dynvor', di_e2v_2e1e2f, 'F', -1. , dj_e1u_2e1e2f, 'F', -1. )   ! Lateral boundary conditions
-         END SELECT
-         !
-      END SELECT
-      
-      IF(lwp) THEN                   ! Print the choice
-         WRITE(numout,*)
-         SELECT CASE( nvor_scheme )
-         CASE( np_ENS )   ;   WRITE(numout,*) '   ==>>>   enstrophy conserving scheme (ENS)'
-         CASE( np_ENE )   ;   WRITE(numout,*) '   ==>>>   energy conserving scheme (Coriolis at F-points) (ENE)'
-         CASE( np_ENT )   ;   WRITE(numout,*) '   ==>>>   energy conserving scheme (Coriolis at T-points) (ENT)'
-         CASE( np_EET )   ;   WRITE(numout,*) '   ==>>>   energy conserving scheme (EEN scheme using e3t) (EET)'
-         CASE( np_EEN )   ;   WRITE(numout,*) '   ==>>>   energy and enstrophy conserving scheme (EEN)'
-         CASE( np_MIX )   ;   WRITE(numout,*) '   ==>>>   mixed enstrophy/energy conserving scheme (MIX)'
-         END SELECT         
-      ENDIF
-      !
-   END SUBROUTINE dyn_vor_init
-
-   !!==============================================================================
-END MODULE dynvor
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/ldfdyn.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/ldfdyn.F90	(revision 14059)
+++ 	(revision )
@@ -1,525 +1,0 @@
-MODULE ldfdyn
-   !!======================================================================
-   !!                       ***  MODULE  ldfdyn  ***
-   !! Ocean physics:  lateral viscosity coefficient 
-   !!=====================================================================
-   !! History :  OPA  ! 1997-07  (G. Madec)  multi dimensional coefficients
-   !!   NEMO     1.0  ! 2002-09  (G. Madec)  F90: Free form and module
-   !!            3.7  ! 2014-01  (F. Lemarie, G. Madec)  restructuration/simplification of ahm specification,
-   !!                 !                                  add velocity dependent coefficient and optional read in file
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   ldf_dyn_init  : initialization, namelist read, and parameters control
-   !!   ldf_dyn       : update lateral eddy viscosity coefficients at each time step 
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers   
-   USE dom_oce         ! ocean space and time domain 
-   USE phycst          ! physical constants
-   USE ldfslp          ! lateral diffusion: slopes of mixing orientation
-   USE ldfc1d_c2d      ! lateral diffusion: 1D and 2D cases
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O module for ehanced bottom friction file
-   USE timing          ! Timing
-   USE lib_mpp         ! distribued memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   ldf_dyn_init   ! called by nemogcm.F90
-   PUBLIC   ldf_dyn        ! called by step.F90
-
-   !                                    !!* Namelist namdyn_ldf : lateral mixing on momentum *
-   LOGICAL , PUBLIC ::   ln_dynldf_OFF   !: No operator (i.e. no explicit diffusion)
-   LOGICAL , PUBLIC ::   ln_dynldf_lap   !: laplacian operator
-   LOGICAL , PUBLIC ::   ln_dynldf_blp   !: bilaplacian operator
-   LOGICAL , PUBLIC ::   ln_dynldf_lev   !: iso-level direction
-   LOGICAL , PUBLIC ::   ln_dynldf_hor   !: horizontal (geopotential) direction
-!  LOGICAL , PUBLIC ::   ln_dynldf_iso   !: iso-neutral direction                        (see ldfslp)
-   INTEGER , PUBLIC ::   nn_ahm_ijk_t    !: choice of time & space variations of the lateral eddy viscosity coef.
-   !                                        !  time invariant coefficients:  aht = 1/2  Ud*Ld   (lap case) 
-   !                                           !                             bht = 1/12 Ud*Ld^3 (blp case)
-   REAL(wp), PUBLIC ::   rn_Uv                 !: lateral viscous velocity  [m/s]
-   REAL(wp), PUBLIC ::   rn_Lv                 !: lateral viscous length    [m]
-   !                                        ! Smagorinsky viscosity  (nn_ahm_ijk_t = 32) 
-   REAL(wp), PUBLIC ::   rn_csmc               !: Smagorinsky constant of proportionality 
-   REAL(wp), PUBLIC ::   rn_minfac             !: Multiplicative factor of theorectical minimum Smagorinsky viscosity
-   REAL(wp), PUBLIC ::   rn_maxfac             !: Multiplicative factor of theorectical maximum Smagorinsky viscosity
-   !                                        ! iso-neutral laplacian (ln_dynldf_lap=ln_dynldf_iso=T)
-   REAL(wp), PUBLIC ::   rn_ahm_b              !: lateral laplacian background eddy viscosity  [m2/s]
-
-   !                                    !!* Parameter to control the type of lateral viscous operator
-   INTEGER, PARAMETER, PUBLIC ::   np_ERROR  =-10                       !: error in setting the operator
-   INTEGER, PARAMETER, PUBLIC ::   np_no_ldf = 00                       !: without operator (i.e. no lateral viscous trend)
-   !                          !!      laplacian     !    bilaplacian    !
-   INTEGER, PARAMETER, PUBLIC ::   np_lap    = 10   ,   np_blp    = 20  !: iso-level operator
-   INTEGER, PARAMETER, PUBLIC ::   np_lap_i  = 11                       !: iso-neutral or geopotential operator
-   !
-   INTEGER           , PUBLIC ::   nldf_dyn         !: type of lateral diffusion used defined from ln_dynldf_... (namlist logicals)
-   LOGICAL           , PUBLIC ::   l_ldfdyn_time    !: flag for time variation of the lateral eddy viscosity coef.
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   ahmt, ahmf   !: eddy viscosity coef. at T- and F-points [m2/s or m4/s]
-   REAL(wp),         ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dtensq       !: horizontal tension squared         (Smagorinsky only)
-   REAL(wp),         ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   dshesq       !: horizontal shearing strain squared (Smagorinsky only)
-   REAL(wp),         ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   esqt, esqf   !: Square of the local gridscale (e1e2/(e1+e2))**2           
-
-   REAL(wp) ::   r1_2    = 0.5_wp            ! =1/2
-   REAL(wp) ::   r1_4    = 0.25_wp           ! =1/4
-   REAL(wp) ::   r1_8    = 0.125_wp          ! =1/8
-   REAL(wp) ::   r1_12   = 1._wp / 12._wp    ! =1/12
-   REAL(wp) ::   r1_288  = 1._wp / 288._wp   ! =1/( 12^2 * 2 )
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: ldfdyn.F90 12822 2020-04-28 09:10:38Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE ldf_dyn_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ldf_dyn_init  ***
-      !!                   
-      !! ** Purpose :   set the horizontal ocean dynamics physics
-      !!
-      !! ** Method  :   the eddy viscosity coef. specification depends on:
-      !!              - the operator:
-      !!             ln_dynldf_lap = T     laplacian operator
-      !!             ln_dynldf_blp = T   bilaplacian operator
-      !!              - the parameter nn_ahm_ijk_t:
-      !!    nn_ahm_ijk_t  =  0 => = constant
-      !!                  = 10 => = F(z) :     = constant with a reduction of 1/4 with depth 
-      !!                  =-20 => = F(i,j)     = shape read in 'eddy_viscosity.nc' file
-      !!                  = 20    = F(i,j)     = F(e1,e2) or F(e1^3,e2^3) (lap or bilap case)
-      !!                  =-30 => = F(i,j,k)   = shape read in 'eddy_viscosity.nc'  file
-      !!                  = 30    = F(i,j,k)   = 2D (case 20) + decrease with depth (case 10)
-      !!                  = 31    = F(i,j,k,t) = F(local velocity) (  |u|e  /12   laplacian operator
-      !!                                                           or |u|e^3/12 bilaplacian operator )
-      !!                  = 32    = F(i,j,k,t) = F(local deformation rate and gridscale) (D and L) (Smagorinsky)  
-      !!                                                           (   L^2|D|      laplacian operator
-      !!                                                           or  L^4|D|/8  bilaplacian operator )
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, jk                     ! dummy loop indices
-      INTEGER  ::   ioptio, ierr, inum, ios, inn   ! local integer
-      REAL(wp) ::   zah0, zah_max, zUfac           ! local scalar
-      REAL(wp) ::   zsum                           ! local scalar
-      CHARACTER(len=5) ::   cl_Units               ! units (m2/s or m4/s)
-      !!
-      NAMELIST/namdyn_ldf/ ln_dynldf_OFF, ln_dynldf_lap, ln_dynldf_blp,   &   ! type of operator
-         &                 ln_dynldf_lev, ln_dynldf_hor, ln_dynldf_iso,   &   ! acting direction of the operator
-         &                 nn_ahm_ijk_t , rn_Uv    , rn_Lv,   rn_ahm_b,   &   ! lateral eddy coefficient
-         &                 rn_csmc      , rn_minfac    , rn_maxfac            ! Smagorinsky settings
-      !!----------------------------------------------------------------------
-      !
-      READ  ( numnam_ref, namdyn_ldf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namdyn_ldf in reference namelist' )
-
-      READ  ( numnam_cfg, namdyn_ldf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namdyn_ldf in configuration namelist' )
-      IF(lwm) WRITE ( numond, namdyn_ldf )
-
-      IF(lwp) THEN                      ! Parameter print
-         WRITE(numout,*)
-         WRITE(numout,*) 'ldf_dyn : lateral momentum physics'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '   Namelist namdyn_ldf : set lateral mixing parameters'
-         !
-         WRITE(numout,*) '      type :'
-         WRITE(numout,*) '         no explicit diffusion                ln_dynldf_OFF = ', ln_dynldf_OFF
-         WRITE(numout,*) '         laplacian operator                   ln_dynldf_lap = ', ln_dynldf_lap
-         WRITE(numout,*) '         bilaplacian operator                 ln_dynldf_blp = ', ln_dynldf_blp
-         !
-         WRITE(numout,*) '      direction of action :'
-         WRITE(numout,*) '         iso-level                            ln_dynldf_lev = ', ln_dynldf_lev
-         WRITE(numout,*) '         horizontal (geopotential)            ln_dynldf_hor = ', ln_dynldf_hor
-         WRITE(numout,*) '         iso-neutral                          ln_dynldf_iso = ', ln_dynldf_iso
-         !
-         WRITE(numout,*) '      coefficients :'
-         WRITE(numout,*) '         type of time-space variation         nn_ahm_ijk_t  = ', nn_ahm_ijk_t
-         WRITE(numout,*) '         lateral viscous velocity  (if cst)      rn_Uv      = ', rn_Uv, ' m/s'
-         WRITE(numout,*) '         lateral viscous length    (if cst)      rn_Lv      = ', rn_Lv, ' m'
-         WRITE(numout,*) '         background viscosity (iso-lap case)     rn_ahm_b   = ', rn_ahm_b, ' m2/s'
-         !
-         WRITE(numout,*) '      Smagorinsky settings (nn_ahm_ijk_t  = 32) :'
-         WRITE(numout,*) '         Smagorinsky coefficient              rn_csmc       = ', rn_csmc
-         WRITE(numout,*) '         factor multiplier for eddy visc.'
-         WRITE(numout,*) '            lower limit (default 1.0)         rn_minfac    = ', rn_minfac
-         WRITE(numout,*) '            upper limit (default 1.0)         rn_maxfac    = ', rn_maxfac
-      ENDIF
-
-      !
-      !           !==  type of lateral operator used  ==!   (set nldf_dyn)
-      !           !=====================================!
-      !
-      nldf_dyn = np_ERROR
-      ioptio = 0
-      IF( ln_dynldf_OFF ) THEN   ;   nldf_dyn = np_no_ldf   ;   ioptio = ioptio + 1   ;   ENDIF
-      IF( ln_dynldf_lap ) THEN   ;                              ioptio = ioptio + 1   ;   ENDIF
-      IF( ln_dynldf_blp ) THEN   ;                              ioptio = ioptio + 1   ;   ENDIF
-      IF( ioptio /= 1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 operator options (NONE/lap/blp)' )
-      !
-      IF(.NOT.ln_dynldf_OFF ) THEN     !==  direction ==>> type of operator  ==!
-         ioptio = 0
-         IF( ln_dynldf_lev )   ioptio = ioptio + 1
-         IF( ln_dynldf_hor )   ioptio = ioptio + 1
-         IF( ln_dynldf_iso )   ioptio = ioptio + 1
-         IF( ioptio /= 1   )   CALL ctl_stop( 'dyn_ldf_init: use ONE of the 3 direction options (level/hor/iso)' )
-         !
-         !                             ! Set nldf_dyn, the type of lateral diffusion, from ln_dynldf_... logicals
-         ierr = 0
-         IF( ln_dynldf_lap ) THEN         ! laplacian operator
-            IF( ln_zco ) THEN                   ! z-coordinate
-               IF ( ln_dynldf_lev )   nldf_dyn = np_lap     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_hor )   nldf_dyn = np_lap     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_iso )   nldf_dyn = np_lap_i   ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_zps ) THEN                   ! z-coordinate with partial step
-               IF ( ln_dynldf_lev )   nldf_dyn = np_lap     ! iso-level              (no rotation)
-               IF ( ln_dynldf_hor )   nldf_dyn = np_lap     ! iso-level              (no rotation)
-               IF ( ln_dynldf_iso )   nldf_dyn = np_lap_i   ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_sco ) THEN                   ! s-coordinate
-               IF ( ln_dynldf_lev )   nldf_dyn = np_lap     ! iso-level = horizontal (no rotation)
-               IF ( ln_dynldf_hor )   nldf_dyn = np_lap_i   ! horizontal             (   rotation)
-               IF ( ln_dynldf_iso )   nldf_dyn = np_lap_i   ! iso-neutral            (   rotation)
-            ENDIF
-         ENDIF
-         !
-         IF( ln_dynldf_blp ) THEN         ! bilaplacian operator
-            IF( ln_zco ) THEN                   ! z-coordinate
-               IF( ln_dynldf_lev )   nldf_dyn = np_blp   ! iso-level = horizontal (no rotation)
-               IF( ln_dynldf_hor )   nldf_dyn = np_blp   ! iso-level = horizontal (no rotation)
-               IF( ln_dynldf_iso )   ierr = 2            ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_zps ) THEN                   ! z-coordinate with partial step
-               IF( ln_dynldf_lev )   nldf_dyn = np_blp   ! iso-level              (no rotation)
-               IF( ln_dynldf_hor )   nldf_dyn = np_blp   ! iso-level              (no rotation)
-               IF( ln_dynldf_iso )   ierr = 2            ! iso-neutral            (   rotation)
-            ENDIF
-            IF( ln_sco ) THEN                   ! s-coordinate
-               IF( ln_dynldf_lev )   nldf_dyn = np_blp   ! iso-level              (no rotation)
-               IF( ln_dynldf_hor )   ierr = 2            ! horizontal             (   rotation)
-               IF( ln_dynldf_iso )   ierr = 2            ! iso-neutral            (   rotation)
-            ENDIF
-         ENDIF
-         !
-         IF( ierr == 2 )   CALL ctl_stop( 'rotated bi-laplacian operator does not exist' )
-         !
-         IF( nldf_dyn == np_lap_i )   l_ldfslp = .TRUE.  ! rotation require the computation of the slopes
-         !
-      ENDIF
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         SELECT CASE( nldf_dyn )
-         CASE( np_no_ldf )   ;   WRITE(numout,*) '   ==>>>   NO lateral viscosity'
-         CASE( np_lap    )   ;   WRITE(numout,*) '   ==>>>   iso-level laplacian operator'
-         CASE( np_lap_i  )   ;   WRITE(numout,*) '   ==>>>   rotated laplacian operator with iso-level background'
-         CASE( np_blp    )   ;   WRITE(numout,*) '   ==>>>   iso-level bi-laplacian operator'
-         END SELECT
-         WRITE(numout,*)
-      ENDIF
-      
-      !
-      !           !==  Space/time variation of eddy coefficients  ==!
-      !           !=================================================!
-      !
-      l_ldfdyn_time = .FALSE.                ! no time variation except in case defined below
-      !
-      IF( ln_dynldf_OFF ) THEN
-         IF(lwp) WRITE(numout,*) '   ==>>>   No viscous operator selected. ahmt and ahmf are not allocated'
-         RETURN
-         !
-      ELSE                                   !==  a lateral diffusion operator is used  ==!
-         !
-         !                                         ! allocate the ahm arrays
-         ALLOCATE( ahmt(jpi,jpj,jpk) , ahmf(jpi,jpj,jpk) , STAT=ierr )
-         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'ldf_dyn_init: failed to allocate arrays')
-         !
-         ahmt(:,:,:) = 0._wp                       ! init to 0 needed 
-         ahmf(:,:,:) = 0._wp
-         !
-         !                                         ! value of lap/blp eddy mixing coef.
-         IF(     ln_dynldf_lap ) THEN   ;   zUfac = r1_2 *rn_Uv   ;   inn = 1   ;   cl_Units = ' m2/s'   !   laplacian
-         ELSEIF( ln_dynldf_blp ) THEN   ;   zUfac = r1_12*rn_Uv   ;   inn = 3   ;   cl_Units = ' m4/s'   ! bilaplacian
-         ENDIF
-         zah0    = zUfac *    rn_Lv**inn              ! mixing coefficient
-         zah_max = zUfac * (ra*rad)**inn              ! maximum reachable coefficient (value at the Equator)
-         !
-         SELECT CASE(  nn_ahm_ijk_t  )             !* Specification of space-time variations of ahmt, ahmf
-         !
-         CASE(   0  )      !==  constant  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity. = constant = ', zah0, cl_Units
-            ahmt(:,:,1:jpkm1) = zah0
-            ahmf(:,:,1:jpkm1) = zah0
-            !
-         CASE(  10  )      !==  fixed profile  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( depth )'
-            IF(lwp) WRITE(numout,*) '           surface viscous coef. = constant = ', zah0, cl_Units
-            ahmt(:,:,1) = zah0                        ! constant surface value
-            ahmf(:,:,1) = zah0
-            CALL ldf_c1d( 'DYN', ahmt(:,:,1), ahmf(:,:,1), ahmt, ahmf )
-            !
-         CASE ( -20 )      !== fixed horizontal shape read in file  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F(i,j) read in eddy_viscosity.nc file'
-            CALL iom_open( 'eddy_viscosity_2D.nc', inum )
-            CALL iom_get ( inum, jpdom_data, 'ahmt_2d', ahmt(:,:,1) )
-            CALL iom_get ( inum, jpdom_data, 'ahmf_2d', ahmf(:,:,1) )
-            CALL iom_close( inum )
-            DO jk = 2, jpkm1
-               ahmt(:,:,jk) = ahmt(:,:,1)
-               ahmf(:,:,jk) = ahmf(:,:,1)
-            END DO
-            !
-         CASE(  20  )      !== fixed horizontal shape  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( e1, e2 ) or F( e1^3, e2^3 ) (lap. or blp. case)'
-            IF(lwp) WRITE(numout,*) '           using a fixed viscous velocity = ', rn_Uv  ,' m/s   and   Lv = Max(e1,e2)'
-            IF(lwp) WRITE(numout,*) '           maximum reachable coefficient (at the Equator) = ', zah_max, cl_Units, '  for e1=1°)'
-            CALL ldf_c2d( 'DYN', zUfac      , inn        , ahmt, ahmf )         ! surface value proportional to scale factor^inn
-            !
-         CASE( -30  )      !== fixed 3D shape read in file  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F(i,j,k) read in eddy_viscosity_3D.nc file'
-            CALL iom_open( 'eddy_viscosity_3D.nc', inum )
-            CALL iom_get ( inum, jpdom_data, 'ahmt_3d', ahmt )
-            CALL iom_get ( inum, jpdom_data, 'ahmf_3d', ahmf )
-            CALL iom_close( inum )
-            !
-         CASE(  30  )       !==  fixed 3D shape  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( latitude, longitude, depth )'
-            IF(lwp) WRITE(numout,*) '           using a fixed viscous velocity = ', rn_Uv  ,' m/s   and   Ld = Max(e1,e2)'
-            IF(lwp) WRITE(numout,*) '           maximum reachable coefficient (at the Equator) = ', zah_max, cl_Units, '  for e1=1°)'
-            CALL ldf_c2d( 'DYN', zUfac      , inn        , ahmt, ahmf )         ! surface value proportional to scale factor^inn
-            CALL ldf_c1d( 'DYN', ahmt(:,:,1), ahmf(:,:,1), ahmt, ahmf )  ! reduction with depth
-            !
-         CASE(  31  )       !==  time varying 3D field  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( latitude, longitude, depth , time )'
-            IF(lwp) WRITE(numout,*) '           proportional to the local velocity : 1/2 |u|e (lap) or 1/12 |u|e^3 (blp)'
-            !
-            l_ldfdyn_time = .TRUE.     ! will be calculated by call to ldf_dyn routine in step.F90
-            !
-         CASE(  32  )       !==  time varying 3D field  ==!
-            IF(lwp) WRITE(numout,*) '   ==>>>   eddy viscosity = F( latitude, longitude, depth , time )'
-            IF(lwp) WRITE(numout,*) '           proportional to the local deformation rate and gridscale (Smagorinsky)'
-            !
-            l_ldfdyn_time = .TRUE.     ! will be calculated by call to ldf_dyn routine in step.F90
-            !
-            !                          ! allocate arrays used in ldf_dyn. 
-            ALLOCATE( dtensq(jpi,jpj,jpk) , dshesq(jpi,jpj,jpk) , esqt(jpi,jpj) , esqf(jpi,jpj) , STAT=ierr )
-            IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'ldf_dyn_init: failed to allocate Smagorinsky arrays')
-            !
-            DO_2D( 1, 1, 1, 1 )
-               esqt(ji,jj) = ( 2._wp * e1e2t(ji,jj) / ( e1t(ji,jj) + e2t(ji,jj) ) )**2 
-               esqf(ji,jj) = ( 2._wp * e1e2f(ji,jj) / ( e1f(ji,jj) + e2f(ji,jj) ) )**2 
-            END_2D
-            !
-         CASE DEFAULT
-            CALL ctl_stop('ldf_dyn_init: wrong choice for nn_ahm_ijk_t, the type of space-time variation of ahm')
-         END SELECT
-         !
-         IF( .NOT.l_ldfdyn_time ) THEN             !* No time variation 
-            IF(     ln_dynldf_lap ) THEN                 !   laplacian operator (mask only)
-               ahmt(:,:,1:jpkm1) =       ahmt(:,:,1:jpkm1)   * tmask(:,:,1:jpkm1)
-               WRITE(numout,*) ' ahmt tmask '
-!! mask tension at the coast (equivalent of ghostpoints at T)
-!              DO jk = 1, jpk
-!                 DO jj = 1, jpjm1
-!                    DO ji = 1, jpim1      ! NO vector opt.
-!                       ! si sum(fmask)==3 = mouillé (on touche pas)
-!                       ! si sum = 2 alors on met a 0 zsum = fmask + fmask + fmask,.. et si zsum < 2 -> 0 sinon = 1
-!                       zsum =   fmask(ji,jj  ,jk) + fmask(ji+1,jj  ,jk)   &
-!                          &   + fmask(ji,jj+1,jk) + fmask(ji+1,jj+1,jk)
-!                       IF ( zsum < 2._wp )   ahmt(ji,jj,jk) = 0
-!                       !
-!                       !ahmt(ji,jj,jk) = ahmt(ji,jj,jk) * fmask(ji,jj  ,jk) * fmask(ji+1,jj  ,jk)   &
-!                       !   &                            * fmask(ji,jj+1,jk) * fmask(ji+1,jj+1,jk)
-!                    END DO
-!                 END DO
-!              END DO
-!              ahmt(jpi,:,1:jpkm1) =  0._wp
-!              ahmt(:,jpj,1:jpkm1) =  0._wp
-!              WRITE(numout,*) '   an45 ahmt x0'
-
-               ahmf(:,:,1:jpkm1) =       ahmf(:,:,1:jpkm1)   * fmask(:,:,1:jpkm1)
-               WRITE(numout,*) ' ahmf fmask '
-!!an apply no slip at the coast (ssfmask = 1 within the domain and at the coast contrary to fmask in free slip)
-!               DO jk = 1, jpkm1
-!                  ahmf(:,:,jk) =    ahmf(:,:,jk) * ( 2._wp * ssfmask(:,:) - fmask(:,:,jk) )
-!               END DO
-!               WRITE(numout,*) '   an45 ahmf x2'
-
-            ELSEIF( ln_dynldf_blp ) THEN                 ! bilaplacian operator (square root + mask)
-               ahmt(:,:,1:jpkm1) = SQRT( ahmt(:,:,1:jpkm1) ) * tmask(:,:,1:jpkm1)
-               ahmf(:,:,1:jpkm1) = SQRT( ahmf(:,:,1:jpkm1) ) * fmask(:,:,1:jpkm1)
-            ENDIF
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE ldf_dyn_init
-
-
-   SUBROUTINE ldf_dyn( kt, Kbb )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ldf_dyn  ***
-      !! 
-      !! ** Purpose :   update at kt the momentum lateral mixing coeff. (ahmt and ahmf)
-      !!
-      !! ** Method  :   time varying eddy viscosity coefficients:
-      !!
-      !!    nn_ahm_ijk_t = 31    ahmt, ahmf = F(i,j,k,t) = F(local velocity) 
-      !!                         ( |u|e /12  or  |u|e^3/12 for laplacian or bilaplacian operator )
-      !!
-      !!    nn_ahm_ijk_t = 32    ahmt, ahmf = F(i,j,k,t) = F(local deformation rate and gridscale) (D and L) (Smagorinsky)  
-      !!                         ( L^2|D|    or  L^4|D|/8  for laplacian or bilaplacian operator )
-      !!
-      !! ** note    :    in BLP cases the sqrt of the eddy coef is returned, since bilaplacian is en re-entrant laplacian
-      !! ** action  :    ahmt, ahmf   updated at each time step
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! time step index
-      INTEGER, INTENT(in) ::   Kbb  ! ocean time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zu2pv2_ij_p1, zu2pv2_ij, zu2pv2_ij_m1, zemax   ! local scalar (option 31)
-      REAL(wp) ::   zcmsmag, zstabf_lo, zstabf_up, zdelta, zdb     ! local scalar (option 32)
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_timing )   CALL timing_start('ldf_dyn')
-      !
-      SELECT CASE(  nn_ahm_ijk_t  )       !== Eddy vicosity coefficients ==!
-      !
-      CASE(  31  )       !==  time varying 3D field  ==!   = F( local velocity )
-         !
-         IF( ln_dynldf_lap   ) THEN        ! laplacian operator : |u| e /12 = |u/144| e
-            DO jk = 1, jpkm1
-               DO_2D( 0, 0, 0, 0 )
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk,Kbb) * uu(ji  ,jj  ,jk,Kbb) + vv(ji  ,jj  ,jk,Kbb) * vv(ji  ,jj  ,jk,Kbb)
-                  zu2pv2_ij_m1 = uu(ji-1,jj  ,jk,Kbb) * uu(ji-1,jj  ,jk,Kbb) + vv(ji  ,jj-1,jk,Kbb) * vv(ji  ,jj-1,jk,Kbb)
-                  zemax = MAX( e1t(ji,jj) , e2t(ji,jj) )
-                  ahmt(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * r1_288 ) * zemax * tmask(ji,jj,jk)      ! 288= 12*12 * 2
-               END_2D
-               DO_2D( 1, 0, 1, 0 )
-                  zu2pv2_ij_p1 = uu(ji  ,jj+1,jk, Kbb) * uu(ji  ,jj+1,jk, Kbb) + vv(ji+1,jj  ,jk, Kbb) * vv(ji+1,jj  ,jk, Kbb)
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk, Kbb) * uu(ji  ,jj  ,jk, Kbb) + vv(ji  ,jj  ,jk, Kbb) * vv(ji  ,jj  ,jk, Kbb)
-                  zemax = MAX( e1f(ji,jj) , e2f(ji,jj) )
-                  ahmf(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * r1_288 ) * zemax * fmask(ji,jj,jk)      ! 288= 12*12 * 2
-               END_2D
-            END DO
-         ELSEIF( ln_dynldf_blp ) THEN      ! bilaplacian operator : sqrt( |u| e^3 /12 ) = sqrt( |u/144| e ) * e
-            DO jk = 1, jpkm1
-               DO_2D( 0, 0, 0, 0 )
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk,Kbb) * uu(ji  ,jj  ,jk,Kbb) + vv(ji  ,jj  ,jk,Kbb) * vv(ji  ,jj  ,jk,Kbb)
-                  zu2pv2_ij_m1 = uu(ji-1,jj  ,jk,Kbb) * uu(ji-1,jj  ,jk,Kbb) + vv(ji  ,jj-1,jk,Kbb) * vv(ji  ,jj-1,jk,Kbb)
-                  zemax = MAX( e1t(ji,jj) , e2t(ji,jj) )
-                  ahmt(ji,jj,jk) = SQRT(  SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * r1_288 ) * zemax  ) * zemax * tmask(ji,jj,jk)
-               END_2D
-               DO_2D( 1, 0, 1, 0 )
-                  zu2pv2_ij_p1 = uu(ji  ,jj+1,jk, Kbb) * uu(ji  ,jj+1,jk, Kbb) + vv(ji+1,jj  ,jk, Kbb) * vv(ji+1,jj  ,jk, Kbb)
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk, Kbb) * uu(ji  ,jj  ,jk, Kbb) + vv(ji  ,jj  ,jk, Kbb) * vv(ji  ,jj  ,jk, Kbb)
-                  zemax = MAX( e1f(ji,jj) , e2f(ji,jj) )
-                  ahmf(ji,jj,jk) = SQRT(  SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * r1_288 ) * zemax  ) * zemax * fmask(ji,jj,jk)
-               END_2D
-            END DO
-         ENDIF
-         !
-         CALL lbc_lnk_multi( 'ldfdyn', ahmt, 'T', 1.,  ahmf, 'F', 1. )
-         !
-         !
-      CASE(  32  )       !==  time varying 3D field  ==!   = F( local deformation rate and gridscale ) (Smagorinsky)
-         !
-         IF( ln_dynldf_lap .OR. ln_dynldf_blp  ) THEN        ! laplacian operator : (C_smag/pi)^2 L^2 |D|
-            !
-            zcmsmag   = (rn_csmc/rpi)**2                                            ! (C_smag/pi)^2
-            zstabf_lo = rn_minfac * rn_minfac / ( 2._wp * 12._wp * 12._wp * zcmsmag ) ! lower limit stability factor scaling
-            zstabf_up = rn_maxfac / ( 4._wp * zcmsmag * 2._wp * rn_Dt )               ! upper limit stability factor scaling
-            IF( ln_dynldf_blp ) zstabf_lo = ( 16._wp / 9._wp ) * zstabf_lo          ! provide |U|L^3/12 lower limit instead 
-            !                                                                       ! of |U|L^3/16 in blp case
-            DO jk = 1, jpkm1
-               !
-               DO_2D( 0, 0, 0, 0 )
-                  zdb =    ( uu(ji,jj,jk,Kbb) * r1_e2u(ji,jj) -  uu(ji-1,jj,jk,Kbb) * r1_e2u(ji-1,jj) )  &
-                       &                      * r1_e1t(ji,jj) * e2t(ji,jj)                           &
-                       & - ( vv(ji,jj,jk,Kbb) * r1_e1v(ji,jj) -  vv(ji,jj-1,jk,Kbb) * r1_e1v(ji,jj-1) )  &
-                       &                      * r1_e2t(ji,jj) * e1t(ji,jj)
-                  dtensq(ji,jj,jk) = zdb * zdb * tmask(ji,jj,jk)
-               END_2D
-               !
-               DO_2D( 1, 0, 1, 0 )
-                  zdb =   (  uu(ji,jj+1,jk,Kbb) * r1_e1u(ji,jj+1) -  uu(ji,jj,jk,Kbb) * r1_e1u(ji,jj) )  &
-                       &                        * r1_e2f(ji,jj)   * e1f(ji,jj)                       &
-                       & + ( vv(ji+1,jj,jk,Kbb) * r1_e2v(ji+1,jj) -  vv(ji,jj,jk,Kbb) * r1_e2v(ji,jj) )  &
-                       &                        * r1_e1f(ji,jj)   * e2f(ji,jj)
-                  dshesq(ji,jj,jk) = zdb * zdb * fmask(ji,jj,jk)
-               END_2D
-               !
-            END DO
-            !
-            CALL lbc_lnk_multi( 'ldfdyn', dtensq, 'T', 1. )  ! lbc_lnk on dshesq not needed
-            !
-            DO jk = 1, jpkm1
-              !
-               DO_2D( 0, 0, 0, 0 )
-                  !
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk,Kbb) * uu(ji  ,jj  ,jk,Kbb) + vv(ji  ,jj  ,jk,Kbb) * vv(ji  ,jj  ,jk,Kbb)
-                  zu2pv2_ij_m1 = uu(ji-1,jj  ,jk,Kbb) * uu(ji-1,jj  ,jk,Kbb) + vv(ji  ,jj-1,jk,Kbb) * vv(ji  ,jj-1,jk,Kbb)
-                  !
-                  zdelta         = zcmsmag * esqt(ji,jj)                                        ! L^2 * (C_smag/pi)^2
-                  ahmt(ji,jj,jk) = zdelta * SQRT(          dtensq(ji  ,jj,jk) +                         &
-                     &                            r1_4 * ( dshesq(ji  ,jj,jk) + dshesq(ji  ,jj-1,jk) +  &
-                     &                                     dshesq(ji-1,jj,jk) + dshesq(ji-1,jj-1,jk) ) )
-                  ahmt(ji,jj,jk) = MAX( ahmt(ji,jj,jk), SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * zdelta * zstabf_lo ) ) ! Impose lower limit == minfac  * |U|L/2
-                  ahmt(ji,jj,jk) = MIN( ahmt(ji,jj,jk),                                    zdelta * zstabf_up )   ! Impose upper limit == maxfac  * L^2/(4*2dt)
-                  !
-               END_2D
-               !
-               DO_2D( 1, 0, 1, 0 )
-                  !
-                  zu2pv2_ij_p1 = uu(ji  ,jj+1,jk, kbb) * uu(ji  ,jj+1,jk, kbb) + vv(ji+1,jj  ,jk, kbb) * vv(ji+1,jj  ,jk, kbb)
-                  zu2pv2_ij    = uu(ji  ,jj  ,jk, kbb) * uu(ji  ,jj  ,jk, kbb) + vv(ji  ,jj  ,jk, kbb) * vv(ji  ,jj  ,jk, kbb)
-                  !
-                  zdelta         = zcmsmag * esqf(ji,jj)                                        ! L^2 * (C_smag/pi)^2
-                  ahmf(ji,jj,jk) = zdelta * SQRT(          dshesq(ji  ,jj,jk) +                         &
-                     &                            r1_4 * ( dtensq(ji  ,jj,jk) + dtensq(ji  ,jj+1,jk) +  &
-                     &                                     dtensq(ji+1,jj,jk) + dtensq(ji+1,jj+1,jk) ) )
-                  ahmf(ji,jj,jk) = MAX( ahmf(ji,jj,jk), SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * zdelta * zstabf_lo ) ) ! Impose lower limit == minfac  * |U|L/2
-                  ahmf(ji,jj,jk) = MIN( ahmf(ji,jj,jk),                                    zdelta * zstabf_up )   ! Impose upper limit == maxfac  * L^2/(4*2dt)
-                  !
-               END_2D
-               !
-            END DO
-            !
-         ENDIF
-         !
-         IF( ln_dynldf_blp ) THEN      ! bilaplacian operator : sqrt( (C_smag/pi)^2 L^4 |D|/8)
-            !                          !                      = sqrt( A_lap_smag L^2/8 )
-            !                          ! stability limits already applied to laplacian values
-            !                          ! effective default limits are 1/12 |U|L^3 < B_hm < 1//(32*2dt) L^4
-            DO jk = 1, jpkm1
-               DO_2D( 0, 0, 0, 0 )
-                  ahmt(ji,jj,jk) = SQRT( r1_8 * esqt(ji,jj) * ahmt(ji,jj,jk) )
-               END_2D
-               DO_2D( 1, 0, 1, 0 )
-                  ahmf(ji,jj,jk) = SQRT( r1_8 * esqf(ji,jj) * ahmf(ji,jj,jk) )
-               END_2D
-            END DO
-            !
-         ENDIF
-         !
-         CALL lbc_lnk_multi( 'ldfdyn', ahmt, 'T', 1. , ahmf, 'F', 1. )
-         !
-      END SELECT
-      !
-      CALL iom_put( "ahmt_2d", ahmt(:,:,1) )   ! surface u-eddy diffusivity coeff.
-      CALL iom_put( "ahmf_2d", ahmf(:,:,1) )   ! surface v-eddy diffusivity coeff.
-      CALL iom_put( "ahmt_3d", ahmt(:,:,:) )   ! 3D      u-eddy diffusivity coeff.
-      CALL iom_put( "ahmf_3d", ahmf(:,:,:) )   ! 3D      v-eddy diffusivity coeff.
-      !
-      IF( ln_timing )   CALL timing_stop('ldf_dyn')
-      !
-   END SUBROUTINE ldf_dyn
-
-   !!======================================================================
-END MODULE ldfdyn
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/nemogcm.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/nemogcm.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/nemogcm.F90	(revision 14062)
@@ -4,32 +4,6 @@
    !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
    !!======================================================================
-   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
-   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
-   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
-   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
-   !!             -   ! 1992-06  (L.Terray)  coupling implementation
-   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
-   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
-   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
-   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
-   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  sea-ice model
-   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
-   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
-   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
-   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
-   !!             -   ! 2004-08  (C. Talandier) New trends organization
-   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
-   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
-   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
-   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
-   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
-   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
-   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
-   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
-   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
-   !!             -   ! 2011-11  (C. Harris) decomposition changes for running with CICE
-   !!            3.6  ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening 
-   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
-   !!            4.0  ! 2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface
+   !! History :  4.0  !  2020-05  (A. Nasser, G. Madec)  Original code from 4.0.2
+   !!             -   !  2020-10  (S. Techene, G. Madec)  cleanning
    !!----------------------------------------------------------------------
 
@@ -42,61 +16,22 @@
    !!----------------------------------------------------------------------
    USE step_oce       ! module used in the ocean time stepping module (step.F90)
+   !
    USE phycst         ! physical constant                  (par_cst routine)
    USE domain         ! domain initialization   (dom_init & dom_cfg routines)
-   USE closea         ! treatment of closed seas (for ln_closea)
    USE usrdef_nam     ! user defined configuration
-   USE tide_mod, ONLY : tide_init ! tidal components initialization   (tide_init routine)
-   USE bdy_oce,  ONLY : ln_bdy
    USE bdyini         ! open boundary cond. setting       (bdy_init routine)
    USE istate         ! initial state setting          (istate_init routine)
-   USE ldfdyn         ! lateral viscosity setting      (ldfdyn_init routine)
-   USE ldftra         ! lateral diffusivity setting    (ldftra_init routine)
-   USE trdini         ! dyn/tra trends initialization     (trd_init routine)
-   USE asminc         ! assimilation increments     
-   USE asmbkg         ! writing out state trajectory
-   USE diaptr         ! poleward transports           (dia_ptr_init routine)
-   USE diadct         ! sections transports           (dia_dct_init routine)
-   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
-   USE diacfl         ! CFL diagnostics               (dia_cfl_init routine)
-   USE diamlr         ! IOM context management for multiple-linear-regression analysis
+   USE trd_oce , ONLY : l_trddyn         ! dynamical trend logical
 #if defined key_RK3
-   USE stpRK3
-#elif defined key_qco
-   USE stpLF
+   USE stprk3         ! NEMO time-stepping               (stp_RK3   routine)
 #else
-   USE step           ! NEMO time-stepping                 (stp     routine)
-#endif
-   USE isfstp         ! ice shelf                     (isf_stp_init routine)
-   USE icbini         ! handle bergs, initialisation
-   USE icbstp         ! handle bergs, calving, themodynamics and transport
-   USE cpl_oasis3     ! OASIS3 coupling
-   USE c1d            ! 1D configuration
-   USE step_c1d       ! Time stepping loop for the 1D configuration
-   USE dyndmp         ! Momentum damping
-   USE stopar         ! Stochastic param.: ???
-   USE stopts         ! Stochastic param.: ???
-   USE diu_layers     ! diurnal bulk SST and coolskin
-   USE crsini         ! initialise grid coarsening utility
-   USE dia25h         ! 25h mean output
-   USE diadetide      ! Weights computation for daily detiding of model diagnostics
-   USE sbc_oce , ONLY : lk_oasis
-   USE wet_dry        ! Wetting and drying setting   (wad_init routine)
-#if defined key_top
-   USE trcini         ! passive tracer initialisation
-#endif
-#if defined key_nemocice_decomp
-   USE ice_domain_size, only: nx_global, ny_global
+   USE stpmlf         ! NEMO time-stepping               (stp_MLF   routine)
 #endif
    !
    USE lib_mpp        ! distributed memory computing
    USE mppini         ! shared/distributed memory setting (mpp_init routine)
-   USE lbcnfd  , ONLY : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges 
+   USE lbcnfd  , ONLY : isendto, nsndto  ! Setup of north fold exchanges 
    USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
-#if defined key_iomput
-   USE xios           ! xIOserver
-#endif
-#if defined key_agrif
-   USE agrif_all_update   ! Master Agrif update
-#endif
+   USE halo_mng       ! Halo manager
 
    IMPLICIT NONE
@@ -139,24 +74,15 @@
       !!----------------------------------------------------------------------
       !
-#if defined key_agrif
-      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
-#endif
       !                            !-----------------------!
       CALL nemo_init               !==  Initialisations  ==!
       !                            !-----------------------!
-      
-#if defined key_agrif
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
-      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA 
-# if defined key_top
-      CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
-# endif
-# if defined key_si3
-      CALL Agrif_Declare_Var_ice   !  "      "   "   "      "  Sea ice
-# endif
-#endif
       ! check that all process are still there... If some process have an error,
       ! they will never enter in step and other processes will wait until the end of the cpu time!
+      !
+      !                                 ! SWE case: only with key_qco
+#if ! defined key_qco  
+      CALL ctl_stop( 'nemo_gcm (SWE): shallow water model requires key_qco' )
+#endif
+      !
       CALL mpp_max( 'nemogcm', nstop )
 
@@ -174,5 +100,5 @@
       !
       DO WHILE( istp <= nitend .AND. nstop == 0 )
-
+         !
          ncom_stp = istp
          IF( ln_timing ) THEN
@@ -181,15 +107,14 @@
             IF ( istp ==         nitend ) elapsed_time = zstptiming - elapsed_time
          ENDIF
+         ! 
 #if defined key_RK3
          CALL stp_RK3    ( istp )
-#elif defined key_qco
-         CALL stp_LF     ( istp )
 #else
-         CALL stp        ( istp )
+         CALL stp_MLF     ( istp )
 #endif
          istp = istp + 1
-
+         !
          IF( lwp .AND. ln_timing )   WRITE(numtime,*) 'timing step ', istp-1, ' : ', MPI_Wtime() - zstptiming
-
+         !
       END DO
       !
@@ -232,7 +157,6 @@
       INTEGER ::   ios, ilocal_comm   ! local integers
       !!
-      NAMELIST/namctl/ sn_cfctl,  nn_print, nn_ictls, nn_ictle,             &
-         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
-         &             ln_timing, ln_diacfl
+      NAMELIST/namctl/ sn_cfctl, ln_timing, ln_diacfl, nn_isplt, nn_jsplt , nn_ictls,   &
+         &                                             nn_ictle, nn_jctls , nn_jctle
       NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
       !!----------------------------------------------------------------------
@@ -246,22 +170,8 @@
       !
 #if defined key_iomput
-      IF( Agrif_Root() ) THEN
-         IF( lk_oasis ) THEN
-            CALL cpl_init( "oceanx", ilocal_comm )                               ! nemo local communicator given by oasis
-            CALL xios_initialize( "not used"       , local_comm =ilocal_comm )   ! send nemo communicator to xios
-         ELSE
-            CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
-         ENDIF
-      ENDIF
+      CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
       CALL mpp_start( ilocal_comm )
 #else
-      IF( lk_oasis ) THEN
-         IF( Agrif_Root() ) THEN
-            CALL cpl_init( "oceanx", ilocal_comm )          ! nemo local communicator given by oasis
-         ENDIF
-         CALL mpp_start( ilocal_comm )
-      ELSE
-         CALL mpp_start( )
-      ENDIF
+      CALL mpp_start( )
 #endif
       !
@@ -292,20 +202,6 @@
       !
       ! finalize the definition of namctl variables
-      IF( sn_cfctl%l_allon ) THEN
-         ! Turn on all options.
-         CALL nemo_set_cfctl( sn_cfctl, .TRUE., .TRUE. )
-         ! Ensure all processors are active
-         sn_cfctl%procmin = 0 ; sn_cfctl%procmax = 1000000 ; sn_cfctl%procincr = 1
-      ELSEIF( sn_cfctl%l_config ) THEN
-         ! Activate finer control of report outputs
-         ! optionally switch off output from selected areas (note this only
-         ! applies to output which does not involve global communications)
-         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
-           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
-           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
-      ELSE
-         ! turn off all options.
-         CALL nemo_set_cfctl( sn_cfctl, .FALSE., .TRUE. )
-      ENDIF
+      IF( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax .OR. MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 )   &
+         &   CALL nemo_set_cfctl( sn_cfctl, .FALSE. )
       !
       lwp = (narea == 1) .OR. sn_cfctl%l_oceout    ! control of all listing output print
@@ -336,4 +232,12 @@
          WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
          WRITE(numout,*)
+         
+         ! Print the working precision to ocean.output
+         IF (wp == dp) THEN
+            WRITE(numout,*) "Working precision = double-precision"
+         ELSE
+            WRITE(numout,*) "Working precision = single-precision"
+         ENDIF
+         WRITE(numout,*)
          !
          WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
@@ -353,7 +257,7 @@
       !
       IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
-         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+         CALL domain_cfg ( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, jperio )
       ELSE                              ! user-defined namelist
-         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
+         CALL usr_def_nam( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, jperio )
       ENDIF
       !
@@ -365,10 +269,11 @@
       CALL mpp_init
 
+      CALL halo_mng_init()
       ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
       CALL nemo_alloc()
 
       ! Initialise time level indices
-      Nbb = 1; Nnn = 2; Naa = 3; Nrhs = Naa
-
+      Nbb = 1   ;   Nnn = 2   ;   Naa = 3   ;   Nrhs = Naa
+      
       !                             !-------------------------------!
       !                             !  NEMO general initialization  !
@@ -382,5 +287,13 @@
       !
                            CALL     phy_cst         ! Physical constants
-                           
+      !
+      !                                             ! SWE: Set rho0 and associated variables (eosbn2 not used)
+                           rho0        = 1026._wp                 !: volumic mass of reference     [kg/m3]
+                           rcp         = 3991.86795711963_wp      !: heat capacity     [J/K]
+                           rho0_rcp    = rho0 * rcp 
+                           r1_rho0     = 1._wp / rho0
+                           r1_rcp      = 1._wp / rcp
+                           r1_rho0_rcp = 1._wp / rho0_rcp 
+      !
                            CALL     dom_init( Nbb, Nnn, Naa ) ! Domain
 
@@ -391,8 +304,5 @@
 
       !                                      ! external forcing 
-                           CALL    tide_init                     ! tidal harmonics
-
                            CALL     sbc_init( Nbb, Nnn, Naa )    ! surface boundary conditions (including sea-ice)
-                           
 
       !                                      ! Ocean physics                                    
@@ -400,21 +310,13 @@
                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
                            
-                           
       !                                      ! Dynamics
                            CALL dyn_adv_init         ! advection (vector or flux form)
-
                            CALL dyn_vor_init         ! vorticity term including Coriolis
-
                            CALL dyn_ldf_init         ! lateral mixing
 
-                           CALL dyn_spg_init         ! surface pressure gradient
-
       !                                      ! Diagnostics
-                           CALL     flo_init( Nnn )    ! drifting Floats
-                           
       IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
-
-                           CALL     trd_init( Nnn )    ! Mixed-layer/Vorticity/Integral constraints trends
-
+      !                                         ! Trends diag: switched off
+                           l_trddyn = .FALSE.        ! No trend diagnostics
 
       IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
@@ -422,5 +324,4 @@
       IF( ln_timing    )   CALL timing_stop( 'nemo_init')
       !
-
    END SUBROUTINE nemo_init
 
@@ -440,7 +341,4 @@
          WRITE(numout,*) '~~~~~~~~'
          WRITE(numout,*) '   Namelist namctl'
-         WRITE(numout,*) '                              sn_cfctl%l_glochk  = ', sn_cfctl%l_glochk
-         WRITE(numout,*) '                              sn_cfctl%l_allon   = ', sn_cfctl%l_allon
-         WRITE(numout,*) '       finer control over o/p sn_cfctl%l_config  = ', sn_cfctl%l_config
          WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
          WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
@@ -454,23 +352,9 @@
          WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
          WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
-         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
-         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
-         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
-         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
-         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
-         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
-         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
          WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
          WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
       ENDIF
       !
-      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
-      nictls    = nn_ictls
-      nictle    = nn_ictle
-      njctls    = nn_jctls
-      njctle    = nn_jctle
-      isplt     = nn_isplt
-      jsplt     = nn_jsplt
-
+      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
       IF(lwp) THEN                  ! control print
          WRITE(numout,*)
@@ -482,44 +366,4 @@
          WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
          WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
-      ENDIF
-      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
-      !
-      !                             ! Parameter control
-      !
-      IF( sn_cfctl%l_prtctl .OR. sn_cfctl%l_prttrc ) THEN              ! sub-domain area indices for the control prints
-         IF( lk_mpp .AND. jpnij > 1 ) THEN
-            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
-         ELSE
-            IF( isplt == 1 .AND. jsplt == 1  ) THEN
-               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
-                  &           ' - the print control will be done over the whole domain' )
-            ENDIF
-            ijsplt = isplt * jsplt            ! total number of processors ijsplt
-         ENDIF
-         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
-         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
-         !
-         !                              ! indices used for the SUM control
-         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
-            lsp_area = .FALSE.
-         ELSE                                             ! print control done over a specific  area
-            lsp_area = .TRUE.
-            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
-               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
-               nictls = 1
-            ENDIF
-            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
-               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
-               nictle = jpiglo
-            ENDIF
-            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
-               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
-               njctls = 1
-            ENDIF
-            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
-               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
-               njctle = jpjglo
-            ENDIF
-         ENDIF
       ENDIF
       !
@@ -571,16 +415,12 @@
       USE diawri    , ONLY : dia_wri_alloc
       USE dom_oce   , ONLY : dom_oce_alloc
-      USE trc_oce   , ONLY : trc_oce_alloc
-      USE bdy_oce   , ONLY : bdy_oce_alloc
       !
       INTEGER :: ierr
       !!----------------------------------------------------------------------
       !
-      ierr =        oce_alloc    ()    ! ocean 
+      ierr =        oce_SWE_alloc()    ! ocean 
       ierr = ierr + dia_wri_alloc()
       ierr = ierr + dom_oce_alloc()    ! ocean domain
       ierr = ierr + zdf_oce_alloc()    ! ocean vertical physics
-      ierr = ierr + trc_oce_alloc()    ! shared TRC / TRA arrays
-      ierr = ierr + bdy_oce_alloc()    ! bdy masks (incl. initialization)
       !
       CALL mpp_sum( 'nemogcm', ierr )
@@ -590,25 +430,18 @@
 
    
-   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto, for_all )
+   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto )
       !!----------------------------------------------------------------------
       !!                     ***  ROUTINE nemo_set_cfctl  ***
       !!
       !! ** Purpose :   Set elements of the output control structure to setto.
-      !!                for_all should be .false. unless all areas are to be
-      !!                treated identically.
       !!
       !! ** Method  :   Note this routine can be used to switch on/off some
-      !!                types of output for selected areas but any output types
-      !!                that involve global communications (e.g. mpp_max, glob_sum)
-      !!                should be protected from selective switching by the
-      !!                for_all argument
-      !!----------------------------------------------------------------------
-      LOGICAL :: setto, for_all
-      TYPE(sn_ctl) :: sn_cfctl
-      !!----------------------------------------------------------------------
-      IF( for_all ) THEN
-         sn_cfctl%l_runstat = setto
-         sn_cfctl%l_trcstat = setto
-      ENDIF
+      !!                types of output for selected areas.
+      !!----------------------------------------------------------------------
+      TYPE(sn_ctl), INTENT(inout) :: sn_cfctl
+      LOGICAL     , INTENT(in   ) :: setto
+      !!----------------------------------------------------------------------
+      sn_cfctl%l_runstat = setto
+      sn_cfctl%l_trcstat = setto
       sn_cfctl%l_oceout  = setto
       sn_cfctl%l_layout  = setto
@@ -620,3 +453,2 @@
    !!======================================================================
 END MODULE nemogcm
-
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/phycst.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/phycst.F90	(revision 14059)
+++ 	(revision )
@@ -1,148 +1,0 @@
-MODULE phycst
-   !!======================================================================
-   !!                    ***  MODULE  phycst  ***
-   !!     Definition of of both ocean and ice parameters used in the code
-   !!=====================================================================
-   !! History :   OPA  !  1990-10  (C. Levy - G. Madec)  Original code
-   !!             8.1  !  1991-11  (G. Madec, M. Imbard)  cosmetic changes
-   !!   NEMO      1.0  !  2002-08  (G. Madec, C. Ethe)  F90, add ice constants
-   !!              -   !  2006-08  (G. Madec)  style 
-   !!             3.2  !  2006-08  (S. Masson, G. Madec)  suppress useless variables + style 
-   !!             3.4  !  2011-11  (C. Harris)  minor changes for CICE constants 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   phy_cst  : define and print physical constant and domain parameters
-   !!----------------------------------------------------------------------
-   USE par_oce          ! ocean parameters
-   USE in_out_manager   ! I/O manager 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   phy_cst     ! routine called by inipar.F90
-
-   REAL(wp), PUBLIC ::   rpi      = 3.141592653589793_wp             !: pi
-   REAL(wp), PUBLIC ::   rad      = 3.141592653589793_wp / 180._wp   !: conversion from degre into radian
-   REAL(wp), PUBLIC ::   rsmall   = 0.5 * EPSILON( 1.e0 )            !: smallest real computer value
-   
-   REAL(wp), PUBLIC ::   rday     = 24.*60.*60.      !: day                                [s]
-   REAL(wp), PUBLIC ::   rsiyea                      !: sideral year                       [s]
-   REAL(wp), PUBLIC ::   rsiday                      !: sideral day                        [s]
-   REAL(wp), PUBLIC ::   raamo    =  12._wp          !: number of months in one year
-   REAL(wp), PUBLIC ::   rjjhh    =  24._wp          !: number of hours in one day
-   REAL(wp), PUBLIC ::   rhhmm    =  60._wp          !: number of minutes in one hour
-   REAL(wp), PUBLIC ::   rmmss    =  60._wp          !: number of seconds in one minute
-   REAL(wp), PUBLIC ::   omega                       !: earth rotation parameter           [s-1]
-   REAL(wp), PUBLIC ::   ra       = 6371229._wp      !: earth radius                       [m]
-   REAL(wp), PUBLIC ::   grav     = 9.80665_wp       !: gravity                            [m/s2]   
-   REAL(wp), PUBLIC ::   rt0      = 273.15_wp        !: freezing point of fresh water [Kelvin]
-
-   REAL(wp), PUBLIC ::   rho0                        !: volumic mass of reference     [kg/m3]
-   REAL(wp), PUBLIC ::   r1_rho0                     !: = 1. / rho0                   [m3/kg]
-   REAL(wp), PUBLIC ::   rcp                         !: ocean specific heat           [J/Kelvin]
-   REAL(wp), PUBLIC ::   r1_rcp                      !: = 1. / rcp                    [Kelvin/J]
-   REAL(wp), PUBLIC ::   rho0_rcp                    !: = rho0 * rcp 
-   REAL(wp), PUBLIC ::   r1_rho0_rcp                 !: = 1. / ( rho0 * rcp )
-
-   REAL(wp), PUBLIC ::   emic     =    0.97_wp       !: emissivity of snow or ice (not used?)
-
-   REAL(wp), PUBLIC ::   sice     =    6.0_wp        !: salinity of ice (for pisces)          [psu]
-   REAL(wp), PUBLIC ::   soce     =   34.7_wp        !: salinity of sea (for pisces and isf)  [psu]
-   REAL(wp), PUBLIC ::   rLevap   =    2.5e+6_wp     !: latent heat of evaporation (water)
-   REAL(wp), PUBLIC ::   vkarmn   =    0.4_wp        !: von Karman constant
-   REAL(wp), PUBLIC ::   stefan   =    5.67e-8_wp    !: Stefan-Boltzmann constant 
-
-   REAL(wp), PUBLIC ::   rhos     =  330._wp         !: volumic mass of snow                                  [kg/m3]
-   REAL(wp), PUBLIC ::   rhoi     =  917._wp         !: volumic mass of sea ice                               [kg/m3]
-   REAL(wp), PUBLIC ::   rhow     = 1000._wp         !: volumic mass of freshwater in melt ponds              [kg/m3]
-   REAL(wp), PUBLIC ::   rcnd_i   =    2.034396_wp   !: thermal conductivity of fresh ice                     [W/m/K]
-   REAL(wp), PUBLIC ::   rcpi     = 2067.0_wp        !: specific heat of fresh ice                            [J/kg/K]
-   REAL(wp), PUBLIC ::   rLsub    =    2.834e+6_wp   !: pure ice latent heat of sublimation                   [J/kg]
-   REAL(wp), PUBLIC ::   rLfus    =    0.334e+6_wp   !: latent heat of fusion of fresh ice                    [J/kg]
-   REAL(wp), PUBLIC ::   rTmlt    =    0.054_wp      !: decrease of seawater meltpoint with salinity
-
-   REAL(wp), PUBLIC ::   r1_rhoi                     !: 1 / rhoi
-   REAL(wp), PUBLIC ::   r1_rhos                     !: 1 / rhos
-   REAL(wp), PUBLIC ::   r1_rcpi                     !: 1 / rcpi
-
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: phycst.F90 12614 2020-03-26 14:59:52Z gm $ 
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-   
-CONTAINS
-   
-   SUBROUTINE phy_cst
-      !!----------------------------------------------------------------------
-      !!                       ***  ROUTINE phy_cst  ***
-      !!
-      !! ** Purpose :   set and print the constants
-      !!----------------------------------------------------------------------
-
-      rsiyea = 365.25_wp * rday * 2._wp * rpi / 6.283076_wp
-      rsiday = rday / ( 1._wp + rday / rsiyea )
-#if defined key_cice
-      omega  = 7.292116e-05
-#else
-      omega  = 2._wp * rpi / rsiday 
-#endif
-
-      r1_rhoi = 1._wp / rhoi
-      r1_rhos = 1._wp / rhos
-      r1_rcpi = 1._wp / rcpi
-      !
-      rho0        = 1026._wp                 !: volumic mass of reference     [kg/m3]
-      rcp         = 3991.86795711963_wp      !: heat capacity     [J/K]
-      !
-      rho0_rcp    = rho0 * rcp 
-      r1_rho0     = 1._wp / rho0
-      r1_rcp      = 1._wp / rcp
-      r1_rho0_rcp = 1._wp / rho0_rcp 
-      !
-      IF(lwp) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'phy_cst : initialization of ocean parameters and constants'
-         WRITE(numout,*) '~~~~~~~'
-         WRITE(numout,*) '      mathematical constant                 rpi = ', rpi
-         WRITE(numout,*) '      day                                rday   = ', rday,   ' s'
-         WRITE(numout,*) '      sideral year                       rsiyea = ', rsiyea, ' s'
-         WRITE(numout,*) '      sideral day                        rsiday = ', rsiday, ' s'
-         WRITE(numout,*) '      omega                              omega  = ', omega,  ' s^-1'
-         WRITE(numout,*)
-         WRITE(numout,*) '      nb of months per year               raamo = ', raamo, ' months'
-         WRITE(numout,*) '      nb of hours per day                 rjjhh = ', rjjhh, ' hours'
-         WRITE(numout,*) '      nb of minutes per hour              rhhmm = ', rhhmm, ' mn'
-         WRITE(numout,*) '      nb of seconds per minute            rmmss = ', rmmss, ' s'
-         WRITE(numout,*)
-         WRITE(numout,*) '      earth radius                         ra   = ', ra   , ' m'
-         WRITE(numout,*) '      gravity                              grav = ', grav , ' m/s^2'
-         WRITE(numout,*)
-         WRITE(numout,*) '      freezing point of water              rt0  = ', rt0  , ' K'
-         WRITE(numout,*)
-         WRITE(numout,*) '   reference density and heat capacity now defined in eosbn2.f90'
-         WRITE(numout,*)
-         WRITE(numout,*) '      thermal conductivity of pure ice          = ', rcnd_i  , ' J/s/m/K'
-         WRITE(numout,*) '      thermal conductivity of snow is defined in a namelist '
-         WRITE(numout,*) '      fresh ice specific heat                   = ', rcpi    , ' J/kg/K'
-         WRITE(numout,*) '      latent heat of fusion of fresh ice / snow = ', rLfus   , ' J/kg'
-         WRITE(numout,*) '      latent heat of subl.  of fresh ice / snow = ', rLsub   , ' J/kg'
-         WRITE(numout,*) '      density of sea ice                        = ', rhoi    , ' kg/m^3'
-         WRITE(numout,*) '      density of snow                           = ', rhos    , ' kg/m^3'
-         WRITE(numout,*) '      density of freshwater (in melt ponds)     = ', rhow    , ' kg/m^3'
-         WRITE(numout,*) '      salinity of ice (for pisces)              = ', sice    , ' psu'
-         WRITE(numout,*) '      salinity of sea (for pisces and isf)      = ', soce    , ' psu'
-         WRITE(numout,*) '      latent heat of evaporation (water)        = ', rLevap  , ' J/m^3' 
-         WRITE(numout,*) '      von Karman constant                       = ', vkarmn 
-         WRITE(numout,*) '      Stefan-Boltzmann constant                 = ', stefan  , ' J/s/m^2/K^4'
-         WRITE(numout,*)
-         WRITE(numout,*) '      conversion: degre ==> radian          rad = ', rad
-         WRITE(numout,*)
-         WRITE(numout,*) '      smallest real computer value       rsmall = ', rsmall
-      ENDIF
-
-   END SUBROUTINE phy_cst
-
-   !!======================================================================
-END MODULE phycst
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/restart.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/restart.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/restart.F90	(revision 14062)
@@ -0,0 +1,279 @@
+MODULE restart
+   !!======================================================================
+   !!                     ***  MODULE  restart  ***
+   !! Ocean restart :  write the ocean restart file
+   !!======================================================================
+   !! History :  OPA  !  1999-11  (M. Imbard)  Original code
+   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form
+   !!            2.0  !  2006-07  (S. Masson)  use IOM for restart
+   !!            3.3  !  2010-04  (M. Leclair, G. Madec)  modified LF-RA
+   !!            - -  !  2010-10  (C. Ethe, G. Madec) TRC-TRA merge (T-S in 4D)
+   !!            3.7  !  2014-01  (G. Madec) suppression of curl and hdiv from the restart
+   !!             -   !  2014-12  (G. Madec) remove KPP scheme
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   rst_opn    : open the ocean restart file
+   !!   rst_write  : write the ocean restart file
+   !!   rst_read   : read the ocean restart file
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers 
+   USE dom_oce         ! ocean space and time domain
+   USE sbc_ice         ! only lk_si3 
+   USE phycst          ! physical constants
+!!st   USE eosbn2          ! equation of state            (eos bn2 routine)
+!!st   USE trdmxl_oce      ! ocean active mixed layer tracers trends variables
+   !
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O module
+   USE diu_bulk
+   USE lib_mpp         ! distribued memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   rst_opn         ! routine called by step module
+   PUBLIC   rst_write       ! routine called by step module
+   PUBLIC   rst_read        ! routine called by istate module
+   PUBLIC   rst_read_open   ! routine called in rst_read and (possibly) in dom_vvl_init
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: restart.F90 13427 2020-08-21 16:26:57Z techene $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE rst_opn( kt )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rst_opn  ***
+      !!                     
+      !! ** Purpose : + initialization (should be read in the namelist) of nitrst 
+      !!              + open the restart when we are one time step before nitrst
+      !!                   - restart header is defined when kt = nitrst-1
+      !!                   - restart data  are written when kt = nitrst
+      !!              + define lrst_oce to .TRUE. when we need to define or write the restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt     ! ocean time-step
+      !!
+      CHARACTER(LEN=20)   ::   clkt      ! ocean time-step deine as a character
+      CHARACTER(LEN=50)   ::   clname    ! ocean output restart file name
+      CHARACTER(lc)       ::   clpath    ! full path to ocean output restart file
+      CHARACTER(LEN=52)   ::   clpname   ! ocean output restart file name including prefix for AGRIF
+      CHARACTER(LEN=256)  ::   clinfo    ! info character
+      !!----------------------------------------------------------------------
+      !
+      IF( kt == nit000 ) THEN   ! default definitions
+         lrst_oce = .FALSE.   
+         IF( ln_rst_list ) THEN
+            nrst_lst = 1
+            nitrst = nn_stocklist( nrst_lst )
+         ELSE
+            nitrst = nitend
+         ENDIF
+      ENDIF
+      
+      IF( .NOT. ln_rst_list .AND. nn_stock == -1 )   RETURN   ! we will never do any restart
+
+      ! frequency-based restart dumping (nn_stock)
+      IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nn_stock ) == 0 ) THEN   
+         ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment
+         nitrst = kt + nn_stock - 1                  ! define the next value of nitrst for restart writing
+         IF( nitrst > nitend )   nitrst = nitend   ! make sure we write a restart at the end of the run
+      ENDIF
+      ! to get better performances with NetCDF format:
+      ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1)
+      ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1
+      IF( kt == nitrst - 1 .OR. nn_stock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN
+         IF( nitrst <= nitend .AND. nitrst > 0 ) THEN 
+            ! beware of the format used to write kt (default is i8.8, that should be large enough...)
+            IF( nitrst > 999999999 ) THEN   ;   WRITE(clkt, *       ) nitrst
+            ELSE                            ;   WRITE(clkt, '(i8.8)') nitrst
+            ENDIF
+            ! create the file
+            clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out)
+            clpath = TRIM(cn_ocerst_outdir)
+            IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
+            IF(lwp) THEN
+               WRITE(numout,*)
+               IF(.NOT.lwxios) THEN
+                  WRITE(numout,*) '             open ocean restart NetCDF file: ',TRIM(clpath)//TRIM(clname)
+                  IF ( snc4set%luse )      WRITE(numout,*) '             opened for NetCDF4 chunking and compression'
+                  IF( kt == nitrst - 1 ) THEN   ;   WRITE(numout,*) '             kt = nitrst - 1 = ', kt
+                  ELSE                          ;   WRITE(numout,*) '             kt = '             , kt
+                  ENDIF
+               ENDIF
+            ENDIF
+            !
+            IF(.NOT.lwxios) THEN
+               CALL iom_open( TRIM(clpath)//TRIM(clname), numrow, ldwrt = .TRUE. )
+            ELSE
+#if defined key_iomput
+               cwxios_context = "rstw_"//TRIM(ADJUSTL(clkt))
+               IF( TRIM(Agrif_CFixed()) == '0' ) THEN
+                  clpname = clname
+               ELSE
+                  clpname = TRIM(Agrif_CFixed())//"_"//clname   
+               ENDIF
+               CALL iom_init( cwxios_context, TRIM(clpath)//TRIM(clpname), .false. )
+               CALL xios_update_calendar(nitrst)
+               CALL iom_swap(      cxios_context          )
+#else
+               clinfo = 'Can not use XIOS in rst_opn'
+               CALL ctl_stop(TRIM(clinfo))
+#endif
+            ENDIF
+            lrst_oce = .TRUE.
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE rst_opn
+
+
+   SUBROUTINE rst_write( kt, Kbb, Kmm )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE rstwrite  ***
+      !!                     
+      !! ** Purpose :   Write restart fields in NetCDF format
+      !!
+      !! ** Method  :   Write in numrow when kt == nitrst in NetCDF
+      !!              file, save fields which are necessary for restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt         ! ocean time-step
+      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
+      !!----------------------------------------------------------------------
+      IF(lwxios) CALL iom_swap(      cwxios_context          )
+      CALL iom_rstput( kt, nitrst, numrow, 'rdt'    , rn_Dt       , ldxios = lwxios)   ! dynamics time step
+      CALL iom_delay_rst( 'WRITE', 'OCE', numrow )   ! save only ocean delayed global communication variables
+      
+      CALL iom_rstput( kt, nitrst, numrow, 'ub'  , uu(:,:,:,Kbb), ldxios = lwxios )     ! before fields
+      CALL iom_rstput( kt, nitrst, numrow, 'vb'  , vv(:,:,:,Kbb), ldxios = lwxios )
+      CALL iom_rstput( kt, nitrst, numrow, 'sshb',ssh(:,:  ,Kbb), ldxios = lwxios )
+      !
+      CALL iom_rstput( kt, nitrst, numrow, 'un'  , uu(:,:,:,Kmm), ldxios = lwxios )     ! now fields
+      CALL iom_rstput( kt, nitrst, numrow, 'vn'  , vv(:,:,:,Kmm), ldxios = lwxios )
+      CALL iom_rstput( kt, nitrst, numrow, 'sshn',ssh(:,:  ,Kmm), ldxios = lwxios )
+      
+      IF(lwxios) CALL iom_swap(      cxios_context          )
+      IF( kt == nitrst ) THEN
+         IF(.NOT.lwxios) THEN
+            CALL iom_close( numrow )     ! close the restart file (only at last time step)
+         ELSE
+            CALL iom_context_finalize(      cwxios_context          )
+         ENDIF
+         lrst_oce = .FALSE.
+         IF( ln_rst_list ) THEN
+            nrst_lst = MIN(nrst_lst + 1, SIZE(nn_stocklist,1))
+            nitrst = nn_stocklist( nrst_lst )
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE rst_write
+
+
+   SUBROUTINE rst_read_open
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE rst_read_open  ***
+      !! 
+      !! ** Purpose :   Open read files for NetCDF restart
+      !! 
+      !! ** Method  :   Use a non-zero, positive value of numror to assess whether or not
+      !!                the file has already been opened
+      !!----------------------------------------------------------------------
+      LOGICAL        ::   llok
+      CHARACTER(lc)  ::   clpath   ! full path to ocean output restart file
+      !!----------------------------------------------------------------------
+      !
+      IF( numror <= 0 ) THEN
+         IF(lwp) THEN                                             ! Contol prints
+            WRITE(numout,*)
+            WRITE(numout,*) 'rst_read : read oce NetCDF restart file'
+            IF ( snc4set%luse )      WRITE(numout,*) 'rst_read : configured with NetCDF4 support'
+            WRITE(numout,*) '~~~~~~~~'
+         ENDIF
+         lxios_sini = .FALSE.
+         clpath = TRIM(cn_ocerst_indir)
+         IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/'
+         CALL iom_open( TRIM(clpath)//cn_ocerst_in, numror )
+! are we using XIOS to read the data? Part above will have to modified once XIOS
+! can handle checking if variable is in the restart file (there will be no need to open
+! restart)
+         IF(.NOT.lxios_set) lrxios = lrxios.AND.lxios_sini
+         IF( lrxios) THEN
+             crxios_context = 'nemo_rst'
+             IF( .NOT.lxios_set ) THEN
+                 IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS'
+                 CALL iom_init( crxios_context )
+                 lxios_set = .TRUE.
+             ENDIF
+         ENDIF
+         IF( TRIM(Agrif_CFixed()) /= '0' .AND. lrxios) THEN
+             CALL iom_init( crxios_context )
+             IF(lwp) WRITE(numout,*) 'Enable restart reading by XIOS for AGRIF'
+             lxios_set = .TRUE.
+         ENDIF 
+      ENDIF
+
+   END SUBROUTINE rst_read_open
+
+
+   SUBROUTINE rst_read( Kbb, Kmm )
+      !!---------------------------------------------------------------------- 
+      !!                   ***  ROUTINE rst_read  ***
+      !! 
+      !! ** Purpose :   Read files for NetCDF restart
+      !! 
+      !! ** Method  :   Read in restart.nc file fields which are necessary for restart
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
+      REAL(wp) ::   zrdt
+      INTEGER  ::   jk
+      REAL(wp), DIMENSION(jpi, jpj, jpk) :: w3d
+      !!----------------------------------------------------------------------
+
+      CALL rst_read_open           ! open restart for reading (if not already opened)
+
+      ! Check dynamics and tracer time-step consistency and force Euler restart if changed
+      IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 )   THEN
+         CALL iom_get( numror, 'rdt', zrdt, ldxios = lrxios )
+         IF( zrdt /= rn_Dt ) THEN
+            IF(lwp) WRITE( numout,*)
+            IF(lwp) WRITE( numout,*) 'rst_read:  rdt not equal to the read one'
+            IF(lwp) WRITE( numout,*)
+            IF(lwp) WRITE( numout,*) '      ==>>>   forced euler first time-step'
+            l_1st_euler =  .TRUE.
+         ENDIF
+      ENDIF
+
+      CALL iom_delay_rst( 'READ', 'OCE', numror )   ! read only ocean delayed global communication variables
+      
+      IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN
+         ! before fields
+         CALL iom_get( numror, jpdom_auto, 'ub'     , uu(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
+         CALL iom_get( numror, jpdom_auto, 'vb'     , vv(:,:,:       ,Kbb), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
+#if ! defined key_qco
+         CALL iom_get( numror, jpdom_auto, 'sshb'   ,ssh(:,:         ,Kbb), ldxios = lrxios )
+#endif
+      ELSE
+         l_1st_euler =  .TRUE.      ! before field not found, forced euler 1st time-step
+      ENDIF
+      !
+      ! now fields
+      CALL iom_get( numror, jpdom_auto, 'un'     , uu(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'U', psgn = -1._wp )
+      CALL iom_get( numror, jpdom_auto, 'vn'     , vv(:,:,:       ,Kmm), ldxios = lrxios, cd_type = 'V', psgn = -1._wp )
+#if ! defined key_qco
+      CALL iom_get( numror, jpdom_auto, 'sshn'   ,ssh(:,:         ,Kmm), ldxios = lrxios )
+#endif
+      !
+      IF( l_1st_euler ) THEN                                  ! Euler restart 
+         uu   (:,:,:  ,Kbb) = uu   (:,:,:  ,Kmm)              ! all before fields set to now values
+         vv   (:,:,:  ,Kbb) = vv   (:,:,:  ,Kmm)
+         ssh  (:,:    ,Kbb) = ssh  (:,:    ,Kmm)
+      ENDIF
+      !
+      ww (:,:,:) = 0._wp !!st  gm is right 3D only !! 
+      !
+   END SUBROUTINE rst_read
+
+   !!=====================================================================
+END MODULE restart
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/sbcice_cice.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/sbcice_cice.F90	(revision 14059)
+++ 	(revision )
@@ -1,1060 +1,0 @@
-MODULE sbcice_cice
-   !!======================================================================
-   !!                       ***  MODULE  sbcice_cice  ***
-   !! To couple with sea ice model CICE (LANL)
-   !!=====================================================================
-#if defined key_cice
-   !!----------------------------------------------------------------------
-   !!   'key_cice' :                                     CICE sea-ice model
-   !!----------------------------------------------------------------------
-   !!   sbc_ice_cice  : sea-ice model time-stepping and update ocean sbc over ice-covered area
-   !!----------------------------------------------------------------------
-   USE oce             ! ocean dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-!!st8
-# if ! defined key_qco
-   USE domvvl
-# else
-   USE domqco
-# endif
-!!st8
-   USE phycst, only : rcp, rho0, r1_rho0, rhos, rhoi
-   USE in_out_manager  ! I/O manager
-   USE iom, ONLY : iom_put,iom_use              ! I/O manager library !!Joakim edit
-   USE lib_mpp         ! distributed memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE daymod          ! calendar
-   USE fldread         ! read input fields
-   USE sbc_oce         ! Surface boundary condition: ocean fields
-   USE sbc_ice         ! Surface boundary condition: ice   fields
-   USE sbcblk          ! Surface boundary condition: bulk
-   USE sbccpl
-
-   USE ice_kinds_mod
-   USE ice_blocks
-   USE ice_domain
-   USE ice_domain_size
-   USE ice_boundary
-   USE ice_constants
-   USE ice_gather_scatter
-   USE ice_calendar, only: dt
-   USE ice_state, only: aice,aicen,uvel,vvel,vsno,vsnon,vice,vicen
-# if defined key_cice4
-   USE ice_flux, only: strax,stray,strocnx,strocny,frain,fsnow,  &
-                strocnxT,strocnyT,                               & 
-                sst,sss,uocn,vocn,ss_tltx,ss_tlty,fsalt_gbm,     &
-                fresh_gbm,fhocn_gbm,fswthru_gbm,frzmlt,          &
-                flatn_f,fsurfn_f,fcondtopn_f,                    &
-                uatm,vatm,wind,fsw,flw,Tair,potT,Qa,rhoa,zlvl,   &
-                swvdr,swvdf,swidr,swidf
-   USE ice_therm_vertical, only: calc_Tsfc
-#else
-   USE ice_flux, only: strax,stray,strocnx,strocny,frain,fsnow,  &
-                strocnxT,strocnyT,                               & 
-                sst,sss,uocn,vocn,ss_tltx,ss_tlty,fsalt_ai,     &
-                fresh_ai,fhocn_ai,fswthru_ai,frzmlt,          &
-                flatn_f,fsurfn_f,fcondtopn_f,                    &
-                uatm,vatm,wind,fsw,flw,Tair,potT,Qa,rhoa,zlvl,   &
-                swvdr,swvdf,swidr,swidf
-   USE ice_therm_shared, only: calc_Tsfc
-#endif
-   USE ice_forcing, only: frcvdr,frcvdf,frcidr,frcidf
-   USE ice_atmo, only: calc_strair
-
-   USE CICE_InitMod
-   USE CICE_RunMod
-   USE CICE_FinalMod
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC cice_sbc_init   ! routine called by sbc_init
-   PUBLIC cice_sbc_final  ! routine called by sbc_final
-   PUBLIC sbc_ice_cice    ! routine called by sbc
-
-   INTEGER             ::   ji_off
-   INTEGER             ::   jj_off
-
-   INTEGER , PARAMETER ::   jpfld   = 13   ! maximum number of files to read 
-   INTEGER , PARAMETER ::   jp_snow = 1    ! index of snow file
-   INTEGER , PARAMETER ::   jp_rain = 2    ! index of rain file
-   INTEGER , PARAMETER ::   jp_sblm = 3    ! index of sublimation file
-   INTEGER , PARAMETER ::   jp_top1 = 4    ! index of category 1 topmelt file
-   INTEGER , PARAMETER ::   jp_top2 = 5    ! index of category 2 topmelt file
-   INTEGER , PARAMETER ::   jp_top3 = 6    ! index of category 3 topmelt file
-   INTEGER , PARAMETER ::   jp_top4 = 7    ! index of category 4 topmelt file
-   INTEGER , PARAMETER ::   jp_top5 = 8    ! index of category 5 topmelt file
-   INTEGER , PARAMETER ::   jp_bot1 = 9    ! index of category 1 botmelt file
-   INTEGER , PARAMETER ::   jp_bot2 = 10   ! index of category 2 botmelt file
-   INTEGER , PARAMETER ::   jp_bot3 = 11   ! index of category 3 botmelt file
-   INTEGER , PARAMETER ::   jp_bot4 = 12   ! index of category 4 botmelt file
-   INTEGER , PARAMETER ::   jp_bot5 = 13   ! index of category 5 botmelt file
-   TYPE(FLD), ALLOCATABLE, DIMENSION(:) ::   sf    ! structure of input fields (file informations, fields read)
-
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:), PRIVATE ::   png     ! local array used in sbc_cice_ice
-
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: sbcice_cice.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION sbc_ice_cice_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION sbc_ice_cice_alloc  ***
-      !!----------------------------------------------------------------------
-      ALLOCATE( png(jpi,jpj,jpnij), STAT=sbc_ice_cice_alloc )
-      CALL mpp_sum ( 'sbcice_cice', sbc_ice_cice_alloc )
-      IF( sbc_ice_cice_alloc > 0 )   CALL ctl_warn('sbc_ice_cice_alloc: allocation of arrays failed.')
-   END FUNCTION sbc_ice_cice_alloc
-
-   SUBROUTINE sbc_ice_cice( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_ice_cice  ***
-      !!                   
-      !! ** Purpose :   update the ocean surface boundary condition via the 
-      !!                CICE Sea Ice Model time stepping 
-      !!
-      !! ** Method  : - Get any extra forcing fields for CICE  
-      !!              - Prepare forcing fields
-      !!              - CICE model time stepping
-      !!              - call the routine that computes mass and 
-      !!                heat fluxes at the ice/ocean interface
-      !!
-      !! ** Action  : - time evolution of the CICE sea-ice model
-      !!              - update all sbc variables below sea-ice:
-      !!                utau, vtau, qns , qsr, emp , sfx
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt      ! ocean time step
-      INTEGER, INTENT(in) ::   ksbc    ! surface forcing type
-      !!----------------------------------------------------------------------
-      !
-      !                                        !----------------------!
-      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !  Ice time-step only  !
-         !                                     !----------------------!
-
-         ! Make sure any fluxes required for CICE are set
-         IF      ( ksbc == jp_flx ) THEN
-            CALL cice_sbc_force(kt)
-         ELSE IF( ksbc == jp_purecpl ) THEN
-            CALL sbc_cpl_ice_flx( fr_i )
-         ENDIF
-
-         CALL cice_sbc_in  ( kt, ksbc )
-         CALL CICE_Run
-         CALL cice_sbc_out ( kt, ksbc )
-
-         IF( ksbc == jp_purecpl )  CALL cice_sbc_hadgam(kt+1)
-
-      ENDIF                                          ! End sea-ice time step only
-      !
-   END SUBROUTINE sbc_ice_cice
-
-
-   SUBROUTINE cice_sbc_init( ksbc, Kbb, Kmm )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_init  ***
-      !! ** Purpose: Initialise ice related fields for NEMO and coupling
-      !!
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT( in  ) ::   ksbc                ! surface forcing type
-      INTEGER, INTENT( in  ) ::   Kbb, Kmm            ! time level indices
-      REAL(wp), DIMENSION(jpi,jpj) :: ztmp1, ztmp2
-      REAL(wp) ::   zcoefu, zcoefv, zcoeff            ! local scalar
-      INTEGER  ::   ji, jj, jl, jk                    ! dummy loop indices
-      !!---------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)'cice_sbc_init'
-
-      ji_off = INT ( (jpiglo - nx_global) / 2 )
-      jj_off = INT ( (jpjglo - ny_global) / 2 )
-
-#if defined key_nemocice_decomp
-      ! Pass initial SST from NEMO to CICE so ice is initialised correctly if
-      ! there is no restart file.
-      ! Values from a CICE restart file would overwrite this
-      IF( .NOT. ln_rstart ) THEN    
-         CALL nemo2cice( ts(:,:,1,jp_tem,Kmm) , sst , 'T' , 1.) 
-      ENDIF  
-#endif
-
-! Initialize CICE
-      CALL CICE_Initialize
-
-! Do some CICE consistency checks
-      IF( (ksbc == jp_flx) .OR. (ksbc == jp_purecpl) ) THEN
-         IF( calc_strair .OR. calc_Tsfc ) THEN
-            CALL ctl_stop( 'STOP', 'cice_sbc_init : Forcing option requires calc_strair=F and calc_Tsfc=F in ice_in' )
-         ENDIF
-      ELSEIF(ksbc == jp_blk) THEN
-         IF( .NOT. (calc_strair .AND. calc_Tsfc) ) THEN
-            CALL ctl_stop( 'STOP', 'cice_sbc_init : Forcing option requires calc_strair=T and calc_Tsfc=T in ice_in' )
-         ENDIF
-      ENDIF
-
-
-! allocate sbc_ice and sbc_cice arrays
-      IF( sbc_ice_alloc()      /= 0 )   CALL ctl_stop( 'STOP', 'sbc_ice_cice_alloc : unable to allocate arrays' )
-      IF( sbc_ice_cice_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_ice_cice_alloc : unable to allocate cice arrays' )
-
-! Ensure ocean temperatures are nowhere below freezing if not a NEMO restart
-      IF( .NOT. ln_rstart ) THEN
-         ts(:,:,:,jp_tem,Kmm) = MAX (ts(:,:,:,jp_tem,Kmm),Tocnfrz)
-         ts(:,:,:,jp_tem,Kbb) = ts(:,:,:,jp_tem,Kmm)
-      ENDIF
-
-      fr_iu(:,:)=0.0
-      fr_iv(:,:)=0.0
-
-      CALL cice2nemo(aice,fr_i, 'T', 1. )
-      IF( (ksbc == jp_flx) .OR. (ksbc == jp_purecpl) ) THEN
-         DO jl=1,ncat
-            CALL cice2nemo(aicen(:,:,jl,:),a_i(:,:,jl), 'T', 1. )
-         ENDDO
-      ENDIF
-
-! T point to U point
-! T point to V point
-      DO_2D( 1, 0, 1, 0 )
-         fr_iu(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji+1,jj))*umask(ji,jj,1)
-         fr_iv(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji,jj+1))*vmask(ji,jj,1)
-      END_2D
-
-      CALL lbc_lnk_multi( 'sbcice_cice', fr_iu , 'U', 1.,  fr_iv , 'V', 1. )
-
-      ! set the snow+ice mass
-      CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
-      CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
-      snwice_mass  (:,:) = ( rhos * ztmp1(:,:) + rhoi * ztmp2(:,:)  )
-      snwice_mass_b(:,:) = snwice_mass(:,:)
-
-      IF( .NOT.ln_rstart ) THEN
-         IF( ln_ice_embd ) THEN            ! embedded sea-ice: deplete the initial ssh below sea-ice area
-            ssh(:,:,Kmm) = ssh(:,:,Kmm) - snwice_mass(:,:) * r1_rho0
-            ssh(:,:,Kbb) = ssh(:,:,Kbb) - snwice_mass(:,:) * r1_rho0
-
-!!gm This should be put elsewhere....   (same remark for limsbc)
-!!gm especially here it is assumed zstar coordinate, but it can be ztilde....
-!!st9
-#if defined key_qco
-            IF( .NOT.ln_linssh )   CALL dom_qco_zgr( Kbb, Kmm, Kaa )   ! interpolation scale factor, depth and water column
-#else
-            IF( .NOT.ln_linssh ) THEN
-               !
-               DO jk = 1,jpkm1                     ! adjust initial vertical scale factors
-                  e3t(:,:,jk,Kmm) = e3t_0(:,:,jk)*( 1._wp + ssh(:,:,Kmm)*r1_ht_0(:,:)*tmask(:,:,jk) )
-                  e3t(:,:,jk,Kbb) = e3t_0(:,:,jk)*( 1._wp + ssh(:,:,Kbb)*r1_ht_0(:,:)*tmask(:,:,jk) )
-               END DO
-               e3t(:,:,:,Krhs) = e3t(:,:,:,Kbb)
-               ! Reconstruction of all vertical scale factors at now and before time-steps
-               ! =============================================================================
-               ! Horizontal scale factor interpolations
-               ! --------------------------------------
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3u(:,:,:,Kbb), 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3v(:,:,:,Kbb), 'V' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3f(:,:,:), 'F' )
-               ! Vertical scale factor interpolations
-               ! ------------------------------------
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-               CALL dom_vvl_interpol( ssh(:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-               CALL dom_vvl_interpol( ssh(:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-               ! t- and w- points depth
-               ! ----------------------
-               gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
-               gdepw(:,:,1,Kmm) = 0.0_wp
-               gde3w(:,:,1)     = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)
-               DO jk = 2, jpk
-                  gdept(:,:,jk,Kmm) = gdept(:,:,jk-1,Kmm) + e3w(:,:,jk,Kmm)
-                  gdepw(:,:,jk,Kmm) = gdepw(:,:,jk-1,Kmm) + e3t(:,:,jk-1,Kmm)
-                  gde3w(:,:,jk)     = gdept(:,:,jk  ,Kmm) - sshn   (:,:)
-               END DO
-            ENDIF
-#endif
-!!st9
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE cice_sbc_init
-
-   
-   SUBROUTINE cice_sbc_in( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_in  ***
-      !! ** Purpose: Set coupling fields and pass to CICE
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in   ) ::   kt   ! ocean time step
-      INTEGER, INTENT(in   ) ::   ksbc ! surface forcing type
-      !
-      INTEGER  ::   ji, jj, jl                   ! dummy loop indices      
-      REAL(wp), DIMENSION(jpi,jpj) :: ztmp, zpice
-      REAL(wp), DIMENSION(jpi,jpj,ncat) :: ztmpn
-      REAL(wp) ::   zintb, zintn  ! dummy argument
-      !!---------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)'cice_sbc_in'
-      ENDIF
-
-      ztmp(:,:)=0.0
-
-! Aggregate ice concentration already set in cice_sbc_out (or cice_sbc_init on 
-! the first time-step)
-
-! forced and coupled case 
-
-      IF( (ksbc == jp_flx).OR.(ksbc == jp_purecpl) ) THEN
-
-         ztmpn(:,:,:)=0.0
-
-! x comp of wind stress (CI_1)
-! U point to F point
-         DO_2D( 1, 0, 1, 1 )
-            ztmp(ji,jj) = 0.5 * (  fr_iu(ji,jj) * utau(ji,jj)      &
-                                 + fr_iu(ji,jj+1) * utau(ji,jj+1) ) * fmask(ji,jj,1)
-         END_2D
-         CALL nemo2cice(ztmp,strax,'F', -1. )
-
-! y comp of wind stress (CI_2)
-! V point to F point
-         DO_2D( 1, 1, 1, 0 )
-            ztmp(ji,jj) = 0.5 * (  fr_iv(ji,jj) * vtau(ji,jj)      &
-                                 + fr_iv(ji+1,jj) * vtau(ji+1,jj) ) * fmask(ji,jj,1)
-         END_2D
-         CALL nemo2cice(ztmp,stray,'F', -1. )
-
-! Surface downward latent heat flux (CI_5)
-         IF(ksbc == jp_flx) THEN
-            DO jl=1,ncat
-               ztmpn(:,:,jl)=qla_ice(:,:,1)*a_i(:,:,jl)
-            ENDDO
-         ELSE
-! emp_ice is set in sbc_cpl_ice_flx as sublimation-snow
-            qla_ice(:,:,1)= - ( emp_ice(:,:)+sprecip(:,:) ) * rLsub
-! End of temporary code
-            DO_2D( 1, 1, 1, 1 )
-               IF(fr_i(ji,jj).eq.0.0) THEN
-                  DO jl=1,ncat
-                     ztmpn(ji,jj,jl)=0.0
-                  ENDDO
-                  ! This will then be conserved in CICE
-                  ztmpn(ji,jj,1)=qla_ice(ji,jj,1)
-               ELSE
-                  DO jl=1,ncat
-                     ztmpn(ji,jj,jl)=qla_ice(ji,jj,1)*a_i(ji,jj,jl)/fr_i(ji,jj)
-                  ENDDO
-               ENDIF
-            END_2D
-         ENDIF
-         DO jl=1,ncat
-            CALL nemo2cice(ztmpn(:,:,jl),flatn_f(:,:,jl,:),'T', 1. )
-
-! GBM conductive flux through ice (CI_6)
-!  Convert to GBM
-            IF(ksbc == jp_flx) THEN
-               ztmp(:,:) = botmelt(:,:,jl)*a_i(:,:,jl)
-            ELSE
-               ztmp(:,:) = botmelt(:,:,jl)
-            ENDIF
-            CALL nemo2cice(ztmp,fcondtopn_f(:,:,jl,:),'T', 1. )
-
-! GBM surface heat flux (CI_7)
-!  Convert to GBM
-            IF(ksbc == jp_flx) THEN
-               ztmp(:,:) = (topmelt(:,:,jl)+botmelt(:,:,jl))*a_i(:,:,jl) 
-            ELSE
-               ztmp(:,:) = (topmelt(:,:,jl)+botmelt(:,:,jl))
-            ENDIF
-            CALL nemo2cice(ztmp,fsurfn_f(:,:,jl,:),'T', 1. )
-         ENDDO
-
-      ELSE IF(ksbc == jp_blk) THEN
-
-! Pass bulk forcing fields to CICE (which will calculate heat fluxes etc itself)
-! x comp and y comp of atmosphere surface wind (CICE expects on T points)
-         ztmp(:,:) = wndi_ice(:,:)
-         CALL nemo2cice(ztmp,uatm,'T', -1. )
-         ztmp(:,:) = wndj_ice(:,:)
-         CALL nemo2cice(ztmp,vatm,'T', -1. )
-         ztmp(:,:) = SQRT ( wndi_ice(:,:)**2 + wndj_ice(:,:)**2 )
-         CALL nemo2cice(ztmp,wind,'T', 1. )    ! Wind speed (m/s)
-         ztmp(:,:) = qsr_ice(:,:,1)
-         CALL nemo2cice(ztmp,fsw,'T', 1. )     ! Incoming short-wave (W/m^2)
-         ztmp(:,:) = qlw_ice(:,:,1)
-         CALL nemo2cice(ztmp,flw,'T', 1. )     ! Incoming long-wave (W/m^2)
-         ztmp(:,:) = tatm_ice(:,:)
-         CALL nemo2cice(ztmp,Tair,'T', 1. )    ! Air temperature (K)
-         CALL nemo2cice(ztmp,potT,'T', 1. )    ! Potential temp (K)
-! Following line uses MAX(....) to avoid problems if tatm_ice has unset halo rows  
-         ztmp(:,:) = 101000. / ( 287.04 * MAX(1.0,tatm_ice(:,:)) )    
-                                               ! Constant (101000.) atm pressure assumed
-         CALL nemo2cice(ztmp,rhoa,'T', 1. )    ! Air density (kg/m^3)
-         ztmp(:,:) = qatm_ice(:,:)
-         CALL nemo2cice(ztmp,Qa,'T', 1. )      ! Specific humidity (kg/kg)
-         ztmp(:,:)=10.0
-         CALL nemo2cice(ztmp,zlvl,'T', 1. )    ! Atmos level height (m)
-
-! May want to check all values are physically realistic (as in CICE routine 
-! prepare_forcing)?
-
-! Divide shortwave into spectral bands (as in prepare_forcing)
-         ztmp(:,:)=qsr_ice(:,:,1)*frcvdr       ! visible direct
-         CALL nemo2cice(ztmp,swvdr,'T', 1. )             
-         ztmp(:,:)=qsr_ice(:,:,1)*frcvdf       ! visible diffuse
-         CALL nemo2cice(ztmp,swvdf,'T', 1. )              
-         ztmp(:,:)=qsr_ice(:,:,1)*frcidr       ! near IR direct
-         CALL nemo2cice(ztmp,swidr,'T', 1. )
-         ztmp(:,:)=qsr_ice(:,:,1)*frcidf       ! near IR diffuse
-         CALL nemo2cice(ztmp,swidf,'T', 1. )
-
-      ENDIF
-
-! Snowfall
-! Ensure fsnow is positive (as in CICE routine prepare_forcing)
-      IF( iom_use('snowpre') )   CALL iom_put('snowpre',MAX( (1.0-fr_i(:,:))*sprecip(:,:) ,0.0)) !!Joakim edit  
-      ztmp(:,:)=MAX(fr_i(:,:)*sprecip(:,:),0.0)  
-      CALL nemo2cice(ztmp,fsnow,'T', 1. ) 
-
-! Rainfall
-      IF( iom_use('precip') )   CALL iom_put('precip', (1.0-fr_i(:,:))*(tprecip(:,:)-sprecip(:,:)) ) !!Joakim edit
-      ztmp(:,:)=fr_i(:,:)*(tprecip(:,:)-sprecip(:,:))
-      CALL nemo2cice(ztmp,frain,'T', 1. ) 
-
-! Freezing/melting potential
-! Calculated over NEMO leapfrog timestep (hence 2*dt)
-      nfrzmlt(:,:) = rho0 * rcp * e3t_m(:,:) * ( Tocnfrz-sst_m(:,:) ) / ( 2.0*dt )
-
-      ztmp(:,:) = nfrzmlt(:,:)
-      CALL nemo2cice(ztmp,frzmlt,'T', 1. )
-
-! SST  and SSS
-
-      CALL nemo2cice(sst_m,sst,'T', 1. )
-      CALL nemo2cice(sss_m,sss,'T', 1. )
-
-! x comp and y comp of surface ocean current
-! U point to F point
-      DO_2D( 1, 0, 1, 1 )
-         ztmp(ji,jj)=0.5*(ssu_m(ji,jj)+ssu_m(ji,jj+1))*fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice(ztmp,uocn,'F', -1. )
-
-! V point to F point
-      DO_2D( 1, 1, 1, 0 )
-         ztmp(ji,jj)=0.5*(ssv_m(ji,jj)+ssv_m(ji+1,jj))*fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice(ztmp,vocn,'F', -1. )
-
-      IF( ln_ice_embd ) THEN             !== embedded sea ice: compute representative ice top surface ==!
-          !
-          ! average interpolation coeff as used in dynspg = (1/nn_fsbc) * {SUM[n/nn_fsbc], n=0,nn_fsbc-1}
-          !                                               = (1/nn_fsbc)^2 * {SUM[n], n=0,nn_fsbc-1}
-         zintn = REAL( nn_fsbc - 1 ) / REAL( nn_fsbc ) * 0.5_wp
-          !
-          ! average interpolation coeff as used in dynspg = (1/nn_fsbc) * {SUM[1-n/nn_fsbc], n=0,nn_fsbc-1}
-          !                                               = (1/nn_fsbc)^2 * (nn_fsbc^2 - {SUM[n], n=0,nn_fsbc-1})
-         zintb = REAL( nn_fsbc + 1 ) / REAL( nn_fsbc ) * 0.5_wp
-          !
-         zpice(:,:) = ssh_m(:,:) + (  zintn * snwice_mass(:,:) +  zintb * snwice_mass_b(:,:)  ) * r1_rho0
-          !
-         !
-      ELSE                                    !== non-embedded sea ice: use ocean surface for slope calculation ==!
-         zpice(:,:) = ssh_m(:,:)
-      ENDIF
-
-! x comp and y comp of sea surface slope (on F points)
-! T point to F point
-      DO_2D( 1, 0, 1, 0 )
-         ztmp(ji,jj)=0.5 * (  (zpice(ji+1,jj  )-zpice(ji,jj  )) * r1_e1u(ji,jj  )    &
-            &               + (zpice(ji+1,jj+1)-zpice(ji,jj+1)) * r1_e1u(ji,jj+1)  ) * fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice( ztmp,ss_tltx,'F', -1. )
-
-! T point to F point
-      DO_2D( 1, 0, 1, 0 )
-         ztmp(ji,jj)=0.5 * (  (zpice(ji  ,jj+1)-zpice(ji  ,jj)) * r1_e2v(ji  ,jj)    &
-            &               + (zpice(ji+1,jj+1)-zpice(ji+1,jj)) * r1_e2v(ji+1,jj)  ) *  fmask(ji,jj,1)
-      END_2D
-      CALL nemo2cice(ztmp,ss_tlty,'F', -1. )
-      !
-   END SUBROUTINE cice_sbc_in
-
-
-   SUBROUTINE cice_sbc_out( kt, ksbc )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_out  ***
-      !! ** Purpose: Get fields from CICE and set surface fields for NEMO
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      INTEGER, INTENT( in  ) ::   ksbc ! surface forcing type
-      
-      INTEGER  ::   ji, jj, jl                 ! dummy loop indices
-      REAL(wp), DIMENSION(jpi,jpj) :: ztmp1, ztmp2
-      !!---------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)'cice_sbc_out'
-      ENDIF
-      
-! x comp of ocean-ice stress 
-      CALL cice2nemo(strocnx,ztmp1,'F', -1. )
-      ss_iou(:,:)=0.0
-! F point to U point
-      DO_2D( 0, 0, 0, 0 )
-         ss_iou(ji,jj) = 0.5 * ( ztmp1(ji,jj-1) + ztmp1(ji,jj) ) * umask(ji,jj,1)
-      END_2D
-      CALL lbc_lnk( 'sbcice_cice', ss_iou , 'U', -1. )
-
-! y comp of ocean-ice stress 
-      CALL cice2nemo(strocny,ztmp1,'F', -1. )
-      ss_iov(:,:)=0.0
-! F point to V point
-
-      DO_2D( 1, 0, 0, 0 )
-         ss_iov(ji,jj) = 0.5 * ( ztmp1(ji-1,jj) + ztmp1(ji,jj) ) * vmask(ji,jj,1)
-      END_2D
-      CALL lbc_lnk( 'sbcice_cice', ss_iov , 'V', -1. )
-
-! x and y comps of surface stress
-! Combine wind stress and ocean-ice stress
-! [Note that fr_iu hasn't yet been updated, so still from start of CICE timestep]
-! strocnx and strocny already weighted by ice fraction in CICE so not done here 
-
-      utau(:,:)=(1.0-fr_iu(:,:))*utau(:,:)-ss_iou(:,:)
-      vtau(:,:)=(1.0-fr_iv(:,:))*vtau(:,:)-ss_iov(:,:)     
- 
-! Also need ice/ocean stress on T points so that taum can be updated 
-! This interpolation is already done in CICE so best to use those values 
-      CALL cice2nemo(strocnxT,ztmp1,'T',-1.) 
-      CALL cice2nemo(strocnyT,ztmp2,'T',-1.) 
- 
-! Update taum with modulus of ice-ocean stress 
-! strocnxT and strocnyT are not weighted by ice fraction in CICE so must be done here 
-taum(:,:)=(1.0-fr_i(:,:))*taum(:,:)+fr_i(:,:)*SQRT(ztmp1*ztmp1 + ztmp2*ztmp2) 
-
-! Freshwater fluxes 
-
-      IF(ksbc == jp_flx) THEN
-! Note that emp from the forcing files is evap*(1-aice)-(tprecip-aice*sprecip)
-! What we want here is evap*(1-aice)-tprecip*(1-aice) hence manipulation below
-! Not ideal since aice won't be the same as in the atmosphere.  
-! Better to use evap and tprecip? (but for now don't read in evap in this case)
-         emp(:,:)  = emp(:,:)+fr_i(:,:)*(tprecip(:,:)-sprecip(:,:))
-      ELSE IF(ksbc == jp_blk) THEN
-         emp(:,:)  = (1.0-fr_i(:,:))*emp(:,:)        
-      ELSE IF(ksbc == jp_purecpl) THEN
-! emp_tot is set in sbc_cpl_ice_flx (called from cice_sbc_in above) 
-! This is currently as required with the coupling fields from the UM atmosphere
-         emp(:,:) = emp_tot(:,:)+tprecip(:,:)*fr_i(:,:) 
-      ENDIF
-
-#if defined key_cice4
-      CALL cice2nemo(fresh_gbm,ztmp1,'T', 1. )
-      CALL cice2nemo(fsalt_gbm,ztmp2,'T', 1. )
-#else
-      CALL cice2nemo(fresh_ai,ztmp1,'T', 1. )
-      CALL cice2nemo(fsalt_ai,ztmp2,'T', 1. )
-#endif
-
-! Check to avoid unphysical expression when ice is forming (ztmp1 negative)
-! Otherwise we are effectively allowing ice of higher salinity than the ocean to form
-! which has to be compensated for by the ocean salinity potentially going negative
-! This check breaks conservation but seems reasonable until we have prognostic ice salinity
-! Note the 1000.0 below is to convert from kg salt to g salt (needed for PSU)
-      WHERE (ztmp1(:,:).lt.0.0) ztmp2(:,:)=MAX(ztmp2(:,:),ztmp1(:,:)*sss_m(:,:)/1000.0)
-      sfx(:,:)=ztmp2(:,:)*1000.0
-      emp(:,:)=emp(:,:)-ztmp1(:,:)
-      fmmflx(:,:) = ztmp1(:,:) !!Joakim edit
-      
-      CALL lbc_lnk_multi( 'sbcice_cice', emp , 'T', 1., sfx , 'T', 1. )
-
-! Solar penetrative radiation and non solar surface heat flux
-
-! Scale qsr and qns according to ice fraction (bulk formulae only)
-
-      IF(ksbc == jp_blk) THEN
-         qsr(:,:)=qsr(:,:)*(1.0-fr_i(:,:))
-         qns(:,:)=qns(:,:)*(1.0-fr_i(:,:))
-      ENDIF
-! Take into account snow melting except for fully coupled when already in qns_tot
-      IF(ksbc == jp_purecpl) THEN
-         qsr(:,:)= qsr_tot(:,:)
-         qns(:,:)= qns_tot(:,:)
-      ELSE
-         qns(:,:)= qns(:,:)-sprecip(:,:)*Lfresh*(1.0-fr_i(:,:))
-      ENDIF
-
-! Now add in ice / snow related terms
-! [fswthru will be zero unless running with calc_Tsfc=T in CICE]
-#if defined key_cice4
-      CALL cice2nemo(fswthru_gbm,ztmp1,'T', 1. )
-#else
-      CALL cice2nemo(fswthru_ai,ztmp1,'T', 1. )
-#endif
-      qsr(:,:)=qsr(:,:)+ztmp1(:,:)
-      CALL lbc_lnk( 'sbcice_cice', qsr , 'T', 1. )
-
-      DO_2D( 1, 1, 1, 1 )
-         nfrzmlt(ji,jj)=MAX(nfrzmlt(ji,jj),0.0)
-      END_2D
-
-#if defined key_cice4
-      CALL cice2nemo(fhocn_gbm,ztmp1,'T', 1. )
-#else
-      CALL cice2nemo(fhocn_ai,ztmp1,'T', 1. )
-#endif
-      qns(:,:)=qns(:,:)+nfrzmlt(:,:)+ztmp1(:,:)
-
-      CALL lbc_lnk( 'sbcice_cice', qns , 'T', 1. )
-
-! Prepare for the following CICE time-step
-
-      CALL cice2nemo(aice,fr_i,'T', 1. )
-      IF( (ksbc == jp_flx).OR.(ksbc == jp_purecpl) ) THEN
-         DO jl=1,ncat
-            CALL cice2nemo(aicen(:,:,jl,:),a_i(:,:,jl), 'T', 1. )
-         ENDDO
-      ENDIF
-
-! T point to U point
-! T point to V point
-      DO_2D( 1, 0, 1, 0 )
-         fr_iu(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji+1,jj))*umask(ji,jj,1)
-         fr_iv(ji,jj)=0.5*(fr_i(ji,jj)+fr_i(ji,jj+1))*vmask(ji,jj,1)
-      END_2D
-
-      CALL lbc_lnk_multi( 'sbcice_cice', fr_iu , 'U', 1., fr_iv , 'V', 1. )
-
-      ! set the snow+ice mass
-      CALL cice2nemo(vsno(:,:,:),ztmp1,'T', 1. )
-      CALL cice2nemo(vice(:,:,:),ztmp2,'T', 1. )
-      snwice_mass  (:,:) = ( rhos * ztmp1(:,:) + rhoi * ztmp2(:,:)  )
-      snwice_mass_b(:,:) = snwice_mass(:,:)
-      snwice_fmass (:,:) = ( snwice_mass(:,:) - snwice_mass_b(:,:) ) / dt
-      !
-   END SUBROUTINE cice_sbc_out
-
-
-   SUBROUTINE cice_sbc_hadgam( kt )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_hadgam  ***
-      !! ** Purpose: Prepare fields needed to pass to HadGAM3 atmosphere
-      !! 
-      !!
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      !!
-      INTEGER  ::   jl                        ! dummy loop index
-      INTEGER  ::   ierror
-      !!---------------------------------------------------------------------
-      !
-      IF( kt == nit000 )  THEN
-         IF(lwp) WRITE(numout,*)'cice_sbc_hadgam'
-         IF( sbc_cpl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'sbc_cpl_alloc : unable to allocate arrays' )
-      ENDIF
-
-      !                                         ! =========================== !
-      !                                         !   Prepare Coupling fields   !
-      !                                         ! =========================== !
-      !
-      ! x and y comp of ice velocity
-      !
-      CALL cice2nemo(uvel,u_ice,'F', -1. )
-      CALL cice2nemo(vvel,v_ice,'F', -1. )
-      !
-      ! Ice concentration (CO_1) = a_i calculated at end of cice_sbc_out  
-      !
-      ! Snow and ice thicknesses (CO_2 and CO_3)
-      !
-      DO jl = 1, ncat
-         CALL cice2nemo( vsnon(:,:,jl,:), h_s(:,:,jl),'T', 1. )
-         CALL cice2nemo( vicen(:,:,jl,:), h_i(:,:,jl),'T', 1. )
-      END DO
-      !
-   END SUBROUTINE cice_sbc_hadgam
-
-
-   SUBROUTINE cice_sbc_final
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_final  ***
-      !! ** Purpose: Finalize CICE
-      !!---------------------------------------------------------------------
-      !
-      IF(lwp) WRITE(numout,*)'cice_sbc_final'
-      !
-      CALL CICE_Finalize
-      !
-   END SUBROUTINE cice_sbc_final
-
-
-   SUBROUTINE cice_sbc_force (kt)
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice_sbc_force  ***
-      !! ** Purpose : Provide CICE forcing from files
-      !!
-      !!---------------------------------------------------------------------
-      !! ** Method  :   READ monthly flux file in NetCDF files
-      !!      
-      !!  snowfall    
-      !!  rainfall    
-      !!  sublimation rate    
-      !!  topmelt (category)
-      !!  botmelt (category)
-      !!
-      !! History :
-      !!----------------------------------------------------------------------
-      USE iom
-      !!
-      INTEGER, INTENT( in  ) ::   kt   ! ocean time step
-      !!
-      INTEGER  ::   ierror             ! return error code
-      INTEGER  ::   ifpr               ! dummy loop index
-      !!
-      CHARACTER(len=100) ::  cn_dir                            !   Root directory for location of CICE forcing files
-      TYPE(FLD_N), DIMENSION(jpfld) ::   slf_i                 ! array of namelist informations on the fields to read
-      TYPE(FLD_N) ::   sn_snow, sn_rain, sn_sblm               ! informations about the fields to be read
-      TYPE(FLD_N) ::   sn_top1, sn_top2, sn_top3, sn_top4, sn_top5
-      TYPE(FLD_N) ::   sn_bot1, sn_bot2, sn_bot3, sn_bot4, sn_bot5 
-      !!
-      NAMELIST/namsbc_cice/ cn_dir, sn_snow, sn_rain, sn_sblm,   &
-         &                          sn_top1, sn_top2, sn_top3, sn_top4, sn_top5,  &
-         &                          sn_bot1, sn_bot2, sn_bot3, sn_bot4, sn_bot5
-      INTEGER :: ios
-      !!---------------------------------------------------------------------
-
-      !                                         ! ====================== !
-      IF( kt == nit000 ) THEN                   !  First call kt=nit000  !
-         !                                      ! ====================== !
-         ! namsbc_cice is not yet in the reference namelist
-         ! set file information (default values)
-         cn_dir = './'       ! directory in which the model is executed
-
-         ! (NB: frequency positive => hours, negative => months)
-         !            !    file          ! frequency !  variable    ! time intep !  clim   ! 'yearly' or ! weights  ! rotation   ! landmask
-         !            !    name          !  (hours)  !   name       !   (T/F)    !  (T/F)  !  'monthly'  ! filename ! pairs      ! file
-         sn_snow = FLD_N( 'snowfall_1m'  ,    -1.    ,  'snowfall'  ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    ) 
-         sn_rain = FLD_N( 'rainfall_1m'  ,    -1.    ,  'rainfall'  ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    ) 
-         sn_sblm = FLD_N( 'sublim_1m'    ,    -1.    ,  'sublim'    ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top1 = FLD_N( 'topmeltn1_1m' ,    -1.    ,  'topmeltn1' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top2 = FLD_N( 'topmeltn2_1m' ,    -1.    ,  'topmeltn2' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top3 = FLD_N( 'topmeltn3_1m' ,    -1.    ,  'topmeltn3' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top4 = FLD_N( 'topmeltn4_1m' ,    -1.    ,  'topmeltn4' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_top5 = FLD_N( 'topmeltn5_1m' ,    -1.    ,  'topmeltn5' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot1 = FLD_N( 'botmeltn1_1m' ,    -1.    ,  'botmeltn1' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot2 = FLD_N( 'botmeltn2_1m' ,    -1.    ,  'botmeltn2' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot3 = FLD_N( 'botmeltn3_1m' ,    -1.    ,  'botmeltn3' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot4 = FLD_N( 'botmeltn4_1m' ,    -1.    ,  'botmeltn4' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-         sn_bot5 = FLD_N( 'botmeltn5_1m' ,    -1.    ,  'botmeltn5' ,  .true.    , .true.  ,  ' yearly'  , ''       , ''         ,  ''    )
-
-         READ  ( numnam_ref, namsbc_cice, IOSTAT = ios, ERR = 901)
-901      IF( ios /= 0 )   CALL ctl_nam ( ios , 'namsbc_cice in reference namelist' )
-
-         READ  ( numnam_cfg, namsbc_cice, IOSTAT = ios, ERR = 902 )
-902      IF( ios >  0 )   CALL ctl_nam ( ios , 'namsbc_cice in configuration namelist' )
-         IF(lwm) WRITE ( numond, namsbc_cice )
-
-         ! store namelist information in an array
-         slf_i(jp_snow) = sn_snow   ;   slf_i(jp_rain) = sn_rain   ;   slf_i(jp_sblm) = sn_sblm
-         slf_i(jp_top1) = sn_top1   ;   slf_i(jp_top2) = sn_top2   ;   slf_i(jp_top3) = sn_top3
-         slf_i(jp_top4) = sn_top4   ;   slf_i(jp_top5) = sn_top5   ;   slf_i(jp_bot1) = sn_bot1
-         slf_i(jp_bot2) = sn_bot2   ;   slf_i(jp_bot3) = sn_bot3   ;   slf_i(jp_bot4) = sn_bot4
-         slf_i(jp_bot5) = sn_bot5
-         
-         ! set sf structure
-         ALLOCATE( sf(jpfld), STAT=ierror )
-         IF( ierror > 0 ) THEN
-            CALL ctl_stop( 'cice_sbc_force: unable to allocate sf structure' )   ;   RETURN
-         ENDIF
-
-         DO ifpr= 1, jpfld
-            ALLOCATE( sf(ifpr)%fnow(jpi,jpj,1) )
-            ALLOCATE( sf(ifpr)%fdta(jpi,jpj,1,2) )
-         END DO
-
-         ! fill sf with slf_i and control print
-         CALL fld_fill( sf, slf_i, cn_dir, 'cice_sbc_force', 'flux formulation for CICE', 'namsbc_cice' )
-         !
-      ENDIF
-
-      CALL fld_read( kt, nn_fsbc, sf )           ! Read input fields and provides the
-      !                                          ! input fields at the current time-step
-
-      ! set the fluxes from read fields
-      sprecip(:,:) = sf(jp_snow)%fnow(:,:,1)
-      tprecip(:,:) = sf(jp_snow)%fnow(:,:,1)+sf(jp_rain)%fnow(:,:,1)
-! May be better to do this conversion somewhere else
-      qla_ice(:,:,1) = -rLsub*sf(jp_sblm)%fnow(:,:,1)
-      topmelt(:,:,1) = sf(jp_top1)%fnow(:,:,1)
-      topmelt(:,:,2) = sf(jp_top2)%fnow(:,:,1)
-      topmelt(:,:,3) = sf(jp_top3)%fnow(:,:,1)
-      topmelt(:,:,4) = sf(jp_top4)%fnow(:,:,1)
-      topmelt(:,:,5) = sf(jp_top5)%fnow(:,:,1)
-      botmelt(:,:,1) = sf(jp_bot1)%fnow(:,:,1)
-      botmelt(:,:,2) = sf(jp_bot2)%fnow(:,:,1)
-      botmelt(:,:,3) = sf(jp_bot3)%fnow(:,:,1)
-      botmelt(:,:,4) = sf(jp_bot4)%fnow(:,:,1)
-      botmelt(:,:,5) = sf(jp_bot5)%fnow(:,:,1)
-
-      ! control print (if less than 100 time-step asked)
-      IF( nitend-nit000 <= 100 .AND. lwp ) THEN
-         WRITE(numout,*) 
-         WRITE(numout,*) '        read forcing fluxes for CICE OK'
-         CALL FLUSH(numout)
-      ENDIF
-
-   END SUBROUTINE cice_sbc_force
-
-   SUBROUTINE nemo2cice( pn, pc, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE nemo2cice  ***
-      !! ** Purpose :   Transfer field in NEMO array to field in CICE array.  
-#if defined key_nemocice_decomp
-      !!             
-      !!                NEMO and CICE PE sub domains are identical, hence
-      !!                there is no need to gather or scatter data from 
-      !!                one PE configuration to another.
-#else
-      !!                Automatically gather/scatter between 
-      !!                different processors and blocks
-      !! ** Method :    A. Ensure all haloes are filled in NEMO field (pn)
-      !!                B. Gather pn into global array (png)
-      !!                C. Map png into CICE global array (pcg)
-      !!                D. Scatter pcg to CICE blocks (pc) + update haloes  
-#endif
-      !!---------------------------------------------------------------------
-      CHARACTER(len=1), INTENT( in ) ::   &
-          cd_type       ! nature of pn grid-point
-          !             !   = T or F gridpoints
-      REAL(wp), INTENT( in ) ::   &
-          psgn          ! control of the sign change
-          !             !   =-1 , the sign is modified following the type of b.c. used
-          !             !   = 1 , no sign change
-      REAL(wp), DIMENSION(jpi,jpj) :: pn
-#if !defined key_nemocice_decomp
-      REAL(wp), DIMENSION(jpiglo,jpjglo) :: png2
-      REAL (kind=dbl_kind), dimension(nx_global,ny_global) :: pcg
-#endif
-      REAL (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: pc
-      INTEGER (int_kind) :: &
-         field_type,        &! id for type of field (scalar, vector, angle)
-         grid_loc            ! id for location on horizontal grid
-                            !  (center, NEcorner, Nface, Eface)
-
-      INTEGER  ::   ji, jj, jn                      ! dummy loop indices
-      !!---------------------------------------------------------------------
-
-!     A. Ensure all haloes are filled in NEMO field (pn)
-
-      CALL lbc_lnk( 'sbcice_cice', pn , cd_type, psgn )
-
-#if defined key_nemocice_decomp
-
-      ! Copy local domain data from NEMO to CICE field
-      pc(:,:,1)=0.0
-      DO jj=2,ny_block-1
-         DO ji=2,nx_block-1
-            pc(ji,jj,1)=pn(ji-1+ji_off,jj-1+jj_off)
-         ENDDO
-      ENDDO
-
-#else
-
-!     B. Gather pn into global array (png)
-
-      IF( jpnij > 1) THEN
-         CALL mppsync
-         CALL mppgather (pn,0,png) 
-         CALL mppsync
-      ELSE
-         png(:,:,1)=pn(:,:)
-      ENDIF
-
-!     C. Map png into CICE global array (pcg)
-
-! Need to make sure this is robust to changes in NEMO halo rows....
-! (may be OK but not 100% sure)
-
-      IF(nproc==0) THEN     
-!        pcg(:,:)=0.0
-         DO jn=1,jpnij
-            DO jj=nldjt(jn),nlejt(jn)
-               DO ji=nldit(jn),nleit(jn)
-                  png2(ji+nimppt(jn)-1,jj+njmppt(jn)-1)=png(ji,jj,jn)
-               ENDDO
-            ENDDO
-         ENDDO
-         DO jj=1,ny_global
-            DO ji=1,nx_global
-               pcg(ji,jj)=png2(ji+ji_off,jj+jj_off)
-            ENDDO
-         ENDDO
-      ENDIF
-
-#endif
-
-      SELECT CASE ( cd_type )
-         CASE ( 'T' )
-            grid_loc=field_loc_center
-         CASE ( 'F' )                              
-            grid_loc=field_loc_NEcorner
-      END SELECT
-
-      SELECT CASE ( NINT(psgn) )
-         CASE ( -1 )
-            field_type=field_type_vector
-         CASE ( 1 )                              
-            field_type=field_type_scalar
-      END SELECT
-
-#if defined key_nemocice_decomp
-      ! Ensure CICE halos are up to date
-      CALL ice_HaloUpdate (pc, halo_info, grid_loc, field_type)
-#else
-!     D. Scatter pcg to CICE blocks (pc) + update halos
-      CALL scatter_global(pc, pcg, 0, distrb_info, grid_loc, field_type)
-#endif
-
-   END SUBROUTINE nemo2cice
-
-   SUBROUTINE cice2nemo ( pc, pn, cd_type, psgn )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE cice2nemo  ***
-      !! ** Purpose :   Transfer field in CICE array to field in NEMO array.
-#if defined key_nemocice_decomp
-      !!             
-      !!                NEMO and CICE PE sub domains are identical, hence
-      !!                there is no need to gather or scatter data from 
-      !!                one PE configuration to another.
-#else 
-      !!                Automatically deal with scatter/gather between
-      !!                different processors and blocks
-      !! ** Method :    A. Gather CICE blocks (pc) into global array (pcg)
-      !!                B. Map pcg into NEMO global array (png)
-      !!                C. Scatter png into NEMO field (pn) for each processor
-      !!                D. Ensure all haloes are filled in pn 
-#endif
-      !!---------------------------------------------------------------------
-
-      CHARACTER(len=1), INTENT( in ) ::   &
-          cd_type       ! nature of pn grid-point
-          !             !   = T or F gridpoints
-      REAL(wp), INTENT( in ) ::   &
-          psgn          ! control of the sign change
-          !             !   =-1 , the sign is modified following the type of b.c. used
-          !             !   = 1 , no sign change
-      REAL(wp), DIMENSION(jpi,jpj) :: pn
-
-#if defined key_nemocice_decomp
-      INTEGER (int_kind) :: &
-         field_type,        & ! id for type of field (scalar, vector, angle)
-         grid_loc             ! id for location on horizontal grid
-                              ! (center, NEcorner, Nface, Eface)
-#else
-      REAL (kind=dbl_kind), dimension(nx_global,ny_global) :: pcg
-#endif
-
-      REAL (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: pc
-
-      INTEGER  ::   ji, jj, jn                      ! dummy loop indices
-
-
-#if defined key_nemocice_decomp
-
-      SELECT CASE ( cd_type )
-         CASE ( 'T' )
-            grid_loc=field_loc_center
-         CASE ( 'F' )                              
-            grid_loc=field_loc_NEcorner
-      END SELECT
-
-      SELECT CASE ( NINT(psgn) )
-         CASE ( -1 )
-            field_type=field_type_vector
-         CASE ( 1 )                              
-            field_type=field_type_scalar
-      END SELECT
-
-      CALL ice_HaloUpdate (pc, halo_info, grid_loc, field_type)
-
-
-      pn(:,:)=0.0
-      DO_2D( 1, 0, 1, 0 )
-         pn(ji,jj)=pc(ji+1-ji_off,jj+1-jj_off,1)
-      END_2D
-
-#else
-
-!      A. Gather CICE blocks (pc) into global array (pcg) 
-
-      CALL gather_global(pcg, pc, 0, distrb_info)
-
-!     B. Map pcg into NEMO global array (png)
-
-! Need to make sure this is robust to changes in NEMO halo rows....
-! (may be OK but not spent much time thinking about it)
-! Note that non-existent pcg elements may be used below, but
-! the lbclnk call on pn will replace these with sensible values
-
-      IF(nproc==0) THEN
-         png(:,:,:)=0.0
-         DO jn=1,jpnij
-            DO jj=nldjt(jn),nlejt(jn)
-               DO ji=nldit(jn),nleit(jn)
-                  png(ji,jj,jn)=pcg(ji+nimppt(jn)-1-ji_off,jj+njmppt(jn)-1-jj_off)
-               ENDDO
-            ENDDO
-         ENDDO
-      ENDIF
-
-!     C. Scatter png into NEMO field (pn) for each processor
-
-      IF( jpnij > 1) THEN
-         CALL mppsync
-         CALL mppscatter (png,0,pn) 
-         CALL mppsync
-      ELSE
-         pn(:,:)=png(:,:,1)
-      ENDIF
-
-#endif
-
-!     D. Ensure all haloes are filled in pn
-
-      CALL lbc_lnk( 'sbcice_cice', pn , cd_type, psgn )
-
-   END SUBROUTINE cice2nemo
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option           Dummy module         NO CICE sea-ice model
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE sbc_ice_cice ( kt, ksbc )     ! Dummy routine
-      IMPLICIT NONE
-      INTEGER, INTENT( in ) :: kt, ksbc
-      WRITE(*,*) 'sbc_ice_cice: You should not have seen this print! error?', kt
-   END SUBROUTINE sbc_ice_cice
-
-   SUBROUTINE cice_sbc_init (ksbc, Kbb, Kmm)    ! Dummy routine
-      IMPLICIT NONE
-      INTEGER, INTENT( in ) :: ksbc
-      INTEGER, INTENT( in ) :: Kbb, Kmm
-      WRITE(*,*) 'cice_sbc_init: You should not have seen this print! error?', ksbc
-   END SUBROUTINE cice_sbc_init
-
-   SUBROUTINE cice_sbc_final     ! Dummy routine
-      IMPLICIT NONE
-      WRITE(*,*) 'cice_sbc_final: You should not have seen this print! error?'
-   END SUBROUTINE cice_sbc_final
-
-#endif
-
-   !!======================================================================
-END MODULE sbcice_cice
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/step.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/step.F90	(revision 14059)
+++ 	(revision )
@@ -1,322 +1,0 @@
-MODULE step
-   !!======================================================================
-   !!                       ***  MODULE step  ***
-   !! Time-stepping   : manager of the shallow water equation time stepping
-   !!======================================================================
-   !! History :  NEMO !  2020-03  (A. Nasser, G. Madec)  Original code from  4.0.2
-   !!----------------------------------------------------------------------
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-#else
-   !!----------------------------------------------------------------------
-   !!   stp             : Shallow Water time-stepping
-   !!----------------------------------------------------------------------
-   USE step_oce         ! time stepping definition modules
-   USE phycst           ! physical constants
-   USE usrdef_nam
-   !
-   USE iom              ! xIOs server 
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   stp   ! called by nemogcm.F90
-   
-   !!----------------------------------------------------------------------
-   !! time level indices
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !! used by nemo_init
-      
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: step.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_agrif
-   RECURSIVE SUBROUTINE stp( )
-      INTEGER             ::   kstp   ! ocean time-step index
-#else
-   SUBROUTINE stp( kstp )
-      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
-#endif
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE stp  ***
-      !!
-      !! ** Purpose : - Time stepping of shallow water (SHW) (momentum and ssh eqs.)
-      !!
-      !! ** Method  : -1- Update forcings
-      !!              -2- Update the ssh at Naa
-      !!              -3- Compute the momentum trends (Nrhs)
-      !!              -4- Update the horizontal velocity
-      !!              -5- Apply Asselin time filter to uu,vv,ssh
-      !!              -6- Outputs and diagnostics
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indice
-      INTEGER ::   indic        ! error indicator if < 0
-!!gm kcall can be removed, I guess
-      INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
-      REAL(wp)::   z1_2rho0     ! local scalars
-      
-      REAL(wp) ::   zue3a, zue3n, zue3b    ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b    !   -      -
-      REAL(wp) ::   ze3t_tf, ze3u_tf, ze3v_tf, zua, zva
-      !! ---------------------------------------------------------------------
-#if defined key_agrif
-      kstp = nit000 + Agrif_Nb_Step()
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      IF( lk_agrif_debug ) THEN
-         IF( Agrif_Root() .and. lwp)   WRITE(*,*) '---'
-         IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
-      ENDIF
-      IF( kstp == nit000 + 1 )   lk_agrif_fstep = .FALSE.
-# if defined key_iomput
-      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
-# endif
-#endif
-      !
-      IF( ln_timing )   CALL timing_start('stp')
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! model timestep
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !
-      IF( l_1st_euler ) THEN     ! start or restart with Euler 1st time-step
-         rDt   =  rn_Dt   
-         r1_Dt = 1._wp / rDt
-      ENDIF
-
-      IF ( kstp == nit000 )   ww(:,:,:) = 0._wp   ! initialize vertical velocity one for all to zero
-
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! update I/O and calendar 
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             indic = 0                ! reset to no error condition
-                             
-      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
-                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
-         IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
-                             CALL iom_init_closedef
-         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
-      ENDIF
-      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
-                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
-      IF( ln_crs         )   CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" )   ! tell IOM we are at time step kstp
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update external forcing (tides, open boundaries, ice shelf interaction and surface boundary condition (including sea-ice)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_tide    )   CALL tide_update( kstp )                     ! update tide potential
-      IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                        ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib) 
-      IF( ln_bdy     )   CALL bdy_dta ( kstp, Nnn )                   ! update dynamic & tracer data at open boundaries
-                         CALL sbc     ( kstp, Nbb, Nnn )              ! Sea Boundary Condition
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !  LATERAL  PHYSICS
-      !                                                                        ! eddy diffusivity coeff.
-      IF( l_ldfdyn_time )   CALL ldf_dyn( kstp, Nbb )                          ! eddy viscosity coeff. 
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  Ocean dynamics : hdiv, ssh, e3, u, v, w
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh, Naa )    ! after ssh (includes call to div_hor)
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-      IF( .NOT.ln_linssh )  CALL dom_vvl_sf_nxt( kstp, Nbb, Nnn,      Naa )    ! after vertical scale factors 
-
-      IF( ln_bdy     )      CALL bdy_dyn3d_dmp ( kstp, Nbb,      uu, vv, Nrhs )  ! bdy damping trends
-
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())  & 
-               &            CALL Agrif_Sponge_dyn        ! momentum sponge
-#endif
-                            CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
- 
-                            CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
- 
-                            CALL dyn_ldf( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! lateral mixing
-
-!!an - calcul du gradient de pression horizontal (explicit)
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
-      END_3D
-      !
-      ! add wind stress forcing and layer linear friction to the RHS 
-      z1_2rho0 = 0.5_wp * r1_rho0
-      DO_3D( 0, 0, 0, 0,1,jpkm1)
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + z1_2rho0 * ( utau_b(ji,jj) + utau(ji,jj) ) / e3u(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + z1_2rho0 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
-      END_3D   
-!!an         
-  
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Leap-Frog time splitting + Robert-Asselin time filter on u,v,e3 
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-          
-!! what about  IF( .NOT.ln_linssh )  ?
-!!an futur module dyn_nxt (a la place de dyn_atf)
-      
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
-         IF( l_1st_euler ) THEN           ! Euler time stepping (no Asselin filter)
-            DO_3D( 0, 0, 0, 0,1,jpkm1)
-               uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-             END_3D          
-         ELSE                             ! Leap Frog time stepping + Asselin filter         
-            DO_3D( 1, 1, 1, 1,1,jpkm1)
-               zua = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zva = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !                                                                  ! Asselin time filter on u,v (Nnn)
-               uu(ji,jj,jk,Nnn) = uu(ji,jj,jk,Nnn) + rn_atfp * (uu(ji,jj,jk,Nbb) - 2._wp * uu(ji,jj,jk,Nnn) + zua)
-               vv(ji,jj,jk,Nnn) = vv(ji,jj,jk,Nnn) + rn_atfp * (vv(ji,jj,jk,Nbb) - 2._wp * vv(ji,jj,jk,Nnn) + zva)
-               !
-               ze3u_tf = e3u(ji,jj,jk,Nnn) + rn_atfp * ( e3u(ji,jj,jk,Nbb) - 2._wp * e3u(ji,jj,jk,Nnn)  + e3u(ji,jj,jk,Naa) )
-               ze3v_tf = e3v(ji,jj,jk,Nnn) + rn_atfp * ( e3v(ji,jj,jk,Nbb) - 2._wp * e3v(ji,jj,jk,Nnn)  + e3v(ji,jj,jk,Naa) )
-               ze3t_tf = e3t(ji,jj,jk,Nnn) + rn_atfp * ( e3t(ji,jj,jk,Nbb) - 2._wp * e3t(ji,jj,jk,Nnn)  + e3t(ji,jj,jk,Naa) )
-               !
-               e3u(ji,jj,jk,Nnn) = ze3u_tf
-               e3v(ji,jj,jk,Nnn) = ze3v_tf
-               e3t(ji,jj,jk,Nnn) = ze3t_tf
-               !              
-               uu(ji,jj,jk,Naa) = zua
-               vv(ji,jj,jk,Naa) = zva
-            END_3D
-         ENDIF
-         !
-      ELSE                          ! flux form : applied on thickness weighted velocity
-         IF( l_1st_euler ) THEN           ! Euler time stepping (no Asselin filter)
-            DO_3D( 0, 0, 0, 0,1,jpkm1)
-               zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
-               zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-               !                                                ! LF time stepping
-               zue3a = zue3b + rDt * e3u(ji,jj,jk,Nrhs) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zve3a = zve3b + rDt * e3v(ji,jj,jk,Nrhs) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !
-               uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
-               vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
-            END_3D
-         ELSE                             ! Leap Frog time stepping + Asselin filter
-            DO_3D( 1, 1, 1, 1,1,jpkm1)
-               zue3n = e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nnn)
-               zve3n = e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nnn)
-               zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
-               zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-               !                                                ! LF time stepping
-               zue3a = zue3b + rDt * e3u(ji,jj,jk,Nrhs) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zve3a = zve3b + rDt * e3v(ji,jj,jk,Nrhs) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !                                                ! Asselin time filter on e3u/v/t
-               ze3u_tf = e3u(ji,jj,jk,Nnn) + rn_atfp * ( e3u(ji,jj,jk,Nbb) - 2._wp * e3u(ji,jj,jk,Nnn)  + e3u(ji,jj,jk,Naa) ) 
-               ze3v_tf = e3v(ji,jj,jk,Nnn) + rn_atfp * ( e3v(ji,jj,jk,Nbb) - 2._wp * e3v(ji,jj,jk,Nnn)  + e3v(ji,jj,jk,Naa) )
-               ze3t_tf = e3t(ji,jj,jk,Nnn) + rn_atfp * ( e3t(ji,jj,jk,Nbb) - 2._wp * e3t(ji,jj,jk,Nnn)  + e3t(ji,jj,jk,Naa) ) 
-               !                                                ! Asselin time filter on u,v (Nnn)
-               uu(ji,jj,jk,Nnn) = ( zue3n + rn_atfp * ( zue3b - 2._wp * zue3n  + zue3a ) ) / ze3u_tf
-               vv(ji,jj,jk,Nnn) = ( zve3n + rn_atfp * ( zve3b - 2._wp * zve3n  + zve3a ) ) / ze3v_tf
-               !
-               e3u(ji,jj,jk,Nnn) = ze3u_tf
-               e3v(ji,jj,jk,Nnn) = ze3v_tf
-               e3t(ji,jj,jk,Nnn) = ze3t_tf
-               !
-               uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
-               vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
-            END_3D       
-         ENDIF
-      ENDIF
-
-
-      CALL lbc_lnk_multi( 'stp', uu(:,:,:,Nnn), 'U', -1., vv(:,:,:,Nnn), 'V', -1.,   &   !* local domain boundaries
-         &                       uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1.    )     
-
-!!an         
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Set boundary conditions, time filter and swap time levels
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-!!an TO BE ADDED : dyn_nxt
-!!                         CALL dyn_atf       ( kstp, Nbb, Nnn, Naa, uu, vv, e3t, e3u, e3v  )  ! time filtering of "now" velocities and scale factors
-!!an TO BE ADDED : a simplifier
-!!                         CALL ssh_atf       ( kstp, Nbb, Nnn, Naa, ssh )                     ! time filtering of "now" sea surface height
-      IF ( .NOT.( l_1st_euler ) ) THEN   ! Only do time filtering for leapfrog timesteps
-         !                                                  ! filtering "now" field
-         ssh(:,:,Nnn) = ssh(:,:,Nnn) + rn_atfp * ( ssh(:,:,Nbb) - 2 * ssh(:,:,Nnn) + ssh(:,:,Naa) )
-      ENDIF
-!!an 
-
-
-      ! Swap time levels
-      Nrhs = Nbb
-      Nbb = Nnn
-      Nnn = Naa
-      Naa = Nrhs
-      !
-                         CALL dom_vvl_sf_update( kstp, Nbb, Nnn, Naa )  ! recompute vertical scale factors
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_floats  )   CALL flo_stp   ( kstp, Nbb, Nnn )      ! drifting Floats
-      IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
-    
-                         CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
-      !
-      IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
-          
-
-#if defined key_agrif
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! AGRIF
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
-                         Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs      ! agrif_oce module copies of time level indices
-                         CALL Agrif_Integrate_ChildGrids( stp )       ! allows to finish all the Child Grids before updating
-
-                         IF( Agrif_NbStepint() == 0 ) THEN
-                            CALL Agrif_update_all( )                  ! Update all components
-                         ENDIF
-#endif
-      IF( ln_diaobs  )   CALL dia_obs      ( kstp, Nnn )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Control
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nnn )
-               
-                         
-      IF( kstp == nit000 ) THEN                          ! 1st time step only
-                                        CALL iom_close( numror )   ! close input  ocean restart file
-         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
-         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
-      ENDIF
-
-      !
-#if defined key_iomput
-      IF( kstp == nitend .OR. indic < 0 ) THEN 
-                      CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-                      IF(lrxios) CALL iom_context_finalize(      cr_ocerst_cxt          )
-      ENDIF
-#endif
-      !
-      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
-         rDt = 2._wp * rn_Dt   
-         r1_Dt = 1._wp / rDt
-         l_1st_euler = .FALSE.      
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('stp')
-      !
-   END SUBROUTINE stp
-#endif
-   !
-   !!======================================================================
-END MODULE step
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stepLF.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stepLF.F90	(revision 14059)
+++ 	(revision )
@@ -1,335 +1,0 @@
-MODULE stpLF
-   !!======================================================================
-   !!                       ***  MODULE step  ***
-   !! Time-stepping   : manager of the shallow water equation time stepping
-   !!======================================================================
-   !! History :  NEMO !  2020-03  (A. Nasser, G. Madec)  Original code from  4.0.2
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   stp             : Shallow Water time-stepping
-   !!----------------------------------------------------------------------
-   USE step_oce         ! time stepping definition modules
-   USE phycst           ! physical constants
-   USE usrdef_nam
-   !
-   USE iom              ! xIOs server 
-   USE domqco
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   stp_LF   ! called by nemogcm.F90
-   
-   !!----------------------------------------------------------------------
-   !! time level indices
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !! used by nemo_init
-      
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: step.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_agrif
-   RECURSIVE SUBROUTINE stp_LF( )
-      INTEGER             ::   kstp   ! ocean time-step index
-#else
-   SUBROUTINE stp_LF( kstp )
-      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
-#endif
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE stp  ***
-      !!
-      !! ** Purpose : - Time stepping of shallow water (SHW) (momentum and ssh eqs.)
-      !!
-      !! ** Method  : -1- Update forcings
-      !!              -2- Update the ssh at Naa
-      !!              -3- Compute the momentum trends (Nrhs)
-      !!              -4- Update the horizontal velocity
-      !!              -5- Apply Asselin time filter to uu,vv,ssh
-      !!              -6- Outputs and diagnostics
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indice
-      INTEGER ::   indic        ! error indicator if < 0
-!!gm kcall can be removed, I guess
-      INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
-      REAL(wp)::   z1_2rho0     ! local scalars
-      
-      REAL(wp) ::   zue3a, zue3n, zue3b    ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b    !   -      -
-      REAL(wp) ::   ze3t_tf, ze3u_tf, ze3v_tf, zua, zva
-      !! ---------------------------------------------------------------------
-#if defined key_agrif
-      kstp = nit000 + Agrif_Nb_Step()
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      IF( lk_agrif_debug ) THEN
-         IF( Agrif_Root() .and. lwp)   WRITE(*,*) '---'
-         IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
-      ENDIF
-      IF( kstp == nit000 + 1 )   lk_agrif_fstep = .FALSE.
-# if defined key_iomput
-      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
-# endif
-#endif
-      !
-      IF( ln_timing )   CALL timing_start('stp_LF')
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! model timestep
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !
-      IF( l_1st_euler ) THEN     ! start or restart with Euler 1st time-step
-         rDt   =  rn_Dt   
-         r1_Dt = 1._wp / rDt
-      ENDIF
-
-      IF ( kstp == nit000 )   ww(:,:,:) = 0._wp   ! initialize vertical velocity one for all to zero
-
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! update I/O and calendar 
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             indic = 0                ! reset to no error condition
-                             
-      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
-                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
-         IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
-                             CALL iom_init_closedef
-         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
-      ENDIF
-      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
-                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
-      IF( ln_crs         )   CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" )   ! tell IOM we are at time step kstp
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update external forcing (tides, open boundaries, ice shelf interaction and surface boundary condition (including sea-ice)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_tide    )   CALL tide_update( kstp )                     ! update tide potential
-      IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                        ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib) 
-      IF( ln_bdy     )   CALL bdy_dta ( kstp, Nnn )                   ! update dynamic & tracer data at open boundaries
-                         CALL sbc     ( kstp, Nbb, Nnn )              ! Sea Boundary Condition
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !  LATERAL  PHYSICS
-      !                                                                        ! eddy diffusivity coeff.
-      IF( l_ldfdyn_time )   CALL ldf_dyn( kstp, Nbb )                          ! eddy viscosity coeff. 
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  Ocean dynamics : hdiv, ssh, e3, u, v, w
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh, Naa )    ! after ssh (includes call to div_hor)
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-      IF( ln_bdy     )      CALL bdy_dyn3d_dmp ( kstp, Nbb,      uu, vv, Nrhs )  ! bdy damping trends
-
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())  & 
-               &            CALL Agrif_Sponge_dyn        ! momentum sponge
-#endif
-                            CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
- 
-                            CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
- 
-                            CALL dyn_ldf( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! lateral mixing
-
-      IF( .NOT.ln_linssh )  CALL dom_qco_r3c   ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio explicit
-      !IF( .NOT.ln_linssh )  CALL dom_vvl_sf_nxt_st( kstp, Nbb, Nnn,      Naa )    ! after vertical scale factors 
-!!an - calcul du gradient de pression horizontal (explicit)
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
-      END_3D
-      !
-      ! add wind stress forcing and layer linear friction to the RHS 
-      z1_2rho0 = 0.5_wp * r1_rho0
-      DO_3D( 0, 0, 0, 0,1,jpkm1)
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + z1_2rho0 * ( utau_b(ji,jj) + utau(ji,jj) ) / e3u(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + z1_2rho0 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
-      END_3D   
-!!an         
-  
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Leap-Frog time splitting + Robert-Asselin time filter on u,v,e3 
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-!!st ssh_atf : add ssh filtering up there
-      IF ( .NOT.( l_1st_euler ) ) THEN   ! Only do time filtering for leapfrog timesteps
-         !                                                  ! filtering "now" field
-         ssh(:,:,Nnn) = ssh(:,:,Nnn) + rn_atfp * ( ssh(:,:,Nbb) - 2._wp * ssh(:,:,Nnn) + ssh(:,:,Naa) )
-      ENDIF
-!!st ssh_atf
-          
-!! what about  IF( .NOT.ln_linssh )  ?
-!!an futur module dyn_nxt (a la place de dyn_atf)
-      
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
-         IF( l_1st_euler ) THEN           ! Euler time stepping (no Asselin filter)
-            DO_3D( 0, 0, 0, 0,1,jpkm1)
-               uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-             END_3D          
-         ELSE                             ! Leap Frog time stepping + Asselin filter         
-            DO_3D( 1, 1, 1, 1,1,jpkm1)
-               zua = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zva = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !                                                                  ! Asselin time filter on u,v (Nnn)
-               uu(ji,jj,jk,Nnn) = uu(ji,jj,jk,Nnn) + rn_atfp * (uu(ji,jj,jk,Nbb) - 2._wp * uu(ji,jj,jk,Nnn) + zua)
-               vv(ji,jj,jk,Nnn) = vv(ji,jj,jk,Nnn) + rn_atfp * (vv(ji,jj,jk,Nbb) - 2._wp * vv(ji,jj,jk,Nnn) + zva)
-               !              
-               uu(ji,jj,jk,Naa) = zua
-               vv(ji,jj,jk,Naa) = zva
-            END_3D
-            CALL dom_qco_r3c( ssh(:,:,Nnn), r3t(:,:,Nnn), r3u(:,:,Nnn), r3v(:,:,Nnn) )   ! "now" ssh/h_0 ratio from filtrered ssh
-#if ! defined key_qco
-            DO jk = 1, jpkm1
-               e3t(:,:,jk,Nnn) = e3t_0(:,:,jk) * ( 1._wp + r3t(:,:,Nnn) )
-               e3u(:,:,jk,Nnn) = e3u_0(:,:,jk) * ( 1._wp + r3u(:,:,Nnn) )
-               e3v(:,:,jk,Nnn) = e3v_0(:,:,jk) * ( 1._wp + r3v(:,:,Nnn) )
-            END DO
-#endif
-         ENDIF
-         !
-      ELSE                          ! flux form : applied on thickness weighted velocity
-         IF( l_1st_euler ) THEN           ! Euler time stepping (no Asselin filter)
-            DO_3D( 0, 0, 0, 0,1,jpkm1)
-               zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
-               zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-               !                                                ! LF time stepping
-               zue3a = zue3b + rDt * e3u(ji,jj,jk,Nrhs) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zve3a = zve3b + rDt * e3v(ji,jj,jk,Nrhs) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !
-               uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
-               vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
-            END_3D
-         ELSE                             ! Leap Frog time stepping + Asselin filter
-            CALL dom_qco_r3c( ssh(:,:,Nnn), r3t_f(:,:), r3u_f(:,:), r3v_f(:,:) )   ! "now" ssh/h_0 ratio from filtrered ssh
-            DO_3D( 1, 1, 1, 1,1,jpkm1)
-               zue3n = e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nnn)
-               zve3n = e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nnn)
-               zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
-               zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-               !                                                ! LF time stepping
-               zue3a = zue3b + rDt * e3u(ji,jj,jk,Nrhs) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-               zve3a = zve3b + rDt * e3v(ji,jj,jk,Nrhs) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-               !                                                ! Asselin time filter on e3u/v/t
-               ze3u_tf = e3u(ji,jj,jk,Nnn) + rn_atfp * ( e3u(ji,jj,jk,Nbb) - 2._wp * e3u(ji,jj,jk,Nnn)  + e3u(ji,jj,jk,Naa) ) 
-               ze3v_tf = e3v(ji,jj,jk,Nnn) + rn_atfp * ( e3v(ji,jj,jk,Nbb) - 2._wp * e3v(ji,jj,jk,Nnn)  + e3v(ji,jj,jk,Naa) )
-               ze3t_tf = e3t(ji,jj,jk,Nnn) + rn_atfp * ( e3t(ji,jj,jk,Nbb) - 2._wp * e3t(ji,jj,jk,Nnn)  + e3t(ji,jj,jk,Naa) ) 
-               !                                                ! Asselin time filter on u,v (Nnn)
-               uu(ji,jj,jk,Nnn) = ( zue3n + rn_atfp * ( zue3b - 2._wp * zue3n  + zue3a ) ) / (e3u_0(ji,jj,jk) * ( 1._wp + r3u_f(ji,jj) ))
-               vv(ji,jj,jk,Nnn) = ( zve3n + rn_atfp * ( zve3b - 2._wp * zve3n  + zve3a ) ) / (e3v_0(ji,jj,jk) * ( 1._wp + r3v_f(ji,jj) ))
-               !
-               uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
-               vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
-            END_3D
-            r3t(:,:,Nnn) = r3t_f(:,:)
-            r3u(:,:,Nnn) = r3u_f(:,:)
-            r3v(:,:,Nnn) = r3v_f(:,:)
-#if ! defined key_qco
-            DO jk = 1, jpkm1
-               e3t(:,:,jk,Nnn) = e3t_0(:,:,jk) * ( 1._wp + r3t(:,:,Nnn) )
-               e3u(:,:,jk,Nnn) = e3u_0(:,:,jk) * ( 1._wp + r3u(:,:,Nnn) )
-               e3v(:,:,jk,Nnn) = e3v_0(:,:,jk) * ( 1._wp + r3v(:,:,Nnn) )
-            END DO
-#endif         
-         ENDIF
-      ENDIF
-
-
-      CALL lbc_lnk_multi( 'stp', uu(:,:,:,Nnn), 'U', -1., vv(:,:,:,Nnn), 'V', -1.,   &   !* local domain boundaries
-         &                       uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1.    )     
-
-!!an         
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Set boundary conditions, time filter and swap time levels
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-
-!!an TO BE ADDED : dyn_nxt
-!!                         CALL dyn_atf       ( kstp, Nbb, Nnn, Naa, uu, vv, e3t, e3u, e3v  )  ! time filtering of "now" velocities and scale factors
-!!an TO BE ADDED : a simplifier
-!                         CALL ssh_atf       ( kstp, Nbb, Nnn, Naa, ssh )                     ! time filtering of "now" sea surface height
-!!st copied above 
-!!      IF ( .NOT.( l_1st_euler ) ) THEN   ! Only do time filtering for leapfrog timesteps
-!!         !                                                  ! filtering "now" field
-!!         ssh(:,:,Nnn) = ssh(:,:,Nnn) + rn_atfp * ( ssh(:,:,Nbb) - 2 * ssh(:,:,Nnn) + ssh(:,:,Naa) )
-!!      ENDIF
-!!st      
-!!an 
-
-
-      ! Swap time levels
-      Nrhs = Nbb
-      Nbb = Nnn
-      Nnn = Naa
-      Naa = Nrhs
-      !
-!                         CALL dom_vvl_sf_update_st( kstp, Nbb, Nnn, Naa )  ! recompute vertical scale factors
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_floats  )   CALL flo_stp   ( kstp, Nbb, Nnn )      ! drifting Floats
-      IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
-    
-                         CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
-
-      !
-      IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
-          
-
-#if defined key_agrif
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! AGRIF
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
-                         Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs      ! agrif_oce module copies of time level indices
-                         CALL Agrif_Integrate_ChildGrids( stp_LF )       ! allows to finish all the Child Grids before updating
-
-                         IF( Agrif_NbStepint() == 0 ) THEN
-                            CALL Agrif_update_all( )                  ! Update all components
-                         ENDIF
-#endif
-      IF( ln_diaobs  )   CALL dia_obs      ( kstp, Nnn )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Control
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nbb, Nnn, indic )
-               
-                         
-      IF( kstp == nit000 ) THEN                          ! 1st time step only
-                                        CALL iom_close( numror )   ! close input  ocean restart file
-         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
-         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
-      ENDIF
-
-      !
-#if defined key_iomput
-      IF( kstp == nitend .OR. indic < 0 ) THEN 
-                      CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-                      IF(lrxios) CALL iom_context_finalize(      cr_ocerst_cxt          )
-      ENDIF
-#endif
-      !
-      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
-         rDt = 2._wp * rn_Dt   
-         r1_Dt = 1._wp / rDt
-         l_1st_euler = .FALSE.      
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('stp')
-      !
-   END SUBROUTINE stp_LF
-   !
-   !!======================================================================
-END MODULE stpLF
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpRK3.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpRK3.F90	(revision 14059)
+++ 	(revision )
@@ -1,378 +1,0 @@
-MODULE stpRK3
-   !!======================================================================
-   !!                       ***  MODULE step  ***
-   !! Time-stepping   : manager of the shallow water equation time stepping
-   !!======================================================================
-   !! History :  NEMO !  2020-03  (A. Nasser, G. Madec)  Original code from  4.0.2
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   stpRK3             : Shallow Water time-stepping
-   !!----------------------------------------------------------------------
-   USE step_oce         ! time stepping definition modules
-   USE phycst           ! physical constants
-   USE usrdef_nam
-   !
-   USE iom              ! xIOs server 
-   USE domqco
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   stp_RK3   ! called by nemogcm.F90
-   
-   !!----------------------------------------------------------------------
-   !! time level indices
-   !!----------------------------------------------------------------------
-   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !! used by nemo_init
-      
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id: step.F90 12614 2020-03-26 14:59:52Z gm $
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-#if defined key_agrif
-   RECURSIVE SUBROUTINE stp_RK3( )
-      INTEGER             ::   kstp   ! ocean time-step index
-#else
-   SUBROUTINE stp_RK3( kstp )
-      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
-#endif
-      !!----------------------------------------------------------------------
-      !!                     ***  ROUTINE stp_RK3  ***
-      !!
-      !! ** Purpose : - Time stepping of shallow water (SHW) (momentum and ssh eqs.)
-      !!
-      !! ** Method  : -1- Update forcings
-      !!              -2- Update the ssh at Naa
-      !!              -3- Compute the momentum trends (Nrhs)
-      !!              -4- Update the horizontal velocity
-      !!              -5- Apply Asselin time filter to uu,vv,ssh
-      !!              -6- Outputs and diagnostics
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk   ! dummy loop indice
-      INTEGER ::   indic        ! error indicator if < 0
-!!gm kcall can be removed, I guess
-      INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
-      REAL(wp)::   z1_2rho0,  z5_6,  z3_4  ! local scalars
-      
-      REAL(wp) ::   zue3a, zue3n, zue3b    ! local scalars
-      REAL(wp) ::   zve3a, zve3n, zve3b    !   -      -
-      REAL(wp) ::   ze3t_tf, ze3u_tf, ze3v_tf, zua, zva
-      !! ---------------------------------------------------------------------
-#if defined key_agrif
-      kstp = nit000 + Agrif_Nb_Step()
-      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
-      IF( lk_agrif_debug ) THEN
-         IF( Agrif_Root() .and. lwp)   WRITE(*,*) '---'
-         IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
-      ENDIF
-      IF( kstp == nit000 + 1 )   lk_agrif_fstep = .FALSE.
-# if defined key_iomput
-      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap( cxios_context )
-# endif
-#endif
-      !
-      IF( ln_timing )   CALL timing_start('stp_RK3')
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! model timestep
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !
-      IF ( kstp == nit000 )   ww(:,:,:) = 0._wp   ! initialize vertical velocity one for all to zero
-
-      !
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! update I/O and calendar 
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             indic = 0                ! reset to no error condition
-                             
-      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
-                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
-         IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
-                             CALL iom_init_closedef
-         IF( ln_crs      )   CALL iom_init( TRIM(cxios_context)//"_crs" )  ! for coarse grid
-      ENDIF
-      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
-                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
-      IF( ln_crs         )   CALL iom_setkt( kstp - nit000 + 1, TRIM(cxios_context)//"_crs" )   ! tell IOM we are at time step kstp
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Update external forcing (tides, open boundaries, ice shelf interaction and surface boundary condition (including sea-ice)
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_tide    )   CALL tide_update( kstp )                     ! update tide potential
-      IF( ln_apr_dyn )   CALL sbc_apr ( kstp )                        ! atmospheric pressure (NB: call before bdy_dta which needs ssh_ib) 
-      IF( ln_bdy     )   CALL bdy_dta ( kstp, Nnn )                   ! update dynamic & tracer data at open boundaries
-                         CALL sbc     ( kstp, Nbb, Nnn )              ! Sea Boundary Condition
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Ocean physics update
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      !  LATERAL  PHYSICS
-      !                                                                        ! eddy diffusivity coeff.
-      IF( l_ldfdyn_time )   CALL ldf_dyn( kstp, Nbb )                          ! eddy viscosity coeff. 
-
-
-      !======================================================================
-      !======================================================================
-      !                     =====       RK3       =====
-      !======================================================================
-      !======================================================================
-
-      
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  RK3 1st stage Ocean dynamics : hdiv, ssh, e3, u, v, w
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      rDt   = rn_Dt / 3._wp  
-      r1_Dt = 1._wp / rDt
-      
-                            CALL ssh_nxt       ( kstp, Nbb, Nbb, ssh, Naa )    ! after ssh (includes call to div_hor)
-
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-                            CALL dyn_adv( kstp, Nbb, Nbb      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
- 
-                            CALL dyn_vor( kstp,      Nbb      , uu, vv, Nrhs )  ! vorticity           	==> RHS
-#if defined key_RK3all 
-                            CALL dyn_ldf( kstp, Nbb, Nbb      , uu, vv, Nrhs )  ! lateral mixing
-#endif
-      !
-!!an - calcul du gradient de pression horizontal (explicit)
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nbb) - ssh(ji,jj,Nbb) ) * r1_e1u(ji,jj)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nbb) - ssh(ji,jj,Nbb) ) * r1_e2v(ji,jj)
-      END_3D
-      !
-#if defined key_RK3all 
-      ! add wind stress forcing and layer linear friction to the RHS 
-      z5_6 = 5._wp/6._wp
-      DO_3D( 0, 0, 0, 0,1,jpkm1)
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + r1_rho0 * ( z5_6*utau_b(ji,jj) + (1._wp - z5_6)*utau(ji,jj) ) / e3u(ji,jj,jk,Nbb)   &
-            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + r1_rho0 * ( z5_6*vtau_b(ji,jj) + (1._wp - z5_6)*vtau(ji,jj) ) / e3v(ji,jj,jk,Nbb)   &
-            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
-      END_3D
-#endif
-!!an
-                            CALL dom_qco_r3c   ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio explicit
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
-         DO_3D( 0, 0, 0, 0,1,jpkm1)
-            uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-            vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-         END_3D          
-      ELSE
-         DO_3D( 0, 0, 0, 0,1,jpkm1)       ! flux form : applied on thickness weighted velocity
-            uu(ji,jj,jk,Naa) = (         uu(ji,jj,jk,Nbb )*e3u(ji,jj,jk,Nbb)                              &
-               &                 + rDt * uu(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nbb) * umask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
-            vv(ji,jj,jk,Naa) = (         vv(ji,jj,jk,Nbb )*e3v(ji,jj,jk,Nbb)                              &
-               &                 + rDt * vv(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nbb) * vmask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
-         END_3D
-      ENDIF
-      ! Swap time levels
-      Nrhs= Nnn
-      Nnn = Naa
-      Naa = Nrhs
-
-      
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  RK3 2nd stage Ocean dynamics : hdiv, ssh, e3, u, v, w
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      rDt   = rn_Dt / 2._wp  
-      r1_Dt = 1._wp / rDt
-      
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh, Naa )    ! after ssh (includes call to div_hor)
-
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-!!st TBC for dyn_adv
-                            CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS 
- 
-                            CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
-#if defined key_RK3all  
-                            CALL dyn_ldf( kstp, Nbb, Nbb      , uu, vv, Nrhs )  ! lateral mixing
-#endif
-                            
-      !
-!!an - calcul du gradient de pression horizontal (explicit)
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
-      END_3D
-      !
-      ! add wind stress forcing and layer linear friction to the RHS 
-#if defined key_RK3all
-      z3_4 = 3._wp/4._wp
-      DO_3D( 0, 0, 0, 0,1,jpkm1)
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + r1_rho0 * ( z3_4*utau_b(ji,jj) + (1._wp - z3_4)*utau(ji,jj) ) / e3u(ji,jj,jk,Nbb)   &
-            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + r1_rho0 * ( z3_4*vtau_b(ji,jj) + (1._wp - z3_4)*vtau(ji,jj) ) / e3v(ji,jj,jk,Nbb)   &
-            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
-      END_3D
-#endif
-!!an
-                           CALL dom_qco_r3c   ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio explicit
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
-         DO_3D( 0, 0, 0, 0,1,jpkm1)
-            uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-            vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-         END_3D          
-      ELSE
-         DO_3D( 0, 0, 0, 0,1,jpkm1)       ! flux form : applied on thickness weighted velocity
-            uu(ji,jj,jk,Naa) = (         uu(ji,jj,jk,Nbb )*e3u(ji,jj,jk,Nbb)                              &
-               &                 + rDt * uu(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nnn) * umask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
-            vv(ji,jj,jk,Naa) = (         vv(ji,jj,jk,Nbb )*e3v(ji,jj,jk,Nbb)                              &
-               &                 + rDt * vv(ji,jj,jk,Nrhs)*e3t(ji,jj,jk,Nnn) * vmask(ji,jj,jk)        )   &
-               &               /                           e3t(ji,jj,jk,Naa)
-         END_3D
-      ENDIF
-      ! Swap time levels
-      Nrhs= Nnn
-      Nnn = Naa
-      Naa = Nrhs
-       
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      !  RK3 3rd stage Ocean dynamics : hdiv, ssh, e3, u, v, w
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      rDt   = rn_Dt
-      r1_Dt = 1._wp / rDt
-
-                            CALL ssh_nxt       ( kstp, Nbb, Nnn, ssh, Naa )    ! after ssh (includes call to div_hor)
-      
-                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
-                         vv(:,:,:,Nrhs) = 0._wp
-
-      IF( ln_bdy     )      CALL bdy_dyn3d_dmp ( kstp, Nbb,      uu, vv, Nrhs )  ! bdy damping trends
-
-#if defined key_agrif
-      IF(.NOT. Agrif_Root())  & 
-               &            CALL Agrif_Sponge_dyn        ! momentum sponge
-#endif
-                            CALL dyn_adv( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
- 
-                            CALL dyn_vor( kstp,      Nnn      , uu, vv, Nrhs )  ! vorticity           	==> RHS
- 
-                            CALL dyn_ldf( kstp, Nbb, Nnn      , uu, vv, Nrhs )  ! lateral mixing
-
-!!an - calcul du gradient de pression horizontal (explicit)
-      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
-      END_3D
-      !
-      ! add wind stress forcing and layer linear friction to the RHS 
-      z1_2rho0 = 0.5_wp * r1_rho0
-      DO_3D( 0, 0, 0, 0,1,jpkm1)
-         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + z1_2rho0 * ( utau_b(ji,jj) + utau(ji,jj) ) / e3u(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
-         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + z1_2rho0 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
-            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
-      END_3D   
-!!an         
-                            CALL dom_qco_r3c   ( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )   ! "after" ssh./h._0 ratio explicit      
-      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
-         DO_3D( 1, 1, 1, 1,1,jpkm1)
-            zua = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-            zva = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-            !                                                                  ! Asselin time filter on u,v (Nnn)
-            uu(ji,jj,jk,Nnn) = uu(ji,jj,jk,Nnn) + rn_atfp * (uu(ji,jj,jk,Nbb) - 2._wp * uu(ji,jj,jk,Nnn) + zua)
-            vv(ji,jj,jk,Nnn) = vv(ji,jj,jk,Nnn) + rn_atfp * (vv(ji,jj,jk,Nbb) - 2._wp * vv(ji,jj,jk,Nnn) + zva)
-            !              
-            uu(ji,jj,jk,Naa) = zua
-            vv(ji,jj,jk,Naa) = zva
-         END_3D
-         !
-      ELSE                          ! flux form : applied on thickness weighted velocity
-         DO_3D( 1, 1, 1, 1,1,jpkm1)
-            zue3n = e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nnn)
-            zve3n = e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nnn)
-            zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
-            zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
-            !                                                ! LF time stepping
-            zue3a = zue3b + rDt * e3t(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
-            zve3a = zve3b + rDt * e3t(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
-            !
-            uu(ji,jj,jk,Naa) = zue3a / e3t(ji,jj,jk,Naa)    
-            vv(ji,jj,jk,Naa) = zve3a / e3t(ji,jj,jk,Naa)
-         END_3D
-!!st je ne comprends pas l'histoire des e3t et du Nbb et pas du Nnn pour le rhs ?        
-      ENDIF
-
-
-      CALL lbc_lnk_multi( 'stp_RK3', uu(:,:,:,Nnn), 'U', -1., vv(:,:,:,Nnn), 'V', -1.,   &   !* local domain boundaries
-         &                       uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1.    )     
-
-!!an         
-
-
-      ! Swap time levels
-      Nrhs = Nbb
-      Nbb = Naa
-      Naa = Nrhs
-      !
-!                         CALL dom_vvl_sf_update_st( kstp, Nbb, Nnn, Naa )  ! recompute vertical scale factors
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! diagnostics and outputs
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-      IF( ln_floats  )   CALL flo_stp   ( kstp, Nbb, Nnn )      ! drifting Floats
-      IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
-    
-                         CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
-
-      !
-      IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
-          
-
-#if defined key_agrif
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! AGRIF
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      
-                         Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs      ! agrif_oce module copies of time level indices
-                         CALL Agrif_Integrate_ChildGrids( stp_RK3 )       ! allows to finish all the Child Grids before updating
-
-                         IF( Agrif_NbStepint() == 0 ) THEN
-                            CALL Agrif_update_all( )                  ! Update all components
-                         ENDIF
-#endif
-      IF( ln_diaobs  )   CALL dia_obs      ( kstp, Nnn )      ! obs-minus-model (assimilation) diagnostics (call after dynamics update)
-
-      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-      ! Control
-      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nbb, Nnn, indic )
-               
-                         
-      IF( kstp == nit000 ) THEN                          ! 1st time step only
-                                        CALL iom_close( numror )   ! close input  ocean restart file
-         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
-         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
-      ENDIF
-
-      !
-#if defined key_iomput
-      IF( kstp == nitend .OR. indic < 0 ) THEN 
-                      CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-                      IF(lrxios) CALL iom_context_finalize(      cr_ocerst_cxt          )
-      ENDIF
-#endif
-      !
-      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
-         rDt = 2._wp * rn_Dt   
-         r1_Dt = 1._wp / rDt
-         l_1st_euler = .FALSE.      
-      ENDIF
-      !
-      IF( ln_timing )   CALL timing_stop('stp_RK3')
-      !
-   END SUBROUTINE stp_RK3
-   !
-   !!======================================================================
-END MODULE stpRK3
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stp_oce.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stp_oce.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stp_oce.F90	(revision 14062)
@@ -0,0 +1,119 @@
+MODULE stp_oce
+   !!======================================================================
+   !!                       ***  MODULE stp_oce  ***
+   !! Ocean time-stepping : module used in both initialisation phase and time stepping
+   !!                                     (i.e. nemo_init and stp or stp_MLF routines)
+   !!======================================================================
+   !! History :   3.3  !  2010-08  (C. Ethe)  Original code - reorganisation of the initial phase
+   !!             3.7  !  2014-01  (G. Madec) LDF simplication 
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers variables
+   USE dom_oce         ! ocean space and time domain variables
+
+   USE daymod          ! calendar                         (day     routine)
+
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE sbcmod          ! surface boundary condition       (sbc     routine)
+   USE sbcrnf          ! surface boundary condition: runoff variables
+   USE sbccpl          ! surface boundary condition: coupled formulation (call send at end of step)
+   USE sbcapr          ! surface boundary condition: atmospheric pressure
+   USE sbcwave         ! Wave intialisation
+   USE tide_mod        ! tides
+
+   USE bdy_oce  , ONLY : ln_bdy
+   USE bdydta          ! open boundary condition data     (bdy_dta routine)
+   USE bdytra          ! bdy cond. for tracers            (bdy_tra routine)
+   USE bdydyn3d        ! bdy cond. for baroclinic vel.  (bdy_dyn3d routine)
+
+   USE isf_oce         ! ice shelf boundary condition
+   USE isfstp          ! ice shelf boundary condition     (isf_stp routine)
+
+   USE sshwzv          ! vertical velocity and ssh        (ssh_nxt routine)
+   !                                                      (ssh_swp routine)
+   !                                                      (wzv     routine)
+   USE domvvl          ! variable vertical scale factors  (dom_vvl_sf_nxt routine)
+   !                                                      (dom_vvl_sf_swp routine)
+   
+   USE divhor          ! horizontal divergence            (div_hor routine)
+   USE dynadv          ! advection                        (dyn_adv routine)
+   USE dynvor          ! vorticity term                   (dyn_vor routine)
+   USE dynhpg          ! hydrostatic pressure grad.       (dyn_hpg routine)
+   USE dynldf          ! lateral momentum diffusion       (dyn_ldf routine)
+   USE dynzdf          ! vertical diffusion               (dyn_zdf routine)
+   USE dynspg          ! surface pressure gradient        (dyn_spg routine)
+   USE dynatf          ! time-filtering                   (dyn_atf routine)
+
+   USE traqsr          ! solar radiation penetration      (tra_qsr routine)
+   USE traisf          ! ice shelf                        (tra_isf routine)
+   USE trasbc          ! surface boundary condition       (tra_sbc routine)
+   USE trabbc          ! bottom boundary condition        (tra_bbc routine)
+   USE trabbl          ! bottom boundary layer            (tra_bbl routine)
+   USE tradmp          ! internal damping                 (tra_dmp routine)
+   USE traadv          ! advection scheme control     (tra_adv_ctl routine)
+   USE traldf          ! lateral mixing                   (tra_ldf routine)
+   USE trazdf          ! vertical mixing                  (tra_zdf routine)
+   USE traatf          ! time filtering                   (tra_atf routine)
+   USE tranpc          ! non-penetrative convection       (tra_npc routine)
+
+   USE eosbn2          ! equation of state                (eos_bn2 routine)
+
+   USE stopar          ! Stochastic parametrization       (sto_par routine)
+   USE stopts 
+
+   USE ldfslp          ! iso-neutral slopes               (ldf_slp routine)
+   USE ldfdyn          ! lateral eddy viscosity coef.     (ldf_dyn routine)
+   USE ldftra          ! lateral eddy diffusive coef.     (ldf_tra routine)
+
+   USE zdf_oce         ! ocean vertical physics variables
+   USE zdfphy          ! vertical physics manager      (zdf_phy_init routine)
+   USE zdfdrg   , ONLY : ln_drgimp   ! implicit top/bottom friction
+   USE zdfosm   , ONLY : osm_rst, dyn_osm, tra_osm      ! OSMOSIS routines used in step.F90
+
+   USE diu_layers      ! diurnal SST bulk and coolskin routines
+   USE sbc_oce         ! surface fluxes  
+   
+   USE zpshde          ! partial step: hor. derivative     (zps_hde routine)
+
+   USE diawri          ! Standard run outputs             (dia_wri routine)
+   USE diaptr          ! poleward transports              (dia_ptr routine)
+   USE diadct          ! sections transports              (dia_dct routine)
+   USE diaar5          ! AR5 diagnosics                   (dia_ar5 routine)
+   USE diahth          ! thermocline depth                (dia_hth routine)
+   USE diahsb          ! heat, salt and volume budgets    (dia_hsb routine)
+   USE diacfl          ! CFL diagnostics                  (dia_cfl routine)
+   USE diaobs          ! Observation operator             (dia_obs routine)
+   USE diadetide       ! Weights computation for daily detiding of model diagnostics
+   USE diamlr          ! IOM context management for multiple-linear-regression analysis
+   USE flo_oce         ! floats variables
+   USE floats          ! floats computation               (flo_stp routine)
+
+   USE crsfld          ! Standard output on coarse grid   (crs_fld routine)
+
+   USE asminc          ! assimilation increments      (tra_asm_inc routine)
+   !                                                   (dyn_asm_inc routine)
+   USE asmbkg          ! writing out state trajectory
+   USE stpctl          ! time stepping control            (stp_ctl routine)
+   USE restart         ! ocean restart                    (rst_wri routine)
+   USE prtctl          ! Print control                    (prt_ctl routine)
+
+   USE in_out_manager  ! I/O manager
+   USE iom             !
+   USE lbclnk
+   USE timing          ! Timing
+
+#if defined key_iomput
+   USE xios            ! I/O server
+#endif
+#if defined key_agrif
+   USE agrif_oce_sponge ! Momemtum and tracers sponges
+   USE agrif_all_update ! Main update driver
+#endif
+#if defined key_top
+   USE trcstp, ONLY : trc_stp    ! passive tracer time-stepping      (trc_stp routine)
+#endif
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id$
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!======================================================================
+END MODULE stp_oce
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpctl.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpctl.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpctl.F90	(revision 14062)
@@ -3,12 +3,8 @@
    !!                       ***  MODULE  stpctl  ***
    !! Ocean run control :  gross check of the ocean time stepping
+   !!              *** Shallow Water Equation (SWE) case ***
+   !!               ( No test on temperature and salinity )
    !!======================================================================
-   !! History :  OPA  ! 1991-03  (G. Madec) Original code
-   !!            6.0  ! 1992-06  (M. Imbard)
-   !!            8.0  ! 1997-06  (A.M. Treguier)
-   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
-   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
-   !!            3.7  ! 2016-09  (G. Madec)  Remove solver
-   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
+   !! History :  SWE  ! 2020-09  (A. Nasser, S. Techene ) OCE/stpctl adaptated to SWE
    !!----------------------------------------------------------------------
 
@@ -21,11 +17,11 @@
    USE zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
    USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
-   !  
+   !
    USE diawri          ! Standard run outputs       (dia_wri_state routine)
    USE in_out_manager  ! I/O manager
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE lib_mpp         ! distributed memory computing
-   !
    USE netcdf          ! NetCDF library
+
    IMPLICIT NONE
    PRIVATE
@@ -35,4 +31,6 @@
    INTEGER                ::   nrunid   ! netcdf file id
    INTEGER, DIMENSION(2)  ::   nvarid   ! netcdf variable id
+
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -49,7 +47,9 @@
       !!
       !! ** Method  : - Save the time step in numstp
+      !!              - Print it each 50 time steps
       !!              - Stop the run IF problem encountered by setting nstop > 0
-      !!                Problems checked: negative sea surface height 
+      !!                Problems checked: e3t0+ssh minimum smaller that 0
       !!                                  |U|   maximum larger than 10 m/s 
+      !!                                  ( not for SWE : negative sea surface salinity )
       !!
       !! ** Actions :   "time.step" file = last ocean time-step
@@ -63,5 +63,5 @@
       INTEGER                         ::   idtime, istatus
       INTEGER , DIMENSION(3)          ::   iareasum, iareamin, iareamax
-      INTEGER , DIMENSION(3,2)        ::   iloc                                  ! min/max loc indices
+      INTEGER , DIMENSION(3,4)        ::   iloc                                  ! min/max loc indices
       REAL(wp)                        ::   zzz                                   ! local real 
       REAL(wp), DIMENSION(3)          ::   zmax, zmaxlocal
@@ -70,4 +70,6 @@
       CHARACTER(len=20)               ::   clname
       !!----------------------------------------------------------------------
+      IF( nstop > 0 .AND. ngrdstop > -1 )   RETURN   !   stpctl was already called by a child grid
+      !
       IF( nstop > 0 .AND. ngrdstop > -1 )   RETURN   !   stpctl was already called by a child grid
       !
@@ -109,10 +111,10 @@
       !                                   !==            test of local extrema           ==!
       !                                   !==  done by all processes at every time step  ==!
-      !
-      llmsk(   1:Nis1,:,:) = .FALSE.                                              ! exclude halos from the checked region
-      llmsk(Nie1: jpi,:,:) = .FALSE.
-      llmsk(:,   1:Njs1,:) = .FALSE.
-      llmsk(:,Nje1: jpj,:) = .FALSE.
-      !
+      zmax(1) = MINVAL( e3t_0(:,:,1)+ssh(:,:,Kmm)  )                              ! e3t_Kmm min
+      llmsk(:,:,:) = umask(:,:,:) == 1._wp
+      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) ), mask = llmsk )                     ! velocity max (zonal only)
+      zmax(3) = REAL( nstop , wp )                                            ! stop indicator
+      !                                   !==               get global extrema             ==!
+      !                                   !==  done by all processes if writting run.stat  ==!
       llmsk(Nis0:Nie0,Njs0:Nje0,1) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp         ! define only the inner domain
       zmax(1) = MAXVAL(     -e3t(:,:,1,Kmm) ), mask = llmsk(:,:,1) )      ! ssh max
@@ -131,13 +133,14 @@
       IF( ll_wrtruns ) THEN
          WRITE(numrun,9500) kt, zmax(1), zmax(2)
-         istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ -zmax(1)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/  zmax(2)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ zmax(1)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/ zmax(2)/), (/kt/), (/1/) )
          IF( kt == nitend )   istatus = NF90_CLOSE(nrunid)
-      END IF
+      ENDIF
       !                                   !==               error handling               ==!
       !                                   !==  done by all processes at every time step  ==!
       !
-      IF(   zmax(1) >  0._wp           .OR.   &               ! negative sea surface height 
-         &  zmax(2) > 10._wp           .OR.   &               ! too large velocity ( > 10 m/s)
+!!SWE specific : start
+      IF(   zmax(1) <=   0._wp .OR.           &               ! negative e3t_Kmm
+         &  zmax(2) >   10._wp .OR.           &               ! too large velocity ( > 10 m/s)
          &  ISNAN( zmax(1) + zmax(2) ) .OR.   &               ! NaN encounter in the tests
          &  ABS(   zmax(1) + zmax(2) ) > HUGE(1._wp) ) THEN   ! Infinity encounter in the tests
@@ -148,8 +151,6 @@
             IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
             ! get global loc on the min/max
-            llmsk(Nis0:Nie0,Njs0:Nje0,1) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp         ! define only the inner domain
-            CALL mpp_maxloc( 'stpctl',   -e3t(:,:,1,Kmm) , llmsk(:,:,1), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
-            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
-            CALL mpp_maxloc( 'stpctl', ABS(uu(:,:,:,Kmm)), llmsk(:,:,:), zzz, iloc(1:3,2) )
+            CALL mpp_minloc( 'stpctl', e3t_0(:,:,1) + ssh(:,:,Kmm), ssmask(:,:  ), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,Kmm))        ,  umask(:,:,:), zzz, iloc(1:3,2) )
             ! find which subdomain has the max.
             iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
@@ -164,17 +165,12 @@
          ELSE                    ! find local min and max locations:
             ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
-            llmsk(Nis0:Nie0,Njs0:Nje0,1) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp         ! define only the inner domain
-            iloc(1:2,1) = MAXLOC(   -e3t(:,:,1,Kmm) , mask = llmsk(:,:,1) )
-            llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp        ! define only the inner domain
-            iloc(1:3,2) = MAXLOC( ABS(uu(:,:,:,Kmm)), mask = llmsk(:,:,:) )
-            DO ji = 1, 2   ! local domain indices ==> global domain indices, excluding halos
-               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
-            END DO
+            iloc(1:2,1) = MINLOC( e3t_0(:,:,1) + ssh(:,:,Kmm), mask = ssmask(:,:  ) == 1._wp ) + (/ nimpp - 1, njmpp - 1    /)
+            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask =  umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
             iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
          ENDIF
          !
-         WRITE(ctmp1,*) ' stp_ctl: |ssh| > 20 m  or  |U| > 10 m/s  or  S <= 0  or  S >= 100  or  NaN encounter in the tests'
-         CALL wrt_line( ctmp2, kt, '|e3t| min', -zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) )
-         CALL wrt_line( ctmp3, kt, '|U|   max',  zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) )
+         WRITE(ctmp1,*) ' stp_ctl:  e3t0+ssh < 0 m  or  |U| > 10 m/s  or  NaN encounter in the tests'
+         CALL wrt_line( ctmp2, kt, 'e3t0+ssh min',  zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) )
+         CALL wrt_line( ctmp3, kt, '|U|   max'   ,  zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) )
          IF( Agrif_Root() ) THEN
             WRITE(ctmp6,*) '      ===> output of last computed fields in output.abort* files'
@@ -194,4 +190,5 @@
          !
       ENDIF
+!!SWE specific : end
       !
       IF( nstop > 0 ) THEN                                                  ! an error was detected and we did not abort yet...
@@ -200,5 +197,5 @@
       ENDIF
       !
-9500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16)
+9500  FORMAT(' it :', i8, '      e3t_min: ', D23.16, ' |U|_max: ', D23.16)
       !
    END SUBROUTINE stp_ctl
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpmlf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpmlf.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stpmlf.F90	(revision 14062)
@@ -0,0 +1,253 @@
+MODULE stpmlf
+   !!======================================================================
+   !!                       ***  MODULE stpMLF  ***
+   !! Time-stepping   : manager of the shallow water equation time stepping
+   !!                   Modified Leap Frog scheme
+   !!======================================================================
+   !! History :  NEMO !  2020-03  (A. Nasser, G. Madec)  Original code from  4.0.2
+   !!             -   !  2020-10  (S. Techene, G. Madec)  cleanning
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   stp_MLF       : MLF Shallow Water Eq. time-stepping
+   !!----------------------------------------------------------------------
+   USE stp_oce        ! modules used in nemo_init and stp_MLF
+   !
+   USE domqco         ! quasi-eulerian coordinate
+   USE phycst         ! physical constants
+   USE usrdef_nam     ! user defined namelist parameters
+!!st   USE usrdef_sbc     ! user defined surface boundary cond
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   stp_MLF   ! called by nemogcm.F90
+   
+   !                                          !**  time level indices  **!
+   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !: used by nemo_init
+      
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: step.F90 12614 2020-03-26 14:59:52Z gm $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE stp_MLF( kstp )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp_MLF  ***
+      !!
+      !! ** Purpose : - Time stepping of shallow water (SHW) (momentum and ssh eqs.)
+      !!
+      !! ** Method  : -1- Update forcings
+      !!              -2- Update the ssh at Naa
+      !!              -3- Compute the momentum trends (Nrhs)
+      !!              -4- Update the horizontal velocity
+      !!              -5- Apply Asselin time filter to uu,vv,ssh
+      !!              -6- Outputs and diagnostics
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk             ! dummy loop indices
+      INTEGER ::   indic                  ! error indicator if < 0
+      REAL(wp)::   z1_2rho0               ! local scalars
+      REAL(wp)::   zrhs_u, zue3a, zue3n, zue3b, zua   ! local scalars
+      REAL(wp)::   zrhs_v, zve3a, zve3n, zve3b, zva   !   -      -
+      !! ---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('stp_MLF')
+      !
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! model timestep
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !
+      IF( l_1st_euler ) THEN   ! start or restart with Euler 1st time-step
+         rDt   = rn_Dt   
+         r1_Dt = 1._wp / rDt
+      ENDIF
+
+      IF( kstp == nit000 )   ww(:,:,:) = 0._wp   ! initialize vertical velocity one for all to zero
+
+      !
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! update I/O and calendar 
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                             indic = 0                ! reset to no error condition
+
+      IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
+                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
+                             CALL iom_init_closedef
+      ENDIF
+      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
+                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update external forcing   (SWE: surface boundary condition only)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+                             CALL sbc     ( kstp, Nbb, Nnn )                   ! Sea Boundary Condition
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update   (SWE: eddy viscosity only)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( l_ldfdyn_time )   CALL ldf_dyn( kstp, Nbb )                          ! eddy viscosity coeff. 
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  RHS of horizontal velocity
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+                         uu(:,:,:,Nrhs) = 0._wp            ! set dynamics trends to zero
+                         vv(:,:,:,Nrhs) = 0._wp
+
+                         CALL dyn_adv( kstp, Nbb, Nnn, uu, vv, Nrhs )   ! advection (VF or FF)	==> RHS
+                         CALL dyn_vor( kstp,      Nnn, uu, vv, Nrhs )   ! vorticity           	==> RHS
+                         CALL dyn_ldf( kstp, Nbb, Nnn, uu, vv, Nrhs )   ! lateral mixing                     ==> RHS
+
+      z1_2rho0 = 0.5_wp * r1_rho0
+      !
+      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+         !                                                              ! horizontal pressure gradient
+         zrhs_u =        - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
+         zrhs_v =        - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
+         !                                                              ! wind stress and layer friction
+         zrhs_u = zrhs_u + z1_2rho0 * ( utau_b(ji,jj) + utau(ji,jj) ) / e3u(ji,jj,jk,Nnn)   &
+            &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
+         zrhs_v = zrhs_v + z1_2rho0 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
+            &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
+         !                                                              ! ==> RHS
+         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + zrhs_u
+         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + zrhs_v
+      END_3D
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Time stepping of ssh Eq. (and update r3_Naa)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !        ! Leap Frog time stepping ==> ssh_Naa and r3_Naa
+                         CALL ssh_nxt( kstp, Nbb, Nnn, ssh   , Naa )    ! after ssh 
+      !                                                                 ! after ssh/h_0 ratio explicit
+                         CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )
+      !        ! Asselin filter ==> ssh_Nnn filtered
+      IF ( .NOT.( l_1st_euler ) ) THEN   ! Time filtering of now ssh
+         ssh(:,:,Nnn) = ssh(:,:,Nnn) + rn_atfp * ( ssh(:,:,Nbb) - 2._wp * ssh(:,:,Nnn) + ssh(:,:,Naa) )
+      ENDIF
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Time stepping of dynamics (u,v)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( ln_dynadv_vec ) THEN      ! vector invariant form : applied on velocity
+         IF( l_1st_euler ) THEN          ! Euler time stepping (no Asselin filter)
+            DO_3D( 0,0, 0,0, 1,jpkm1)
+               uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+               vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+             END_3D          
+         ELSE                            ! Leap Frog time stepping + Asselin filter         
+            DO_3D( 0,0, 0,0, 1,jpkm1)
+               zua = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+               zva = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+               !                                                                  ! Asselin time filter on u,v (Nnn)
+               uu(ji,jj,jk,Nnn) = uu(ji,jj,jk,Nnn) + rn_atfp * (uu(ji,jj,jk,Nbb) - 2._wp * uu(ji,jj,jk,Nnn) + zua)
+               vv(ji,jj,jk,Nnn) = vv(ji,jj,jk,Nnn) + rn_atfp * (vv(ji,jj,jk,Nbb) - 2._wp * vv(ji,jj,jk,Nnn) + zva)
+               !              
+               uu(ji,jj,jk,Naa) = zua
+               vv(ji,jj,jk,Naa) = zva
+            END_3D
+            !                            ! Update r3_Nnn
+            CALL dom_qco_r3c( ssh(:,:,Nnn), r3t(:,:,Nnn), r3u(:,:,Nnn), r3v(:,:,Nnn) )   ! now ssh/h_0 ratio from filtrered ssh
+         ENDIF
+         !
+      ELSE                          ! flux form : applied on thickness weighted velocity
+         IF( l_1st_euler ) THEN          ! Euler time stepping (no Asselin filter)
+            DO_3D( 0,0, 0,0, 1,jpkm1)
+               zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
+               zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
+               !                                                ! Euler time stepping
+               zue3a = zue3b + rDt * e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+               zve3a = zve3b + rDt * e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+               !
+               uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
+               vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
+            END_3D
+         ELSE                             ! Leap Frog time stepping + Asselin filter
+            CALL dom_qco_r3c( ssh(:,:,Nnn), r3t_f(:,:), r3u_f(:,:), r3v_f(:,:) )   ! now ssh/h_0 ratio from filtrered ssh
+            DO_3D( 0,0, 0,0, 1,jpkm1)
+               zue3n = ( 1._wp + r3u(ji,jj,Nnn) ) * uu(ji,jj,jk,Nnn)
+               zve3n = ( 1._wp + r3v(ji,jj,Nnn) ) * vv(ji,jj,jk,Nnn)
+               zue3b = ( 1._wp + r3u(ji,jj,Nbb) ) * uu(ji,jj,jk,Nbb)
+               zve3b = ( 1._wp + r3v(ji,jj,Nbb) ) * vv(ji,jj,jk,Nbb)
+               !                                                ! LF time stepping
+               zue3a = zue3b + rDt * ( 1._wp + r3u(ji,jj,Nnn) ) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+               zve3a = zve3b + rDt * ( 1._wp + r3v(ji,jj,Nnn) ) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+               !                                                ! Asselin time filter on u,v (Nnn)
+               uu(ji,jj,jk,Nnn) = ( zue3n + rn_atfp * ( zue3b - 2._wp * zue3n  + zue3a ) ) / ( 1._wp + r3u_f(ji,jj) )
+               vv(ji,jj,jk,Nnn) = ( zve3n + rn_atfp * ( zve3b - 2._wp * zve3n  + zve3a ) ) / ( 1._wp + r3v_f(ji,jj) )
+               !
+               uu(ji,jj,jk,Naa) = zue3a / ( 1._wp + r3u(ji,jj,Naa) )    
+               vv(ji,jj,jk,Naa) = zve3a / ( 1._wp + r3v(ji,jj,Naa) )
+            END_3D
+            !                             ! Update r3_Nnn with time filtered values
+            r3t(:,:,Nnn) = r3t_f(:,:)
+            r3u(:,:,Nnn) = r3u_f(:,:)
+            r3v(:,:,Nnn) = r3v_f(:,:)
+         ENDIF
+      ENDIF
+
+      CALL lbc_lnk_multi( 'stp_MLF', uu(:,:,:,Nnn), 'U', -1., vv(:,:,:,Nnn), 'V', -1.,   &   !* local domain boundaries
+         &                           uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1.    )     
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Set boundary conditions, time filter and swap time levels
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      ! Swap time levels
+      Nrhs = Nbb
+      Nbb = Nnn
+      Nnn = Naa
+      Naa = Nrhs
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      
+      IF( ln_diacfl  )   CALL dia_cfl  ( kstp,      Nnn )      ! Courant number diagnostics
+                         CALL dia_wri  ( kstp,      Nnn )      ! ocean model: outputs
+      !
+      IF( lrst_oce   )   CALL rst_write( kstp, Nbb, Nnn )      ! write output ocean restart file
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL stp_ctl      ( kstp, Nnn )
+
+      IF( kstp == nit000 ) THEN                          ! 1st time step only
+                                        CALL iom_close( numror )   ! close input  ocean restart file
+         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
+         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
+      ENDIF
+
+      !
+#if defined key_iomput
+      IF( kstp == nitend .OR. indic < 0 ) THEN
+!!st : cxios_context needed ? because opened earlier ???         
+         CALL iom_context_finalize( cxios_context ) ! needed for XIOS+AGRIF
+!!st : crxios_context not needed associated with coarsening ! 
+         IF(lrxios) CALL iom_context_finalize( crxios_context )
+      ENDIF
+#endif
+      !
+      IF( l_1st_euler ) THEN         ! recover Leap-frog timestep
+         rDt   = 2._wp * rn_Dt   
+         r1_Dt = 1._wp / rDt
+         l_1st_euler = .FALSE.      
+      ENDIF
+      !
+      IF( ln_timing )   CALL timing_stop('stp_MLF')
+      !
+   END SUBROUTINE stp_MLF
+
+   !!======================================================================
+END MODULE stpmlf
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stprk3.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stprk3.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/SWE/stprk3.F90	(revision 14062)
@@ -0,0 +1,377 @@
+MODULE stprk3
+   !!======================================================================
+   !!                       ***  MODULE stprk3  ***
+   !! Time-stepping   : manager of the shallow water equation time stepping
+   !!                   3rd order Runge-Kutta scheme
+   !!======================================================================
+   !! History :  NEMO !  2020-03  (A. Nasser, G. Madec)  Original code from  4.0.2
+   !!             -   !  2020-10  (S. Techene, G. Madec)  cleanning
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   stp_RK3       : RK3 Shallow Water Eq. time-stepping
+   !!----------------------------------------------------------------------
+   USE stp_oce        ! modules used in nemo_init and stp_RK3
+   !
+   USE domqco         ! quasi-eulerian coordinate
+   USE phycst         ! physical constants
+   USE usrdef_nam     ! user defined namelist parameters
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   stp_RK3   ! called by nemogcm.F90
+
+   !                                          !**  time level indices  **!
+   INTEGER, PUBLIC ::   Nbb, Nnn, Naa, Nrhs   !: used by nemo_init
+      
+   !! * Substitutions
+#  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: step.F90 12614 2020-03-26 14:59:52Z gm $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE stp_RK3( kstp )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE stp_RK3  ***
+      !!
+      !! ** Purpose : - RK3 Time stepping scheme for shallow water Eq.
+      !!
+      !! ** Method  : 3rd order time stepping scheme which has 3 stages
+      !!       * Update calendar and forcings
+      !!       stage 1   : n ==> n+1/3 using variables at n
+      !!                 - Compute the rhs of momentum
+      !!                 - Time step ssh at Naa (n+1/3)
+      !!                 - Time step u,v at Naa (n+1/3)
+      !!                 - Swap time indices
+      !!       stage 2   : n ==> n+1/2 using variables at n and n+1/3
+      !!                 - Compute the rhs of momentum
+      !!                 - Time step ssh at Naa (n+1/2)
+      !!                 - Time step u,v at Naa (n+1/2)
+      !!                 - Swap time indices
+      !!       stage 3   : n ==> n+1 using variables at n and n+1/2
+      !!                 - Compute the rhs of momentum
+      !!                 - Time step ssh at Naa (n+1)
+      !!                 - Time step u,v at Naa (n+1)
+      !!                 - Swap time indices
+      !!       * Outputs and diagnostics
+      !!
+      !!       NB: in stages 1 and 2 lateral mixing and forcing are not taken
+      !!           into account in the momentum RHS execpt if key_RK3all is used
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in   ) ::   kstp   ! ocean time-step index
+      !
+      INTEGER ::   ji, jj, jk   ! dummy loop indice
+      INTEGER ::   indic        ! error indicator if < 0
+      REAL(wp)::   z1_2rho0,  z5_6,  z3_4  ! local scalars
+      REAL(wp)::   zue3a, zue3b, zua, zrhs_u    ! local scalars
+      REAL(wp)::   zve3a, zve3b, zva, zrhs_v    !   -      -
+      !! ---------------------------------------------------------------------
+      !
+      IF( ln_timing )   CALL timing_start('stp_RK3')
+      !
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! model timestep
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      !
+      IF ( kstp == nit000 )   ww(:,:,:) = 0._wp   ! initialize vertical velocity one for all to zero
+
+      !
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! update I/O and calendar 
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                             indic = 0                ! reset to no error condition
+                             
+      IF( kstp == nit000 ) THEN                       ! initialize IOM context
+                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including possible AGRIF zoom)
+                             CALL iom_init_closedef
+      ENDIF
+      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
+                             CALL iom_setkt( kstp - nit000 + 1,      cxios_context          )   ! tell IOM we are at time step kstp
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Update external forcing   (SWE: surface boundary condition only)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+                             CALL sbc     ( kstp, Nbb, Nnn )                   ! Sea Boundary Condition
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Ocean physics update   (SWE: eddy viscosity only)
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+      IF( l_ldfdyn_time )   CALL ldf_dyn( kstp, Nbb )                          ! eddy viscosity coeff. 
+
+      !======================================================================
+      !======================================================================
+      !                     =====       RK3       =====
+      !======================================================================
+      !======================================================================
+
+      
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  RK3 1st stage Ocean dynamics : u, v, ssh
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      rDt   = rn_Dt / 3._wp  
+      r1_Dt = 1._wp / rDt
+      !
+      !                                 !==  RHS of the momentum Eq.  ==!
+      !
+      uu(:,:,:,Nrhs) = 0._wp                        ! set dynamics trends to zero
+      vv(:,:,:,Nrhs) = 0._wp
+
+      CALL dyn_adv( kstp, Nbb, Nbb, uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
+      CALL dyn_vor( kstp,      Nbb, uu, vv, Nrhs )  ! vorticity           	==> RHS
+#if defined key_RK3all 
+      CALL dyn_ldf( kstp, Nbb, Nbb, uu, vv, Nrhs )  ! lateral mixing
+#endif
+!!st       !
+!!st       DO_3D( 0,0, 0,0, 1,jpkm1 )
+!!st          !                                          ! horizontal pressure gradient
+!!st          uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nbb) - ssh(ji,jj,Nbb) ) * r1_e1u(ji,jj)
+!!st          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nbb) - ssh(ji,jj,Nbb) ) * r1_e2v(ji,jj)
+!!st       END_3D
+!!st       !
+!!st #if defined key_RK3all 
+!!st       !                                             ! wind stress and layer friction
+!!st       z5_6 = 5._wp/6._wp
+!!st       DO_3D( 0, 0, 0, 0,1,jpkm1)
+!!st          uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + r1_rho0 * ( z5_6*utau_b(ji,jj) + (1._wp - z5_6)*utau(ji,jj) ) / e3u(ji,jj,jk,Nbb)   &
+!!st             &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
+!!st          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + r1_rho0 * ( z5_6*vtau_b(ji,jj) + (1._wp - z5_6)*vtau(ji,jj) ) / e3v(ji,jj,jk,Nbb)   &
+!!st             &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
+!!st       END_3D
+!!st #endif
+!!st why not ?
+      z5_6 = 5._wp/6._wp
+      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+         !                                          ! horizontal pressure gradient
+         zrhs_u =        - grav    * ( ssh(ji+1,jj,Nbb) - ssh(ji,jj,Nbb) ) * r1_e1u(ji,jj)
+         zrhs_v =        - grav    * ( ssh(ji,jj+1,Nbb) - ssh(ji,jj,Nbb) ) * r1_e2v(ji,jj)
+#if defined key_RK3all
+         !                                          ! wind stress and layer friction
+         zrhs_u = zrhs_u + r1_rho0 * ( z5_6*utau_b(ji,jj) + (1._wp - z5_6)*utau(ji,jj) ) / e3u(ji,jj,jk,Nbb)   &
+            &            - rn_rfr  * uu(ji,jj,jk,Nbb)
+         zrhs_v = zrhs_v + r1_rho0 * ( z5_6*vtau_b(ji,jj) + (1._wp - z5_6)*vtau(ji,jj) ) / e3v(ji,jj,jk,Nbb)   &
+            &            - rn_rfr  * vv(ji,jj,jk,Nbb)
+#endif
+         !                                          ! ==> RHS
+         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + zrhs_u
+         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + zrhs_v
+      END_3D
+!!st end
+      !
+      !                                 !==  Time stepping of ssh Eq.  ==!   (and update r3_Naa)
+      !
+      CALL ssh_nxt( kstp, Nbb, Nbb, ssh, Naa )      ! after ssh
+      !                                             ! after ssh/h_0 ratio
+      CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )
+      !
+      !                                 !==  Time stepping of momentum Eq.  ==!
+      !
+      IF( ln_dynadv_vec ) THEN                      ! vector invariant form : applied on velocity
+         DO_3D( 0, 0, 0, 0, 1,jpkm1)
+            uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+         END_3D          
+      ELSE
+         DO_3D( 0, 0, 0, 0, 1,jpkm1)                 ! flux form : applied on thickness weighted velocity
+            zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
+            zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
+            zue3a = zue3b + rDt * e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            zve3a = zve3b + rDt * e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+            !
+            uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
+            vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
+         END_3D
+      ENDIF
+      !
+      CALL lbc_lnk_multi( 'stp_RK3', uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1. )
+      !
+      !                                 !==  Swap time levels  ==!
+      Nrhs= Nnn
+      Nnn = Naa
+      Naa = Nrhs
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  RK3 2nd stage Ocean dynamics : hdiv, ssh, e3, u, v, w
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      rDt   = rn_Dt / 2._wp  
+      r1_Dt = 1._wp / rDt
+      !
+      !                                 !==  RHS of the momentum Eq.  ==!
+      !
+      uu(:,:,:,Nrhs) = 0._wp                        ! set dynamics trends to zero
+      vv(:,:,:,Nrhs) = 0._wp
+      CALL dyn_adv( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS 
+      CALL dyn_vor( kstp,      Nnn, uu, vv, Nrhs )  ! vorticity           	==> RHS
+#if defined key_RK3all  
+      CALL dyn_ldf( kstp, Nbb, Nbb, uu, vv, Nrhs )  ! lateral mixing
+#endif
+      !
+      z3_4 = 3._wp/4._wp
+      DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+         !                                          ! horizontal pressure gradient
+         zrhs_u =        - grav    * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
+         zrhs_v =        - grav    * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
+#if defined key_RK3all
+         !                                          ! wind stress and layer friction
+         zrhs_u = zrhs_u + r1_rho0 * ( z3_4*utau_b(ji,jj) + (1._wp - z3_4)*utau(ji,jj) ) / e3u(ji,jj,jk,Nnn)   &
+            &            - rn_rfr  * uu(ji,jj,jk,Nbb)
+         zrhs_v = zrhs_v + r1_rho0 * ( z3_4*vtau_b(ji,jj) + (1._wp - z3_4)*vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
+            &            - rn_rfr  * vv(ji,jj,jk,Nbb)
+#endif
+         !                                          ! ==> RHS
+         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + zrhs_u
+         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + zrhs_v
+      END_3D
+!!st       !
+!!st       DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+!!st          !                                          ! horizontal pressure gradient
+!!st          uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
+!!st          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
+!!st       END_3D
+!!st       !
+!!st #if defined key_RK3all
+!!st       !                                             ! wind stress and layer friction
+!!st       z3_4 = 3._wp/4._wp
+!!st       DO_3D( 0, 0, 0, 0,1,jpkm1)
+!!st          uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + r1_rho0 * ( z3_4*utau_b(ji,jj) + (1._wp - z3_4)*utau(ji,jj) ) / e3u(ji,jj,jk,Nbb)   &
+!!st             &                                  - rn_rfr * uu(ji,jj,jk,Nbb)
+!!st          vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + r1_rho0 * ( z3_4*vtau_b(ji,jj) + (1._wp - z3_4)*vtau(ji,jj) ) / e3v(ji,jj,jk,Nbb)   &
+!!st             &                                  - rn_rfr * vv(ji,jj,jk,Nbb)
+!!st       END_3D
+!!st #endif
+      !
+      !                                 !==  Time stepping of ssh Eq.  ==!   (and update r3_Naa)
+      !
+      CALL ssh_nxt( kstp, Nbb, Nnn, ssh, Naa )      ! after ssh
+      !                                             ! after ssh/h_0 ratio
+      CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )
+      !
+      !                                 !==  Time stepping of momentum Eq.  ==!
+      !
+      IF( ln_dynadv_vec ) THEN                      ! vector invariant form : applied on velocity
+         DO_3D( 0, 0, 0, 0, 1,jpkm1)
+            uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+         END_3D          
+      ELSE
+         DO_3D( 0, 0, 0, 0, 1,jpkm1)                 ! flux form : applied on thickness weighted velocity
+            zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
+            zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
+            zue3a = zue3b + rDt * e3u(ji,jj,jk,Nnn) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            zve3a = zve3b + rDt * e3v(ji,jj,jk,Nnn) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+            !
+            uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
+            vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
+         END_3D
+      ENDIF
+      !
+      CALL lbc_lnk_multi( 'stp_RK3', uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1. )
+      !
+      !                                 !==  Swap time levels  ==!
+      Nrhs= Nnn
+      Nnn = Naa
+      Naa = Nrhs
+       
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      !  RK3 3rd stage Ocean dynamics : hdiv, ssh, e3, u, v, w
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      rDt   = rn_Dt
+      r1_Dt = 1._wp / rDt
+      !
+      !                                 !==  RHS of the momentum Eq.  ==!
+      !
+      uu(:,:,:,Nrhs) = 0._wp                        ! set dynamics trends to zero
+      vv(:,:,:,Nrhs) = 0._wp
+      !
+      CALL dyn_adv( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! advection (VF or FF)	==> RHS
+      CALL dyn_vor( kstp,      Nnn, uu, vv, Nrhs )  ! vorticity           	==> RHS
+      CALL dyn_ldf( kstp, Nbb, Nnn, uu, vv, Nrhs )  ! lateral mixing
+
+      z1_2rho0 = 0.5_wp * r1_rho0
+      DO_3D( 0, 0, 0, 0, 1,jpkm1 )
+         !                                          ! horizontal pressure gradient
+         zrhs_u =        - grav * ( ssh(ji+1,jj,Nnn) - ssh(ji,jj,Nnn) ) * r1_e1u(ji,jj)
+         zrhs_v =        - grav * ( ssh(ji,jj+1,Nnn) - ssh(ji,jj,Nnn) ) * r1_e2v(ji,jj)
+         !                                          ! wind stress and layer friction
+         zrhs_u = zrhs_u + z1_2rho0 * ( utau_b(ji,jj) + utau(ji,jj) ) / e3u(ji,jj,jk,Nnn)   &
+            &            - rn_rfr   * uu(ji,jj,jk,Nbb)
+         zrhs_v = zrhs_v + z1_2rho0 * ( vtau_b(ji,jj) + vtau(ji,jj) ) / e3v(ji,jj,jk,Nnn)   &
+            &            - rn_rfr   * vv(ji,jj,jk,Nbb)
+         !                                          ! ==> RHS
+         uu(ji,jj,jk,Nrhs) = uu(ji,jj,jk,Nrhs) + zrhs_u
+         vv(ji,jj,jk,Nrhs) = vv(ji,jj,jk,Nrhs) + zrhs_v
+      END_3D
+      !
+      !                                 !==  Time stepping of ssh Eq.  ==!   (and update r3_Naa)
+      !
+      CALL ssh_nxt( kstp, Nbb, Nnn, ssh, Naa )      ! after ssh
+      !                                             ! after ssh/h_0 ratio
+      CALL dom_qco_r3c( ssh(:,:,Naa), r3t(:,:,Naa), r3u(:,:,Naa), r3v(:,:,Naa), r3f(:,:) )
+      !
+      !                                 !==  Time stepping of momentum Eq.  ==!
+      !
+      IF( ln_dynadv_vec ) THEN                      ! vector invariant form : applied on velocity
+         DO_3D( 0, 0, 0, 0, 1,jpkm1)
+            uu(ji,jj,jk,Naa) = uu(ji,jj,jk,Nbb) + rDt * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            vv(ji,jj,jk,Naa) = vv(ji,jj,jk,Nbb) + rDt * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+         END_3D
+         !
+      ELSE                                          ! flux form : applied on thickness weighted velocity
+         DO_3D( 0, 0, 0, 0, 1,jpkm1)
+            zue3b = e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nbb)
+            zve3b = e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nbb)
+            zue3a = zue3b + rDt * e3u(ji,jj,jk,Nbb) * uu(ji,jj,jk,Nrhs) * umask(ji,jj,jk)
+            zve3a = zve3b + rDt * e3v(ji,jj,jk,Nbb) * vv(ji,jj,jk,Nrhs) * vmask(ji,jj,jk)
+            !
+            uu(ji,jj,jk,Naa) = zue3a / e3u(ji,jj,jk,Naa)    
+            vv(ji,jj,jk,Naa) = zve3a / e3v(ji,jj,jk,Naa)
+         END_3D
+      ENDIF
+      !
+      CALL lbc_lnk_multi( 'stp_RK3', uu(:,:,:,Naa), 'U', -1., vv(:,:,:,Naa), 'V', -1. )
+      !
+      !                                 !==  Swap time levels  ==!
+      !
+      Nrhs = Nbb
+      Nbb = Naa
+      Naa = Nrhs
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! diagnostics and outputs
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+      
+      IF( ln_diacfl  )   CALL dia_cfl   ( kstp,      Nnn )      ! Courant number diagnostics
+                         CALL dia_wri   ( kstp,      Nnn )      ! ocean model: outputs
+      !
+      IF( lrst_oce   )   CALL rst_write    ( kstp, Nbb, Nnn )   ! write output ocean restart file
+
+      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+      ! Control
+      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+                         CALL stp_ctl      ( kstp, Nnn )
+
+      IF( kstp == nit000 ) THEN                          ! 1st time step only
+                                        CALL iom_close( numror )   ! close input  ocean restart file
+         IF(lwm)                        CALL FLUSH    ( numond )   ! flush output namelist oce
+         IF(lwm .AND. numoni /= -1 )    CALL FLUSH    ( numoni )   ! flush output namelist ice (if exist)
+      ENDIF
+
+      !
+#if defined key_iomput
+      IF( kstp == nitend .OR. indic < 0 ) THEN 
+         CALL iom_context_finalize( cxios_context )
+      ENDIF
+#endif
+      !
+      IF( ln_timing )   CALL timing_stop('stp_RK3')
+      !
+   END SUBROUTINE stp_RK3
+
+   !!======================================================================
+END MODULE stprk3
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/TOP/PISCES/SED/oce_sed.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/TOP/PISCES/SED/oce_sed.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/TOP/PISCES/SED/oce_sed.F90	(revision 14062)
@@ -13,5 +13,5 @@
    USE dom_oce , ONLY :   glamt     =>   glamt          !: longitude of t-point (degre)
    USE dom_oce , ONLY :   gphit     =>   gphit          !: latitude  of t-point (degre)
-!!st 
+ 
 #if ! defined key_qco
    USE dom_oce , ONLY :   e3t       =>   e3t            !: latitude  of t-point (degre)
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/TOP/TRP/trcatf.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/TOP/TRP/trcatf.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/TOP/TRP/trcatf.F90	(revision 14062)
@@ -32,5 +32,5 @@
    USE trdtra
 # if defined key_qco
-   USE traatfqco
+   USE traatf_qco
 # else
    USE traatf
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/EXPREF/namelist_cfg_orca025_like
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/EXPREF/namelist_cfg_orca025_like	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/EXPREF/namelist_cfg_orca025_like	(revision 14062)
@@ -178,6 +178,6 @@
 !-----------------------------------------------------------------------
    ln_dynvor_een = .true. !  energy & enstrophy scheme
-      nn_een_e3f = 0          ! =0  e3f = mi(mj(e3t))/4 
-      !                       ! =1  e3f = mi(mj(e3t))/mi(mj( tmask))
+   nn_e3f_typ = 0         ! =0  e3f = mi(mj(e3t))/4 
+   !                      ! =1  e3f = mi(mj(e3t))/mi(mj( tmask))
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/EXPREF/namelist_cfg_orca12_like
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/EXPREF/namelist_cfg_orca12_like	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/EXPREF/namelist_cfg_orca12_like	(revision 14062)
@@ -177,5 +177,5 @@
 !-----------------------------------------------------------------------
    ln_dynvor_een = .true. !  energy & enstrophy scheme
-      nn_een_e3f = 0          ! =0  e3f = mi(mj(e3t))/4 
+      nn_e3f_typ = 0          ! =0  e3f = mi(mj(e3t))/4 
       !                       ! =1  e3f = mi(mj(e3t))/mi(mj( tmask))
 /
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/MY_SRC/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/BENCH/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -26,5 +26,6 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called by istate.F90
+   PUBLIC   usr_def_istate       ! called by istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by domqco.F90
 
    !! * Substitutions
@@ -37,5 +38,5 @@
 CONTAINS
   
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv ) !!st, pssh )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -52,5 +53,5 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
+!!st      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
       !
       REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! 2D workspace
@@ -79,5 +80,5 @@
       !
       ! sea level:
-      pssh(:,:) = z2d(:,:)                                                ! +/- 0.05 m
+!!st      pssh(:,:) = z2d(:,:)                                                ! +/- 0.05 m
       !
       DO_3D( 0, 0, 0, 0, 1, jpkm1 )
@@ -95,5 +96,5 @@
       pv( :,:,jpk  ) = 0._wp
       !
-      CALL lbc_lnk('usrdef_istate', pssh, 'T',  1. )            ! apply boundary conditions
+!!st      CALL lbc_lnk('usrdef_istate', pssh, 'T',  1. )            ! apply boundary conditions
       CALL lbc_lnk('usrdef_istate',  pts, 'T',  1. )            ! apply boundary conditions
       CALL lbc_lnk('usrdef_istate',   pu, 'U', -1. )            ! apply boundary conditions
@@ -102,4 +103,35 @@
    END SUBROUTINE usr_def_istate
 
+
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of ssh
+      !!                Here BENCH configuration 
+      !!
+      !! ** Method  :   Set ssh
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask   [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height   [m]
+      !
+      INTEGER  ::   ji, jj
+      INTEGER  ::   igloi, igloj   ! to be removed in the future, see usr_def_istate comment 
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : BENCH configuration, analytical definition of initial ssh'
+      !
+      igloi = Ni0glo + 2 * COUNT( (/ jperio == 1 .OR. jperio == 4 .OR. jperio == 6 .OR. jperio == 7 /) )
+      igloj = Nj0glo + 2 * COUNT( (/ jperio == 2 .OR. jperio == 7 /) ) + 1 * COUNT( (/ jperio >= 4 .AND. jperio <= 6 /) )
+      ! sea level:  +/- 0.05 m
+      DO_2D( 0, 0, 0, 0 )
+         pssh(ji,jj) = 0.1 * ( 0.5 - REAL( mig0_oldcmp(ji) + (mjg0_oldcmp(jj)-1) * igloi, wp ) / REAL( igloi * igloj, wp ) )
+      END_2D
+      !
+      CALL lbc_lnk('usrdef_istate', pssh, 'T',  1. )            ! apply boundary conditions
+      !
+   END SUBROUTINE usr_def_istate_ssh
+   
    !!======================================================================
 END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/EXPREF/namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/EXPREF/namelist_cfg	(revision 14062)
@@ -235,7 +235,7 @@
    ln_dynvor_mix = .false.  !  mixed scheme
    ln_dynvor_een = .false.  !  energy & enstrophy scheme
-   ln_dynvor_enT = .false.  !  energy conserving scheme (T-point)
+r_enT = .false.  !  energy conserving scheme (T-point)
    ln_dynvor_eeT = .true.   !  energy conserving scheme (een using e3t)
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
+      nn_e3f_typ = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
@@ -319,17 +319,8 @@
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
 !!   namdiu       Cool skin and warm layer models                       (default: OFF)
-<<<<<<< .working
-!!   namflo       float parameters                                      (default: OFF)
-!!   nam_diadct   transports through some sections                      (default: OFF)
-||||||| .merge-left.r13465
-!!   namflo       float parameters                                      (default: OFF)
-!!   nam_diaharm  Harmonic analysis of tidal constituents               (default: OFF)
-!!   nam_diadct   transports through some sections                      (default: OFF)
-=======
 !!   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: OFF)
->>>>>>> .merge-right.r13470
 !!   nam_dia25h   25h Mean Output                                       (default: OFF)
 !!   namnc4       netcdf4 chunking and compression settings             ("key_netcdf4")
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/MY_SRC/domvvl.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/MY_SRC/domvvl.F90	(revision 14059)
+++ 	(revision )
@@ -1,1025 +1,0 @@
-MODULE domvvl
-   !!======================================================================
-   !!                       ***  MODULE domvvl   ***
-   !! Ocean : 
-   !!======================================================================
-   !! History :  2.0  !  2006-06  (B. Levier, L. Marie)  original code
-   !!            3.1  !  2009-02  (G. Madec, M. Leclair, R. Benshila)  pure z* coordinate
-   !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl: vvl option includes z_star and z_tilde coordinates
-   !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
-   !!            4.x  ! 2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
-   !!----------------------------------------------------------------------
-
-   USE oce             ! ocean dynamics and tracers
-   USE phycst          ! physical constant
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! ocean surface boundary condition
-   USE wet_dry         ! wetting and drying
-   USE usrdef_istate   ! user defined initial state (wad only)
-   USE restart         ! ocean restart
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE lib_mpp         ! distributed memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   !                                                      !!* Namelist nam_vvl
-   LOGICAL , PUBLIC :: ln_vvl_zstar           = .FALSE.    ! zstar  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde          = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_layer           = .FALSE.    ! level  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde_as_zstar = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_zstar_at_eqtor  = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_kepe            = .FALSE.    ! kinetic/potential energy transfer
-   !                                                       ! conservation: not used yet
-   REAL(wp)         :: rn_ahe3                             ! thickness diffusion coefficient
-   REAL(wp)         :: rn_rst_e3t                          ! ztilde to zstar restoration timescale [days]
-   REAL(wp)         :: rn_lf_cutoff                        ! cutoff frequency for low-pass filter  [days]
-   REAL(wp)         :: rn_zdef_max                         ! maximum fractional e3t deformation
-   LOGICAL , PUBLIC :: ln_vvl_dbg = .FALSE.                ! debug control prints
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: un_td, vn_td                ! thickness diffusion transport
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: hdiv_lf                     ! low frequency part of hz divergence
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_b, tilde_e3t_n    ! baroclinic scale factors
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_a, dtilde_e3t_a   ! baroclinic scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_e3t                 ! retoring period for scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                 ! retoring period for low freq. divergence
-
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-#else
-   !!----------------------------------------------------------------------
-   !!   Default key      Old management of time varying vertical coordinate
-   !!----------------------------------------------------------------------
-   
-   !!----------------------------------------------------------------------
-   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
-   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
-   !!   dom_vvl_sf_update   : Swap vertical scale factors and update the vertical grid
-   !!   dom_vvl_interpol : Interpolate vertical scale factors from one grid point to another
-   !!   dom_vvl_rst      : read/write restart file
-   !!   dom_vvl_ctl      : Check the vvl options
-   !!----------------------------------------------------------------------
-
-   PUBLIC  dom_vvl_init       ! called by domain.F90
-   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
-   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
-   PUBLIC  dom_vvl_sf_update  ! called by step.F90
-   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
-   
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id$
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION dom_vvl_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION dom_vvl_alloc  ***
-      !!----------------------------------------------------------------------
-      IF( ln_vvl_zstar )   dom_vvl_alloc = 0
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         ALLOCATE( tilde_e3t_b(jpi,jpj,jpk)  , tilde_e3t_n(jpi,jpj,jpk) , tilde_e3t_a(jpi,jpj,jpk) ,   &
-            &      dtilde_e3t_a(jpi,jpj,jpk) , un_td  (jpi,jpj,jpk)     , vn_td  (jpi,jpj,jpk)     ,   &
-            &      STAT = dom_vvl_alloc        )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-         un_td = 0._wp
-         vn_td = 0._wp
-      ENDIF
-      IF( ln_vvl_ztilde ) THEN
-         ALLOCATE( frq_rst_e3t(jpi,jpj) , frq_rst_hdv(jpi,jpj) , hdiv_lf(jpi,jpj,jpk) , STAT= dom_vvl_alloc )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-      ENDIF
-      !
-   END FUNCTION dom_vvl_alloc
-
-
-   SUBROUTINE dom_vvl_init( Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Initialization of all scale factors, depths
-      !!               and water column heights
-      !!
-      !! ** Method  :  - use restart file and/or initialize
-      !!               - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3[u/v](:,:,:,Kmm)
-      !!                        e3[u/v](:,:,:,Kmm)       
-      !!                        e3w(:,:,:,Kmm)           
-      !!                        e3[u/v]w_b
-      !!                        e3[u/v]w_n      
-      !!                        gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm) and gde3w
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dom_vvl_init : Variable volume activated'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      !
-      CALL dom_vvl_ctl     ! choose vertical coordinate (z_star, z_tilde or layer)
-      !
-      !                    ! Allocate module arrays
-      IF( dom_vvl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_init : unable to allocate arrays' )
-      !
-      !                    ! Read or initialize e3t_(b/n), tilde_e3t_(b/n) and hdiv_lf
-      CALL dom_vvl_rst( nit000, Kbb, Kmm, 'READ' )
-      e3t(:,:,jpk,Kaa) = e3t_0(:,:,jpk)  ! last level always inside the sea floor set one for all
-      !
-      CALL dom_vvl_zgr(Kbb, Kmm, Kaa) ! interpolation scale factor, depth and water column
-      !
-   END SUBROUTINE dom_vvl_init
-
-
-   SUBROUTINE dom_vvl_zgr(Kbb, Kmm, Kaa)
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Interpolation of all scale factors, 
-      !!               depths and water column heights
-      !!
-      !! ** Method  :  - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3(u/v)_n
-      !!                        e3(u/v)_b       
-      !!                        e3w_n           
-      !!                        e3(u/v)w_b      
-      !!                        e3(u/v)w_n      
-      !!                        gdept_n, gdepw_n and gde3w_n
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   ii0, ii1, ij0, ij1
-      REAL(wp)::   zcoef
-      !!----------------------------------------------------------------------
-      !
-      !                    !== Set of all other vertical scale factors  ==!  (now and before)
-      !                                ! Horizontal interpolation of e3t
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3u(:,:,:,Kbb), 'U' )    ! from T to U
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3v(:,:,:,Kbb), 'V' )    ! from T to V 
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3f(:,:,:), 'F' )    ! from U to F
-      !                                ! Vertical interpolation of e3t,u,v 
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )  ! from T to W
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3w (:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )  ! from U to UW
-      CALL dom_vvl_interpol( e3u(:,:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( e3v(:,:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )  ! from V to UW
-      CALL dom_vvl_interpol( e3v(:,:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! We need to define e3[tuv]_a for AGRIF initialisation (should not be a problem for the restartability...)
-      e3t(:,:,:,Kaa) = e3t(:,:,:,Kmm)
-      e3u(:,:,:,Kaa) = e3u(:,:,:,Kmm)
-      e3v(:,:,:,Kaa) = e3v(:,:,:,Kmm)
-      !
-      !                    !==  depth of t and w-point  ==!   (set the isf depth as it is in the initial timestep)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)       ! reference to the ocean surface (used for MLD and light penetration)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)  ! reference to a common level z=0 for hpg
-      gdept(:,:,1,Kbb) = 0.5_wp * e3w(:,:,1,Kbb)
-      gdepw(:,:,1,Kbb) = 0.0_wp
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-         !    zcoef = tmask - wmask    ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-         !                             ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
-         !                             ! 0.5 where jk = mikt     
-!!gm ???????   BUG ?  gdept(:,:,:,Kmm) as well as gde3w  does not include the thickness of ISF ??
-         zcoef = ( tmask(ji,jj,jk) - wmask(ji,jj,jk) )
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm)) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-         gdepw(ji,jj,jk,Kbb) = gdepw(ji,jj,jk-1,Kbb) + e3t(ji,jj,jk-1,Kbb)
-         gdept(ji,jj,jk,Kbb) =      zcoef  * ( gdepw(ji,jj,jk  ,Kbb) + 0.5 * e3w(ji,jj,jk,Kbb))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kbb) +       e3w(ji,jj,jk,Kbb)) 
-      END_3D
-      !
-      !                    !==  thickness of the water column  !!   (ocean portion only)
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)   !!gm  BUG  :  this should be 1/2 * e3w(k=1) ....
-      hu(:,:,Kbb) = e3u(:,:,1,Kbb) * umask(:,:,1)
-      hu(:,:,Kmm) = e3u(:,:,1,Kmm) * umask(:,:,1)
-      hv(:,:,Kbb) = e3v(:,:,1,Kbb) * vmask(:,:,1)
-      hv(:,:,Kmm) = e3v(:,:,1,Kmm) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         hu(:,:,Kbb) = hu(:,:,Kbb) + e3u(:,:,jk,Kbb) * umask(:,:,jk)
-         hu(:,:,Kmm) = hu(:,:,Kmm) + e3u(:,:,jk,Kmm) * umask(:,:,jk)
-         hv(:,:,Kbb) = hv(:,:,Kbb) + e3v(:,:,jk,Kbb) * vmask(:,:,jk)
-         hv(:,:,Kmm) = hv(:,:,Kmm) + e3v(:,:,jk,Kmm) * vmask(:,:,jk)
-      END DO
-      !
-      !                    !==  inverse of water column thickness   ==!   (u- and v- points)
-      r1_hu(:,:,Kbb) = ssumask(:,:) / ( hu(:,:,Kbb) + 1._wp - ssumask(:,:) )    ! _i mask due to ISF
-      r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kbb) = ssvmask(:,:) / ( hv(:,:,Kbb) + 1._wp - ssvmask(:,:) )
-      r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) )
-
-      !                    !==   z_tilde coordinate case  ==!   (Restoring frequencies)
-      IF( ln_vvl_ztilde ) THEN
-!!gm : idea: add here a READ in a file of custumized restoring frequency
-         !                                   ! Values in days provided via the namelist
-         !                                   ! use rsmall to avoid possible division by zero errors with faulty settings
-         frq_rst_e3t(:,:) = 2._wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.0_wp )
-         frq_rst_hdv(:,:) = 2._wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.0_wp )
-         !
-         IF( ln_vvl_ztilde_as_zstar ) THEN   ! z-star emulation using z-tile
-            frq_rst_e3t(:,:) = 0._wp               !Ignore namelist settings
-            frq_rst_hdv(:,:) = 1._wp / rn_Dt
-         ENDIF
-         IF ( ln_vvl_zstar_at_eqtor ) THEN   ! use z-star in vicinity of the Equator
-            DO_2D( 1, 1, 1, 1 )
-!!gm  case |gphi| >= 6 degrees is useless   initialized just above by default
-               IF( ABS(gphit(ji,jj)) >= 6.) THEN
-                  ! values outside the equatorial band and transition zone (ztilde)
-                  frq_rst_e3t(ji,jj) =  2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.e0_wp )
-                  frq_rst_hdv(ji,jj) =  2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.e0_wp )
-               ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN    ! Equator strip ==> z-star
-                  ! values inside the equatorial band (ztilde as zstar)
-                  frq_rst_e3t(ji,jj) =  0.0_wp
-                  frq_rst_hdv(ji,jj) =  1.0_wp / rn_Dt
-               ELSE                                      ! transition band (2.5 to 6 degrees N/S)
-                  !                                      ! (linearly transition from z-tilde to z-star)
-                  frq_rst_e3t(ji,jj) = 0.0_wp + (frq_rst_e3t(ji,jj)-0.0_wp)*0.5_wp   &
-                     &            * (  1.0_wp - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-                  frq_rst_hdv(ji,jj) = (1.0_wp / rn_Dt)                                &
-                     &            + (  frq_rst_hdv(ji,jj)-(1.e0_wp / rn_Dt) )*0.5_wp   &
-                     &            * (  1._wp  - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-               ENDIF
-            END_2D
-            IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
-               IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-                  ii0 = 103 + nn_hls - 1   ;   ii1 = 111 + nn_hls - 1      
-                  ij0 = 128 + nn_hls       ;   ij1 = 135 + nn_hls
-                  frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
-                  frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rn_Dt
-               ENDIF
-            ENDIF
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_zgr
-
-
-   SUBROUTINE dom_vvl_sf_nxt( kt, Kbb, Kmm, Kaa, kcall ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_nxt  ***
-      !!                   
-      !! ** Purpose :  - compute the after scale factors used in tra_zdf, dynnxt,
-      !!                 tranxt and dynspg routines
-      !!
-      !! ** Method  :  - z_star case:  Repartition of ssh INCREMENT proportionnaly to the level thickness.
-      !!               - z_tilde_case: after scale factor increment = 
-      !!                                    high frequency part of horizontal divergence
-      !!                                  + retsoring towards the background grid
-      !!                                  + thickness difusion
-      !!                               Then repartition of ssh INCREMENT proportionnaly
-      !!                               to the "baroclinic" level thickness.
-      !!
-      !! ** Action  :  - hdiv_lf    : restoring towards full baroclinic divergence in z_tilde case
-      !!               - tilde_e3t_a: after increment of vertical scale factor 
-      !!                              in z_tilde case
-      !!               - e3(t/u/v)_a
-      !!
-      !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )           ::   kt             ! time step
-      INTEGER, INTENT( in )           ::   Kbb, Kmm, Kaa  ! time step
-      INTEGER, INTENT( in ), OPTIONAL ::   kcall          ! optional argument indicating call sequence
-      !
-      INTEGER                ::   ji, jj, jk            ! dummy loop indices
-      INTEGER , DIMENSION(3) ::   ijk_max, ijk_min      ! temporary integers
-      REAL(wp)               ::   z_tmin, z_tmax        ! local scalars
-      LOGICAL                ::   ll_do_bclinic         ! local logical
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3t
-      LOGICAL , DIMENSION(:,:,:), ALLOCATABLE ::   llmsk
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_nxt')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
-      ENDIF
-
-      ll_do_bclinic = .TRUE.
-      IF( PRESENT(kcall) ) THEN
-         IF( kcall == 2 .AND. ln_vvl_ztilde )   ll_do_bclinic = .FALSE.
-      ENDIF
-
-      ! ******************************* !
-      ! After acale factors at t-points !
-      ! ******************************* !
-      !                                                ! --------------------------------------------- !
-      !                                                ! z_star coordinate and barotropic z-tilde part !
-      !                                                ! --------------------------------------------- !
-      !
-      z_scale(:,:) = ( ssh(:,:,Kaa) - ssh(:,:,Kbb) ) * ssmask(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-      DO jk = 1, jpkm1
-         ! formally this is the same as e3t(:,:,:,Kaa) = e3t_0*(1+ssha/ht_0)
-         e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kbb) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-      END DO
-      !
-      IF( (ln_vvl_ztilde .OR. ln_vvl_layer) .AND. ll_do_bclinic ) THEN   ! z_tilde or layer coordinate !
-         !                                                               ! ------baroclinic part------ !
-         ! I - initialization
-         ! ==================
-
-         ! 1 - barotropic divergence
-         ! -------------------------
-         zhdiv(:,:) = 0._wp
-         zht(:,:)   = 0._wp
-         DO jk = 1, jpkm1
-            zhdiv(:,:) = zhdiv(:,:) + e3t(:,:,jk,Kmm) * hdiv(:,:,jk)
-            zht  (:,:) = zht  (:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         zhdiv(:,:) = zhdiv(:,:) / ( zht(:,:) + 1. - tmask_i(:,:) )
-
-         ! 2 - Low frequency baroclinic horizontal divergence  (z-tilde case only)
-         ! --------------------------------------------------
-         IF( ln_vvl_ztilde ) THEN
-            IF( kt > nit000 ) THEN
-               DO jk = 1, jpkm1
-                  hdiv_lf(:,:,jk) = hdiv_lf(:,:,jk) - rn_Dt * frq_rst_hdv(:,:)   &
-                     &          * ( hdiv_lf(:,:,jk) - e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) )
-               END DO
-            ENDIF
-         ENDIF
-
-         ! II - after z_tilde increments of vertical scale factors
-         ! =======================================================
-         tilde_e3t_a(:,:,:) = 0._wp  ! tilde_e3t_a used to store tendency terms
-
-         ! 1 - High frequency divergence term
-         ! ----------------------------------
-         IF( ln_vvl_ztilde ) THEN     ! z_tilde case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - ( e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) - hdiv_lf(:,:,jk) )
-            END DO
-         ELSE                         ! layer case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) -   e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) * tmask(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 2 - Restoring term (z-tilde case only)
-         ! ------------------
-         IF( ln_vvl_ztilde ) THEN
-            DO jk = 1, jpk
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - frq_rst_e3t(:,:) * tilde_e3t_b(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 3 - Thickness diffusion term
-         ! ----------------------------
-         zwu(:,:) = 0._wp
-         zwv(:,:) = 0._wp
-         DO_3D( 1, 0, 1, 0, 1, jpkm1 )
-            un_td(ji,jj,jk) = rn_ahe3 * umask(ji,jj,jk) * e2_e1u(ji,jj)           &
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji+1,jj  ,jk) )
-            vn_td(ji,jj,jk) = rn_ahe3 * vmask(ji,jj,jk) * e1_e2v(ji,jj)           & 
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji  ,jj+1,jk) )
-            zwu(ji,jj) = zwu(ji,jj) + un_td(ji,jj,jk)
-            zwv(ji,jj) = zwv(ji,jj) + vn_td(ji,jj,jk)
-         END_3D
-         DO_2D( 1, 1, 1, 1 )
-            un_td(ji,jj,mbku(ji,jj)) = un_td(ji,jj,mbku(ji,jj)) - zwu(ji,jj)
-            vn_td(ji,jj,mbkv(ji,jj)) = vn_td(ji,jj,mbkv(ji,jj)) - zwv(ji,jj)
-         END_2D
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            tilde_e3t_a(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) + (   un_td(ji-1,jj  ,jk) - un_td(ji,jj,jk)    &
-               &                                          +     vn_td(ji  ,jj-1,jk) - vn_td(ji,jj,jk)    &
-               &                                            ) * r1_e1e2t(ji,jj)
-         END_3D
-         !                       ! d - thickness diffusion transport: boundary conditions
-         !                             (stored for tracer advction and continuity equation)
-         CALL lbc_lnk_multi( 'domvvl', un_td , 'U' , -1._wp, vn_td , 'V' , -1._wp)
-
-         ! 4 - Time stepping of baroclinic scale factors
-         ! ---------------------------------------------
-         CALL lbc_lnk( 'domvvl', tilde_e3t_a(:,:,:), 'T', 1._wp )
-         tilde_e3t_a(:,:,:) = tilde_e3t_b(:,:,:) + rDt * tmask(:,:,:) * tilde_e3t_a(:,:,:)
-
-         ! Maximum deformation control
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ALLOCATE( ze3t(jpi,jpj,jpk), llmsk(jpi,jpj,jpk) )
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            ze3t(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) / e3t_0(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
-         END_3D
-         !
-         llmsk(   1:Nis1,:,:) = .FALSE.   ! exclude halos from the checked region
-         llmsk(Nie1: jpi,:,:) = .FALSE.
-         llmsk(:,   1:Njs1,:) = .FALSE.
-         llmsk(:,Nje1: jpj,:) = .FALSE.
-         !
-         llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp                  ! define only the inner domain
-         z_tmax = MAXVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_max( 'domvvl', z_tmax )   ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_min( 'domvvl', z_tmin )   ! min over the global domain
-         ! - ML - test: for the moment, stop simulation for too large e3_t variations
-         IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            CALL mpp_maxloc( 'domvvl', ze3t, llmsk, z_tmax, ijk_max )
-            CALL mpp_minloc( 'domvvl', ze3t, llmsk, z_tmin, ijk_min )
-            IF (lwp) THEN
-               WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
-               WRITE(numout, *) 'at i, j, k=', ijk_max
-               WRITE(numout, *) 'MIN( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmin
-               WRITE(numout, *) 'at i, j, k=', ijk_min            
-               CALL ctl_stop( 'STOP', 'MAX( ABS( tilde_e3t_a(:,:,: ) ) / e3t_0(:,:,:) ) too high')
-            ENDIF
-         ENDIF
-         DEALLOCATE( ze3t, llmsk )
-         ! - ML - end test
-         ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
-         tilde_e3t_a(:,:,:) = MIN( tilde_e3t_a(:,:,:),   rn_zdef_max * e3t_0(:,:,:) )
-         tilde_e3t_a(:,:,:) = MAX( tilde_e3t_a(:,:,:), - rn_zdef_max * e3t_0(:,:,:) )
-
-         !
-         ! "tilda" change in the after scale factor
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - tilde_e3t_b(:,:,jk)
-         END DO
-         ! III - Barotropic repartition of the sea surface height over the baroclinic profile
-         ! ==================================================================================
-         ! add ( ssh increment + "baroclinicity error" ) proportionly to e3t(n)
-         ! - ML - baroclinicity error should be better treated in the future
-         !        i.e. locally and not spread over the water column.
-         !        (keep in mind that the idea is to reduce Eulerian velocity as much as possible)
-         zht(:,:) = 0.
-         DO jk = 1, jpkm1
-            zht(:,:)  = zht(:,:) + tilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-         z_scale(:,:) =  - zht(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = dtilde_e3t_a(:,:,jk) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-         END DO
-
-      ENDIF
-
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer )  THEN   ! z_tilde or layer coordinate !
-      !                                           ! ---baroclinic part--------- !
-         DO jk = 1, jpkm1
-            e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kaa) + dtilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-      ENDIF
-
-      IF( ln_vvl_dbg .AND. .NOT. ll_do_bclinic ) THEN   ! - ML - test: control prints for debuging
-         !
-         IF( lwp ) WRITE(numout, *) 'kt =', kt
-         IF ( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-            z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( zht(:,:) ) )
-            CALL mpp_max( 'domvvl', z_tmax )                             ! max over the global domain
-            IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(SUM(tilde_e3t_a))) =', z_tmax
-         END IF
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kmm) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshn-SUM(e3t(:,:,:,Kmm)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kaa) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kaa) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+ssha-SUM(e3t(:,:,:,Kaa)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kbb) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kbb) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshb-SUM(e3t(:,:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kbb) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kmm) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kmm)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kaa) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kaa)))) =', z_tmax
-      END IF
-
-      ! *********************************** !
-      ! After scale factors at u- v- points !
-      ! *********************************** !
-
-      CALL dom_vvl_interpol( e3t(:,:,:,Kaa), e3u(:,:,:,Kaa), 'U' )
-      CALL dom_vvl_interpol( e3t(:,:,:,Kaa), e3v(:,:,:,Kaa), 'V' )
-
-      ! *********************************** !
-      ! After depths at u- v points         !
-      ! *********************************** !
-
-      hu(:,:,Kaa) = e3u(:,:,1,Kaa) * umask(:,:,1)
-      hv(:,:,Kaa) = e3v(:,:,1,Kaa) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         hu(:,:,Kaa) = hu(:,:,Kaa) + e3u(:,:,jk,Kaa) * umask(:,:,jk)
-         hv(:,:,Kaa) = hv(:,:,Kaa) + e3v(:,:,jk,Kaa) * vmask(:,:,jk)
-      END DO
-      !                                        ! Inverse of the local depth
-!!gm BUG ?  don't understand the use of umask_i here .....
-      r1_hu(:,:,Kaa) = ssumask(:,:) / ( hu(:,:,Kaa) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kaa) = ssvmask(:,:) / ( hv(:,:,Kaa) + 1._wp - ssvmask(:,:) )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_nxt')
-      !
-   END SUBROUTINE dom_vvl_sf_nxt
-
-
-   SUBROUTINE dom_vvl_sf_update( kt, Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_update  ***
-      !!                   
-      !! ** Purpose :  for z tilde case: compute time filter and swap of scale factors 
-      !!               compute all depths and related variables for next time step
-      !!               write outputs and restart file
-      !!
-      !! ** Method  :  - swap of e3t with trick for volume/tracer conservation (ONLY FOR Z TILDE CASE)
-      !!               - reconstruct scale factor at other grid points (interpolate)
-      !!               - recompute depths and water height fields
-      !!
-      !! ** Action  :  - tilde_e3t_(b/n) ready for next time step
-      !!               - Recompute:
-      !!                    e3(u/v)_b       
-      !!                    e3w(:,:,:,Kmm)           
-      !!                    e3(u/v)w_b      
-      !!                    e3(u/v)w_n      
-      !!                    gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm)  and gde3w
-      !!                    h(u/v) and h(u/v)r
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
-      !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt              ! time step
-      INTEGER, INTENT( in ) ::   Kbb, Kmm, Kaa   ! time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoef        ! local scalar
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_update')
-      !
-      IF( kt == nit000 )   THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_update : - interpolate scale factors and compute depths for next time step'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
-      ENDIF
-      !
-      ! Time filter and swap of scale factors
-      ! =====================================
-      ! - ML - e3(t/u/v)_b are allready computed in dynnxt.
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         IF( l_1st_euler ) THEN
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:)
-         ELSE
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:) & 
-            &         + rn_atfp * ( tilde_e3t_b(:,:,:) - 2.0_wp * tilde_e3t_n(:,:,:) + tilde_e3t_a(:,:,:) )
-         ENDIF
-         tilde_e3t_n(:,:,:) = tilde_e3t_a(:,:,:)
-      ENDIF
-
-      ! Compute all missing vertical scale factor and depths
-      ! ====================================================
-      ! Horizontal scale factor interpolations
-      ! --------------------------------------
-      ! - ML - e3u(:,:,:,Kbb) and e3v(:,:,:,Kbb) are already computed in dynnxt
-      ! - JC - hu(:,:,:,Kbb), hv(:,:,:,:,Kbb), hur_b, hvr_b also
-      
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3f(:,:,:), 'F'  )
-      
-      ! Vertical scale factor interpolations
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm),  e3w(:,:,:,Kmm), 'W'  )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-      CALL dom_vvl_interpol( e3v(:,:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb),  e3w(:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( e3v(:,:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! t- and w- points depth (set the isf depth as it is in the initial step)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-        !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-                                                           ! 1 for jk = mikt
-         zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =    zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm) )  &
-             &             + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm) ) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-      END_3D
-
-      ! Local depth and Inverse of the local depth of the water
-      ! -------------------------------------------------------
-      !
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-      END DO
-
-      ! write restart file
-      ! ==================
-      IF( lrst_oce  )   CALL dom_vvl_rst( kt, Kbb, Kmm, 'WRITE' )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_update')
-      !
-   END SUBROUTINE dom_vvl_sf_update
-
-
-   SUBROUTINE dom_vvl_interpol( pe3_in, pe3_out, pout )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl__interpol  ***
-      !!
-      !! ** Purpose :   interpolate scale factors from one grid point to another
-      !!
-      !! ** Method  :   e3_out = e3_0 + interpolation(e3_in - e3_0)
-      !!                - horizontal interpolation: grid cell surface averaging
-      !!                - vertical interpolation: simple averaging
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::  pe3_in    ! input e3 to be interpolated
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::  pe3_out   ! output interpolated e3
-      CHARACTER(LEN=*)                , INTENT(in   ) ::  pout      ! grid point of out scale factors
-      !                                                             !   =  'U', 'V', 'W, 'F', 'UW' or 'VW'
-      !
-      INTEGER ::   ji, jj, jk                                       ! dummy loop indices
-      REAL(wp) ::  zlnwd                                            ! =1./0. when ln_wd_il = T/F
-      !!----------------------------------------------------------------------
-      !
-      IF(ln_wd_il) THEN
-        zlnwd = 1.0_wp
-      ELSE
-        zlnwd = 0.0_wp
-      END IF
-      !
-      SELECT CASE ( pout )    !==  type of interpolation  ==!
-         !
-      CASE( 'U' )                   !* from T- to U-point : hor. surface weighted mean
-         DO_3D( 1, 0, 1, 0, 1, jpk )
-            pe3_out(ji,jj,jk) = 0.5_wp * (  umask(ji,jj,jk) * (1.0_wp - zlnwd) + zlnwd ) * r1_e1e2u(ji,jj)   &
-               &                       * (   e1e2t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) )     &
-               &                           + e1e2t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) )
-         END_3D
-         CALL lbc_lnk( 'domvvl', pe3_out(:,:,:), 'U', 1._wp )
-         pe3_out(:,:,:) = pe3_out(:,:,:) + e3u_0(:,:,:)
-         !
-      CASE( 'V' )                   !* from T- to V-point : hor. surface weighted mean
-         DO_3D( 1, 0, 1, 0, 1, jpk )
-            pe3_out(ji,jj,jk) = 0.5_wp * ( vmask(ji,jj,jk)  * (1.0_wp - zlnwd) + zlnwd ) * r1_e1e2v(ji,jj)   &
-               &                       * (   e1e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) )     &
-               &                           + e1e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) )
-         END_3D
-         CALL lbc_lnk( 'domvvl', pe3_out(:,:,:), 'V', 1._wp )
-         pe3_out(:,:,:) = pe3_out(:,:,:) + e3v_0(:,:,:)
-         !
-      CASE( 'F' )                   !* from U-point to F-point : hor. surface weighted mean
-         DO_3D( 1, 0, 1, 0, 1, jpk )
-            pe3_out(ji,jj,jk) = 0.5_wp * (  umask(ji,jj,jk) * umask(ji,jj+1,jk) * (1.0_wp - zlnwd) + zlnwd ) &
-               &                       *    r1_e1e2f(ji,jj)                                                  &
-               &                       * (   e1e2u(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3u_0(ji,jj  ,jk) )     &
-               &                           + e1e2u(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3u_0(ji,jj+1,jk) ) )
-         END_3D
-         CALL lbc_lnk( 'domvvl', pe3_out(:,:,:), 'F', 1._wp )
-         pe3_out(:,:,:) = pe3_out(:,:,:) + e3f_0(:,:,:)
-         !
-      CASE( 'W' )                   !* from T- to W-point : vertical simple mean
-         !
-         pe3_out(:,:,1) = e3w_0(:,:,1) + pe3_in(:,:,1) - e3t_0(:,:,1)
-         ! - ML - The use of mask in this formulea enables the special treatment of the last w-point without indirect adressing
-!!gm BUG? use here wmask in case of ISF ?  to be checked
-         DO jk = 2, jpk
-            pe3_out(:,:,jk) = e3w_0(:,:,jk) + ( 1.0_wp - 0.5_wp * ( tmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd ) )   &
-               &                            * ( pe3_in(:,:,jk-1) - e3t_0(:,:,jk-1) )                               &
-               &                            +            0.5_wp * ( tmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd )     &
-               &                            * ( pe3_in(:,:,jk  ) - e3t_0(:,:,jk  ) )
-         END DO
-         !
-      CASE( 'UW' )                  !* from U- to UW-point : vertical simple mean
-         !
-         pe3_out(:,:,1) = e3uw_0(:,:,1) + pe3_in(:,:,1) - e3u_0(:,:,1)
-         ! - ML - The use of mask in this formaula enables the special treatment of the last w- point without indirect adressing
-!!gm BUG? use here wumask in case of ISF ?  to be checked
-         DO jk = 2, jpk
-            pe3_out(:,:,jk) = e3uw_0(:,:,jk) + ( 1.0_wp - 0.5_wp * ( umask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd ) )  &
-               &                             * ( pe3_in(:,:,jk-1) - e3u_0(:,:,jk-1) )                              &
-               &                             +            0.5_wp * ( umask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd )    &
-               &                             * ( pe3_in(:,:,jk  ) - e3u_0(:,:,jk  ) )
-         END DO
-         !
-      CASE( 'VW' )                  !* from V- to VW-point : vertical simple mean
-         !
-         pe3_out(:,:,1) = e3vw_0(:,:,1) + pe3_in(:,:,1) - e3v_0(:,:,1)
-         ! - ML - The use of mask in this formaula enables the special treatment of the last w- point without indirect adressing
-!!gm BUG? use here wvmask in case of ISF ?  to be checked
-         DO jk = 2, jpk
-            pe3_out(:,:,jk) = e3vw_0(:,:,jk) + ( 1.0_wp - 0.5_wp * ( vmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd ) )  &
-               &                             * ( pe3_in(:,:,jk-1) - e3v_0(:,:,jk-1) )                              &
-               &                             +            0.5_wp * ( vmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd )    &
-               &                             * ( pe3_in(:,:,jk  ) - e3v_0(:,:,jk  ) )
-         END DO
-      END SELECT
-      !
-   END SUBROUTINE dom_vvl_interpol
-
-
-   SUBROUTINE dom_vvl_rst( kt, Kbb, Kmm, cdrw )
-      !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE dom_vvl_rst  ***
-      !!                     
-      !! ** Purpose :   Read or write VVL file in restart file
-      !!
-      !! ** Method  :   use of IOM library
-      !!                if the restart does not contain vertical scale factors,
-      !!                they are set to the _0 values
-      !!                if the restart does not contain vertical scale factors increments (z_tilde),
-      !!                they are set to 0.
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt        ! ocean time-step
-      INTEGER         , INTENT(in) ::   Kbb, Kmm  ! ocean time level indices
-      CHARACTER(len=*), INTENT(in) ::   cdrw      ! "READ"/"WRITE" flag
-      !
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   id1, id2, id3, id4, id5     ! local integers
-      !!----------------------------------------------------------------------
-      !
-      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-         !                                   ! ===============
-         IF( ln_rstart ) THEN                   !* Read the restart file
-            CALL rst_read_open                  !  open the restart file if necessary
-            CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm)    )
-            !
-            id1 = iom_varid( numror, 'e3t_b', ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'e3t_n', ldstop = .FALSE. )
-            id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
-            id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
-            id5 = iom_varid( numror, 'hdiv_lf', ldstop = .FALSE. )
-            !
-            !                             ! --------- !
-            !                             ! all cases !
-            !                             ! --------- !
-            !
-            IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               ! needed to restart if land processor not computed 
-               IF(lwp) write(numout,*) 'dom_vvl_rst : e3t(:,:,:,Kbb) and e3t(:,:,:,Kmm) found in restart files'
-               WHERE ( tmask(:,:,:) == 0.0_wp ) 
-                  e3t(:,:,:,Kmm) = e3t_0(:,:,:)
-                  e3t(:,:,:,Kbb) = e3t_0(:,:,:)
-               END WHERE
-               IF( l_1st_euler ) THEN
-                  e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               ENDIF
-            ELSE IF( id1 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_n set equal to e3t_b.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               l_1st_euler = .true.
-            ELSE IF( id2 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kbb) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_b set equal to e3t_n.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ELSE
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart file'
-               IF(lwp) write(numout,*) 'Compute scale factor from sshn'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm) ) &
-                      &                          / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                      &          + e3t_0(:,:,jk)                               * (1._wp -tmask(:,:,jk))
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ENDIF
-            !                             ! ----------- !
-            IF( ln_vvl_zstar ) THEN       ! z_star case !
-               !                          ! ----------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN
-                  CALL ctl_stop( 'dom_vvl_rst: z_star cannot restart from a z_tilde or layer run' )
-               ENDIF
-               !                          ! ----------------------- !
-            ELSE                          ! z_tilde and layer cases !
-               !                          ! ----------------------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN  ! all required arrays exist
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
-               ELSE                            ! one at least array is missing
-                  tilde_e3t_b(:,:,:) = 0.0_wp
-                  tilde_e3t_n(:,:,:) = 0.0_wp
-               ENDIF
-               !                          ! ------------ !
-               IF( ln_vvl_ztilde ) THEN   ! z_tilde case !
-                  !                       ! ------------ !
-                  IF( id5 > 0 ) THEN  ! required array exists
-                     CALL iom_get( numror, jpdom_auto, 'hdiv_lf', hdiv_lf(:,:,:) )
-                  ELSE                ! array is missing
-                     hdiv_lf(:,:,:) = 0.0_wp
-                  ENDIF
-               ENDIF
-            ENDIF
-            !
-         ELSE                                   !* Initialize at "rest"
-            !
-
-            IF( ll_wd ) THEN   ! MJB ll_wd edits start here - these are essential 
-               !
-               IF( cn_cfg == 'wad' ) THEN
-                  ! Wetting and drying test case
-                  CALL usr_def_istate( gdept(:,:,:,Kbb), tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-                  ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-                  ssh (:,:,Kmm)     = ssh(:,:,Kbb)
-                  uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
-                  vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
-               ELSE
-                  ! if not test case
-                  ssh(:,:,Kmm) = -ssh_ref
-                  ssh(:,:,Kbb) = -ssh_ref
-
-                  DO_2D( 1, 1, 1, 1 )
-                     IF( ht_0(ji,jj)-ssh_ref <  rn_wdmin1 ) THEN ! if total depth is less than min depth
-                        ssh(ji,jj,Kbb) = rn_wdmin1 - (ht_0(ji,jj) )
-                        ssh(ji,jj,Kmm) = rn_wdmin1 - (ht_0(ji,jj) )
-                     ENDIF
-                  END_2D
-               ENDIF !If test case else
-
-               ! Adjust vertical metrics for all wad
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm)  ) &
-                    &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-
-               DO_2D( 1, 1, 1, 1 )
-                  IF ( ht_0(ji,jj) .LE. 0.0 .AND. NINT( ssmask(ji,jj) ) .EQ. 1) THEN
-                     CALL ctl_stop( 'dom_vvl_rst: ht_0 must be positive at potentially wet points' )
-                  ENDIF
-               END_2D
-               !
-            ELSE
-               !
-               ! usr_def_istate called here only to get ssh(Kbb) needed to initialize e3t(Kbb) and e3t(Kmm)
-               !
-               CALL usr_def_istate( gdept_0, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )  
-               !
-               ! usr_def_istate will be called again in istate_init to initialize ts, ssh, u and v
-               !
-               DO jk=1,jpk
-                  e3t(:,:,jk,Kbb) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kbb) ) &
-                    &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )   ! make sure e3t(:,:,:,Kbb) != 0 on land points
-               END DO
-               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               ssh(:,:,Kmm) = ssh(:,:,Kbb)                                     ! needed later for gde3w
-               !
-            END IF           ! end of ll_wd edits
-
-            IF( ln_vvl_ztilde .OR. ln_vvl_layer) THEN
-               tilde_e3t_b(:,:,:) = 0._wp
-               tilde_e3t_n(:,:,:) = 0._wp
-               IF( ln_vvl_ztilde ) hdiv_lf(:,:,:) = 0._wp
-            END IF
-         ENDIF
-         !
-      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-         !                                   ! ===================
-         IF(lwp) WRITE(numout,*) '---- dom_vvl_rst ----'
-         !                                           ! --------- !
-         !                                           ! all cases !
-         !                                           ! --------- !
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_b', e3t(:,:,:,Kbb) )
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t(:,:,:,Kmm) )
-         !                                           ! ----------------------- !
-         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
-            !                                        ! ----------------------- !
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_b', tilde_e3t_b(:,:,:))
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_n', tilde_e3t_n(:,:,:))
-         END IF
-         !                                           ! -------------!    
-         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
-            !                                        ! ------------ !
-            CALL iom_rstput( kt, nitrst, numrow, 'hdiv_lf', hdiv_lf(:,:,:))
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_rst
-
-
-   SUBROUTINE dom_vvl_ctl
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl_ctl  ***
-      !!                
-      !! ** Purpose :   Control the consistency between namelist options
-      !!                for vertical coordinate
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios
-      !!
-      NAMELIST/nam_vvl/ ln_vvl_zstar, ln_vvl_ztilde, ln_vvl_layer, ln_vvl_ztilde_as_zstar, &
-         &              ln_vvl_zstar_at_eqtor      , rn_ahe3     , rn_rst_e3t            , &
-         &              rn_lf_cutoff               , rn_zdef_max , ln_vvl_dbg                ! not yet implemented: ln_vvl_kepe
-      !!---------------------------------------------------------------------- 
-      !
-      READ  ( numnam_ref, nam_vvl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist' )
-      READ  ( numnam_cfg, nam_vvl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist' )
-      IF(lwm) WRITE ( numond, nam_vvl )
-      !
-      IF(lwp) THEN                    ! Namelist print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_vvl_ctl : choice/control of the variable vertical coordinate'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist nam_vvl : chose a vertical coordinate'
-         WRITE(numout,*) '      zstar                      ln_vvl_zstar   = ', ln_vvl_zstar
-         WRITE(numout,*) '      ztilde                     ln_vvl_ztilde  = ', ln_vvl_ztilde
-         WRITE(numout,*) '      layer                      ln_vvl_layer   = ', ln_vvl_layer
-         WRITE(numout,*) '      ztilde as zstar   ln_vvl_ztilde_as_zstar  = ', ln_vvl_ztilde_as_zstar
-         WRITE(numout,*) '      ztilde near the equator    ln_vvl_zstar_at_eqtor  = ', ln_vvl_zstar_at_eqtor
-         WRITE(numout,*) '      !'
-         WRITE(numout,*) '      thickness diffusion coefficient                      rn_ahe3      = ', rn_ahe3
-         WRITE(numout,*) '      maximum e3t deformation fractional change            rn_zdef_max  = ', rn_zdef_max
-         IF( ln_vvl_ztilde_as_zstar ) THEN
-            WRITE(numout,*) '      ztilde running in zstar emulation mode (ln_vvl_ztilde_as_zstar=T) '
-            WRITE(numout,*) '         ignoring namelist timescale parameters and using:'
-            WRITE(numout,*) '            hard-wired : z-tilde to zstar restoration timescale (days)'
-            WRITE(numout,*) '                         rn_rst_e3t     = 0.e0'
-            WRITE(numout,*) '            hard-wired : z-tilde cutoff frequency of low-pass filter (days)'
-            WRITE(numout,*) '                         rn_lf_cutoff   = 1.0/rn_Dt'
-         ELSE
-            WRITE(numout,*) '      z-tilde to zstar restoration timescale (days)        rn_rst_e3t   = ', rn_rst_e3t
-            WRITE(numout,*) '      z-tilde cutoff frequency of low-pass filter (days)   rn_lf_cutoff = ', rn_lf_cutoff
-         ENDIF
-         WRITE(numout,*) '         debug prints flag                                 ln_vvl_dbg   = ', ln_vvl_dbg
-      ENDIF
-      !
-      ioptio = 0                      ! Parameter control
-      IF( ln_vvl_ztilde_as_zstar )   ln_vvl_ztilde = .true.
-      IF( ln_vvl_zstar           )   ioptio = ioptio + 1
-      IF( ln_vvl_ztilde          )   ioptio = ioptio + 1
-      IF( ln_vvl_layer           )   ioptio = ioptio + 1
-      !
-      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE vertical coordinate in namelist nam_vvl' )
-      !
-      IF(lwp) THEN                   ! Print the choice
-         WRITE(numout,*)
-         IF( ln_vvl_zstar           ) WRITE(numout,*) '      ==>>>   zstar vertical coordinate is used'
-         IF( ln_vvl_ztilde          ) WRITE(numout,*) '      ==>>>   ztilde vertical coordinate is used'
-         IF( ln_vvl_layer           ) WRITE(numout,*) '      ==>>>   layer vertical coordinate is used'
-         IF( ln_vvl_ztilde_as_zstar ) WRITE(numout,*) '      ==>>>   to emulate a zstar coordinate'
-      ENDIF
-      !
-#if defined key_agrif
-      IF( (.NOT.Agrif_Root()).AND.(.NOT.ln_vvl_zstar) )   CALL ctl_stop( 'AGRIF is implemented with zstar coordinate only' )
-#endif
-      !
-   END SUBROUTINE dom_vvl_ctl
-
-#endif
-
-   !!======================================================================
-END MODULE domvvl
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/MY_SRC/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CANAL/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -26,5 +26,6 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called by istate.F90
+   PUBLIC   usr_def_istate       ! called by istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by sshwzv.F90
 
    !! * Substitutions
@@ -37,5 +38,5 @@
 CONTAINS
   
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -52,5 +53,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
       !
       INTEGER  :: ji, jj, jk, jl  ! dummy loop indices
@@ -87,7 +87,5 @@
 
       CASE(0)    ! rest
-         
-         ! sea level:
-         pssh(:,:) = 0.
+         !
          ! temperature:
          pts(:,:,:,jp_tem) = 10._wp
@@ -99,24 +97,5 @@
          
       CASE(1)    ! geostrophic zonal jet from -zjety to +zjety
-
-         ! sea level:
-         SELECT CASE( nn_fcase )
-         CASE(0)    ! f = f0
-            ! sea level: ssh = - fuy / g
-            WHERE( ABS(gphit) <= zjety )
-               pssh(:,:) = - ff_t(:,:) * rn_uzonal * gphit(:,:) * 1.e3 / grav
-            ELSEWHERE
-               pssh(:,:) = - ff_t(:,:) * rn_uzonal * SIGN(zjety, gphit(:,:)) * 1.e3 / grav
-            END WHERE
-         CASE(1)    ! f = f0 + beta*y
-            ! sea level: ssh = - u / g * ( fy + 0.5 * beta * y^2 )
-            zbeta = 2._wp * omega * COS( rad * rn_ppgphi0 ) / ra
-            WHERE( ABS(gphit) <= zjety )
-               pssh(:,:) = - rn_uzonal / grav * ( zf0 * gphit(:,:) * 1.e3 + 0.5 * zbeta * gphit(:,:) * gphit(:,:) * 1.e6 )
-            ELSEWHERE
-               pssh(:,:) = - rn_uzonal / grav * ( zf0 * SIGN(zjety, gphit(:,:)) * 1.e3   &
-                  &                             + 0.5 * zbeta * zjety * zjety * 1.e6 )
-            END WHERE
-         END SELECT
+         !
          ! temperature:
          pts(:,:,:,jp_tem) = 10._wp
@@ -139,25 +118,5 @@
          !                  
       CASE(2)    ! geostrophic zonal current shear
-      
-         ! sea level:
-         SELECT CASE( nn_fcase )
-         CASE(0)    ! f = f0
-            ! sea level: ssh = - fuy / g
-            WHERE( ABS(gphit) <= zjety )
-               pssh(:,:) = - ff_t(:,:) * rn_uzonal * ABS(gphit(:,:)) * 1.e3 / grav
-            ELSEWHERE
-               pssh(:,:) = - ff_t(:,:) * rn_uzonal * zjety * 1.e3 / grav
-            END WHERE
-         CASE(1)    ! f = f0 + beta*y
-            ! sea level: ssh = - u / g * ( fy + 0.5 * beta * y^2 )
-            zbeta = 2._wp * omega * COS( rad * rn_ppgphi0 ) / ra
-            WHERE( ABS(gphit) <= zjety )
-               pssh(:,:) = - SIGN(rn_uzonal, gphit(:,:)) / grav   &
-                  &        * ( zf0 * gphit(:,:) * 1.e3 + 0.5 * zbeta * gphit(:,:) * gphit(:,:) * 1.e6 )
-            ELSEWHERE
-               pssh(:,:) = - SIGN(rn_uzonal, gphit(:,:)) / grav   &
-                  &        * ( zf0 * SIGN(zjety, gphit(:,:)) * 1.e3 + 0.5 * zbeta * zjety * zjety * 1.e6 )
-            END WHERE
-         END SELECT
+         !
          ! temperature:
          pts(:,:,:,jp_tem) = 10._wp
@@ -176,5 +135,5 @@
          !                  
       CASE(3)    ! gaussian zonal currant
-
+         !
          ! zonal current
          DO jk=1, jpkm1
@@ -182,14 +141,4 @@
             pu(:,:,jk) = rn_uzonal * EXP( - 0.5 * gphit(:,:)**2 / rn_lambda**2 )
          END DO
-         
-         ! sea level:
-         pssh(:,1) = - ff_t(:,1) / grav * pu(:,1,1) * e2t(:,1)
-         DO jl=1, jpnj
-            DO_2D( 0, 0, 0, 0 )
-               pssh(ji,jj) = pssh(ji,jj-1) - ff_t(ji,jj) / grav * pu(ji,jj,1) * e2t(ji,jj)
-            END_2D
-            CALL lbc_lnk( 'usrdef_istate', pssh, 'T',  1. )
-         END DO
-         
          ! temperature:
          pts(:,:,:,jp_tem) = 10._wp
@@ -202,5 +151,5 @@
          !            
       CASE(4)    ! geostrophic zonal pulse
-   
+         !
          DO_2D( 1, 1, 1, 1 )
             IF ( ABS(glamt(ji,jj)) <= zjetx ) THEN
@@ -210,24 +159,22 @@
             ELSE
                zdu = 0.
-            END IF
+            ENDIF
             IF ( ABS(gphit(ji,jj)) <= zjety ) THEN
-               pssh(ji,jj) = - ff_t(ji,jj) * zdu * gphit(ji,jj) * 1.e3 / grav
                pu(ji,jj,:) = zdu
                pts(ji,jj,:,jp_sal) = zdu / rn_uzonal + 1.
             ELSE
-               pssh(ji,jj) = - ff_t(ji,jj) * zdu * SIGN(zjety,gphit(ji,jj)) * 1.e3 / grav 
                pu(ji,jj,:) = 0.
                pts(ji,jj,:,jp_sal) = 1.
-            END IF
-         END_2D
-         
+            ENDIF
+         END_2D
+         !
          ! temperature:
          pts(:,:,:,jp_tem) = 10._wp * ptmask(:,:,:)        
          pv(:,:,:) = 0.
-         
-       CASE(5)    ! vortex
-                  !
+         !
+      CASE(5)    ! vortex
+         !
          zf0   = 2._wp * omega * SIN( rad * rn_ppgphi0 )
-         zumax = rn_vtxmax * SIGN(1._wp, zf0) ! Here Anticyclonic: set zumax=-1 for cyclonic
+         zumax = rn_vtxmax * SIGN(1._wp, zf0)  ! Here Anticyclonic: set zumax=-1 for cyclonic
          zlambda = SQRT(2._wp)*rn_lambda*1.e3       ! Horizontal scale in meters 
          zn2 = 3.e-3**2
@@ -242,12 +189,4 @@
             ! Surface pressure: P(x,y,z) = F(z) * Psurf(x,y)
             zpsurf = zP0 * EXP(-(zx**2+zy**2)*zr_lambda2) - rho0 * ff_t(ji,jj) * rn_uzonal * zy
-            ! Sea level:
-            pssh(ji,jj) = 0.
-            DO jl=1,5
-               zdt = pssh(ji,jj)
-               zdzF = (1._wp - EXP(zdt-zH)) / (zH - 1._wp + EXP(-zH))   ! F'(z)
-               zrho1 = rho0 * (1._wp + zn2*zdt/grav) - zdzF * zpsurf / grav    ! -1/g Dz(P) = -1/g * F'(z) * Psurf(x,y)
-               pssh(ji,jj) = zpsurf / (zrho1*grav) * ptmask(ji,jj,1)   ! ssh = Psurf / (Rho*g)
-            END DO
             ! temperature:
             DO jk=1,jpk
@@ -299,16 +238,146 @@
          !            
       END SELECT
-      
+      !
+      CALL lbc_lnk( 'usrdef_istate', pts , 'T',  1. )
+      CALL lbc_lnk_multi( 'usrdef_istate', pu, 'U', -1., pv, 'V', -1. )
+
+   END SUBROUTINE usr_def_istate
+
+  
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracers
+      !!                Here CANAL configuration 
+      !!
+      !! ** Method  :   Set ssh 
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask             [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
+      !
+      INTEGER  :: ji, jj, jk, jl  ! dummy loop indices
+      REAL(wp) :: zx, zy, zP0, zumax, zlambda, zr_lambda2, zn2, zf0, zH, zrho1, za, zf, zdzF
+      REAL(wp) :: zpsurf, zdyPs, zdxPs
+      REAL(wp) :: zdt, zdu, zdv
+      REAL(wp) :: zjetx, zjety, zbeta
+      REAL(wp), DIMENSION(jpi,jpj)  ::   zrandom
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : CANAL configuration, analytical definition of initial state'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~   '
+      !
+      IF (ln_sshnoise) CALL RANDOM_NUMBER(zrandom)
+      zjetx = ABS(rn_ujetszx)/2.
+      zjety = ABS(rn_ujetszy)/2.
+      !
+      SELECT CASE(nn_initcase)
+      CASE(0)                      !==   rest  ==!
+         !
+         pssh(:,:) = 0.
+         !
+      CASE(1)                      !==  geostrophic zonal jet from -zjety to +zjety  ==!
+         !
+         SELECT CASE( nn_fcase )
+         CASE(0)                          !* f = f0 : ssh = - fuy / g
+            WHERE( ABS(gphit) <= zjety )
+               pssh(:,:) = - ff_t(:,:) * rn_uzonal * gphit(:,:) * 1.e3 / grav
+            ELSEWHERE
+               pssh(:,:) = - ff_t(:,:) * rn_uzonal * SIGN(zjety, gphit(:,:)) * 1.e3 / grav
+            END WHERE
+         CASE(1)                          !* f = f0 + beta*y : ssh = - u / g * ( fy + 0.5 * beta * y^2 )
+            zbeta = 2._wp * omega * COS( rad * rn_ppgphi0 ) / ra
+            WHERE( ABS(gphit) <= zjety )
+               pssh(:,:) = - rn_uzonal / grav * ( ff_t(:,:) * gphit(:,:) * 1.e3 + 0.5 * zbeta * gphit(:,:) * gphit(:,:) * 1.e6 )
+            ELSEWHERE
+               pssh(:,:) = - rn_uzonal / grav * ( ff_t(:,:) * SIGN(zjety, gphit(:,:)) * 1.e3   &
+                  &                             + 0.5 * zbeta * zjety * zjety * 1.e6 )
+            END WHERE
+         END SELECT
+         !                  
+      CASE(2)                      !==  geostrophic zonal current shear  ==!
+         !
+         SELECT CASE( nn_fcase )
+         CASE(0)                          !* f = f0 : ssh = - fuy / g
+            WHERE( ABS(gphit) <= zjety )
+               pssh(:,:) = - ff_t(:,:) * rn_uzonal * ABS(gphit(:,:)) * 1.e3 / grav
+            ELSEWHERE
+               pssh(:,:) = - ff_t(:,:) * rn_uzonal * zjety * 1.e3 / grav
+            END WHERE
+         CASE(1)                          !* f = f0 + beta*y : ssh = - u / g * ( fy + 0.5 * beta * y^2 )
+            zbeta = 2._wp * omega * COS( rad * rn_ppgphi0 ) / ra
+            WHERE( ABS(gphit) <= zjety )
+               pssh(:,:) = - SIGN(rn_uzonal, gphit(:,:)) / grav   &
+                  &        * ( ff_t(:,:) * gphit(:,:) * 1.e3 + 0.5 * zbeta * gphit(:,:) * gphit(:,:) * 1.e6 )
+            ELSEWHERE
+               pssh(:,:) = - SIGN(rn_uzonal, gphit(:,:)) / grav   &
+                  &        * ( ff_t(:,:) * SIGN(zjety, gphit(:,:)) * 1.e3 + 0.5 * zbeta * zjety * zjety * 1.e6 )
+            END WHERE
+         END SELECT
+         !                  
+      CASE(3)                      !==  gaussian zonal currant  ==!
+         !
+         pssh(:,1) = - ff_t(:,1) / grav * e2t(:,1) * rn_uzonal * EXP( - 0.5 * gphit(:,1)**2 / rn_lambda**2 )
+         DO jl=1, jpnj
+            DO_2D( 0, 0, 0, 0 )
+               pssh(ji,jj) = pssh(ji,jj-1) - ff_t(ji,jj) / grav * rn_uzonal * EXP( - 0.5 * gphit(ji,jj)**2 / rn_lambda**2 ) * e2t(ji,jj)
+            END_2D
+            CALL lbc_lnk( 'usrdef_istate_ssh', pssh, 'T',  1. )
+         END DO
+         !            
+      CASE(4)                      !==  geostrophic zonal pulse !!st need to implement a way to separate ssh properly  ==!
+         !
+         DO_2D( 1, 1, 1, 1 )
+            IF ( ABS(glamt(ji,jj)) <= zjetx ) THEN
+               zdu = rn_uzonal
+            ELSEIF ( ABS(glamt(ji,jj)) <= zjetx + 100. ) THEN
+               zdu = rn_uzonal * ( ( zjetx-ABS(glamt(ji,jj)) )/100. + 1. )
+            ELSE
+               zdu = 0.
+            ENDIF
+            IF ( ABS(gphit(ji,jj)) <= zjety ) THEN
+               pssh(ji,jj) = - ff_t(ji,jj) * zdu * gphit(ji,jj) * 1.e3 / grav
+            ELSE
+               pssh(ji,jj) = - ff_t(ji,jj) * zdu * SIGN(zjety,gphit(ji,jj)) * 1.e3 / grav 
+            ENDIF
+         END_2D
+         !
+      CASE(5)                    !==  vortex  ==!
+         !
+         zf0   = 2._wp * omega * SIN( rad * rn_ppgphi0 )
+         zumax = rn_vtxmax * SIGN(1._wp, zf0)   ! Here Anticyclonic: set zumax=-1 for cyclonic
+         zlambda = SQRT(2._wp)*rn_lambda        ! Horizontal scale in meters 
+         zn2 = 3.e-3**2
+         zH = 0.5_wp * 5000._wp
+         !
+         zr_lambda2 = 1._wp / zlambda**2
+         zP0 = rho0 * zf0 * zumax * zlambda * SQRT(EXP(1._wp)/2._wp)
+         !
+         DO_2D( 1, 1, 1, 1 )
+            zx = glamt(ji,jj) * 1.e3
+            zy = gphit(ji,jj) * 1.e3
+            !                                   ! Surface pressure: P(x,y,z) = F(z) * Psurf(x,y)
+            zpsurf = zP0 * EXP(-(zx**2+zy**2)*zr_lambda2) - rho0 * ff_t(ji,jj) * rn_uzonal * zy
+            pssh(ji,jj) = 0.
+            DO jl=1,5
+               zdt = pssh(ji,jj)
+               zdzF = (1._wp - EXP(zdt-zH)) / (zH - 1._wp + EXP(-zH))   ! F'(z)
+               zrho1 = rho0 * (1._wp + zn2*zdt/grav) - zdzF * zpsurf / grav    ! -1/g Dz(P) = -1/g * F'(z) * Psurf(x,y)
+               pssh(ji,jj) = zpsurf / (zrho1*grav) * ptmask(ji,jj,1)   ! ssh = Psurf / (Rho*g)
+            END DO
+         END_2D
+         !            
+      END SELECT
+      !                          !==  add noise  ==!
       IF (ln_sshnoise) THEN
          CALL RANDOM_SEED()
          CALL RANDOM_NUMBER(zrandom)
          pssh(:,:) = pssh(:,:) + ( 0.1  * zrandom(:,:) - 0.05 )
-      END IF
-      CALL lbc_lnk( 'usrdef_istate', pssh, 'T',  1. )
-      CALL lbc_lnk( 'usrdef_istate', pts , 'T',  1. )
-      CALL lbc_lnk_multi( 'usrdef_istate', pu, 'U', -1., pv, 'V', -1. )
-
-   END SUBROUTINE usr_def_istate
-
+      ENDIF
+      CALL lbc_lnk( 'usrdef_istate_ssh', pssh, 'T',  1. )
+      !
+   END SUBROUTINE usr_def_istate_ssh
+   
    !!======================================================================
 END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CPL_OASIS/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CPL_OASIS/EXPREF/namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/CPL_OASIS/EXPREF/namelist_cfg	(revision 14062)
@@ -367,5 +367,4 @@
 !-----------------------------------------------------------------------
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 0          ! =0   e3f = mean masked e3t divided by 4
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/ISOMIP+/MY_SRC/istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/ISOMIP+/MY_SRC/istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/ISOMIP+/MY_SRC/istate.F90	(revision 14062)
@@ -117,28 +117,14 @@
             CALL dta_tsd( nit000, 'ini', ts(:,:,:,:,Kbb) )       ! read 3D T and S data at nit000
             !
-            ssh(:,:,Kbb)   = 0._wp               ! set the ocean at rest
-            uu  (:,:,:,Kbb) = 0._wp
-            vv  (:,:,:,Kbb) = 0._wp  
+            uu (:,:,:,Kbb) = 0._wp
+            vv (:,:,:,Kbb) = 0._wp
             !
-            IF( ll_wd ) THEN
-               ssh(:,:,Kbb) =  -ssh_ref  ! Added in 30 here for bathy that adds 30 as Iterative test CEOD 
-               !
-               ! Apply minimum wetdepth criterion
-               !
-               DO_2D( 1, 1, 1, 1 )
-                  IF( ht_0(ji,jj) + ssh(ji,jj,Kbb)  < rn_wdmin1 ) THEN
-                     ssh(ji,jj,Kbb) = tmask(ji,jj,1)*( rn_wdmin1 - (ht_0(ji,jj)) )
-                  ENDIF
-               END_2D
-            ENDIF 
-             !
          ELSE                                 ! user defined initial T and S
             DO jk = 1, jpk
                zgdept(:,:,jk) = gdept(:,:,jk,Kbb)
             END DO
-            CALL usr_def_istate( zgdept, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )         
+            CALL usr_def_istate( zgdept, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb)  )         
          ENDIF
          ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-         ssh (:,:,Kmm)     = ssh(:,:,Kbb)   
          uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
          vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/ISOMIP/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/ISOMIP/MY_SRC/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/ISOMIP/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -9,4 +9,5 @@
    !! History :  NEMO ! 2016-11 (S. Flavoni)             Original code
    !!                 ! 2017-02 (P. Mathiot, S. Flavoni) Adapt code to ISOMIP case
+   !!                 ! 2020-11 (S. Techene, G. Madec) separate tsuv from ssh
    !!----------------------------------------------------------------------
 
@@ -24,5 +25,6 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called by istate.F90
+   PUBLIC   usr_def_istate       ! called by istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by domqco.F90
 
    !!----------------------------------------------------------------------
@@ -33,5 +35,5 @@
 CONTAINS
   
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -48,7 +50,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
-      !
-      INTEGER  ::   jk     ! dummy loop indices
       !!----------------------------------------------------------------------
       !
@@ -58,6 +57,4 @@
       pu  (:,:,:) = 0._wp        ! ocean at rest
       pv  (:,:,:) = 0._wp
-      pssh(:,:)   = 0._wp
-      !
       !                          ! T & S profiles
       pts(:,:,:,jp_tem) = - 1.9 * ptmask(:,:,:)          ! ISOMIP configuration : start from constant T+S fields
@@ -66,4 +63,25 @@
    END SUBROUTINE usr_def_istate
 
+
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of ssh
+      !!                Here ISOMIP configuration 
+      !!
+      !! ** Method  :   set ssh to 0
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask   [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height   [m]
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : ISOMIP configuration, analytical definition of initial state'
+      !
+      pssh(:,:)   = 0._wp
+      !
+   END SUBROUTINE usr_def_istate_ssh
+
    !!======================================================================
 END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_flux_ubs_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_flux_ubs_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_flux_ubs_cfg	(revision 14062)
@@ -201,5 +201,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_vect_ens_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_vect_ens_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/EXPREF/namelist_FCT2_vect_ens_cfg	(revision 14062)
@@ -129,5 +129,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/MY_SRC/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/LOCK_EXCHANGE/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -8,4 +8,5 @@
    !!======================================================================
    !! History :  NEMO ! 2016-03  (S. Flavoni, G. Madec) Original code
+   !!                 ! 2020-11  (S. Techene, G. Madec) separate tsuv from ssh
    !!----------------------------------------------------------------------
 
@@ -23,5 +24,6 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called by istate.F90
+   PUBLIC   usr_def_istate       ! called by istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by domqco.F90
 
    !!----------------------------------------------------------------------
@@ -32,5 +34,5 @@
 CONTAINS
   
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -47,5 +49,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
       !
       INTEGER  ::   jk     ! dummy loop indices
@@ -65,5 +66,4 @@
       pu  (:,:,:) = 0._wp        ! ocean at rest
       pv  (:,:,:) = 0._wp
-      pssh(:,:)   = 0._wp
       !
       !                          ! T & S profiles
@@ -78,4 +78,25 @@
    END SUBROUTINE usr_def_istate
 
+
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of ssh
+      !!                Here LOCK_EXCHANGE configuration 
+      !!
+      !! ** Method  :   set ssh to 0
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask   [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height   [m]
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : LOCK_EXCHANGE configuration, analytical definition of initial state'
+      !
+      pssh(:,:)   = 0._wp
+      !
+   END SUBROUTINE usr_def_istate_ssh
+
    !!======================================================================
 END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT2_flux_cen-ahm1000_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT2_flux_cen-ahm1000_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT2_flux_cen-ahm1000_cfg	(revision 14062)
@@ -139,5 +139,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT2_flux_ubs_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT2_flux_ubs_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT2_flux_ubs_cfg	(revision 14062)
@@ -139,5 +139,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT4_flux_cen-ahm1000_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT4_flux_cen-ahm1000_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT4_flux_cen-ahm1000_cfg	(revision 14062)
@@ -139,5 +139,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT4_flux_ubs_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT4_flux_ubs_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_sco_FCT4_flux_ubs_cfg	(revision 14062)
@@ -139,5 +139,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT2_flux_ubs_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT2_flux_ubs_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT2_flux_ubs_cfg	(revision 14062)
@@ -139,5 +139,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_flux_ubs_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_flux_ubs_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_flux_ubs_cfg	(revision 14062)
@@ -201,5 +201,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .false. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_vect_een_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_vect_een_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/EXPREF/namelist_zps_FCT4_vect_een_cfg	(revision 14062)
@@ -139,5 +139,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .true. !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/MY_SRC/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -8,4 +8,5 @@
    !!==============================================================================
    !! History :  NEMO ! 2016-03  (S. Flavoni, G. Madec) Original code
+   !!                 ! 2020-11  (S. Techene, G. Madec) separate tsuv from ssh
    !!----------------------------------------------------------------------
 
@@ -23,6 +24,7 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called by istate.F90
-
+   PUBLIC   usr_def_istate       ! called by istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by domqco.F90
+   
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -32,5 +34,5 @@
 CONTAINS
   
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -47,5 +49,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
       !
       INTEGER  ::   jk     ! dummy loop indices
@@ -65,5 +66,4 @@
       pu  (:,:,:) = 0._wp        ! ocean at rest
       pv  (:,:,:) = 0._wp
-      pssh(:,:)   = 0._wp
       !
       !                          ! T & S profiles
@@ -78,4 +78,25 @@
    END SUBROUTINE usr_def_istate
 
+
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of the ssh
+      !!                Here  OVERFLOW configuration 
+      !!
+      !! ** Method  :   set ssh to 0
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask   [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height   [m]
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : OVERFLOW configuration, analytical definition of initial state'
+      !
+      pssh(:,:)   = 0._wp
+      !
+   END SUBROUTINE usr_def_istate_ssh
+
    !!======================================================================
 END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/MY_SRC/usrdef_zgr.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/MY_SRC/usrdef_zgr.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/OVERFLOW/MY_SRC/usrdef_zgr.F90	(revision 14062)
@@ -193,4 +193,5 @@
             pdept(ji,jj,ik+1) = pdepw(ji,jj,ik+1) + pe3t (ji,jj,ik+1) * 0.5_wp
             pe3w (ji,jj,ik+1) = pdept(ji,jj,ik+1) - pdept(ji,jj,ik)              ! = pe3t (ji,jj,ik  )
+            pe3w (ji,jj,ik  ) = pdept(ji,jj,ik  ) - pdept(ji,jj,ik-1)            ! st caution ik > 1
          END_2D         
          !                                   ! bottom scale factors and depth at  U-, V-, UW and VW-points
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/axis_def_nemo.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/axis_def_nemo.xml	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/axis_def_nemo.xml	(revision 14062)
@@ -0,0 +1,1 @@
+link ../../../cfgs/SHARED/axis_def_nemo.xml
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/context_nemo.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/context_nemo.xml	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/context_nemo.xml	(revision 14062)
@@ -0,0 +1,37 @@
+<!--
+ ============================================================================================== 
+    NEMO context
+============================================================================================== 
+-->
+<context id="nemo">
+    <!-- $id$ -->
+    <variable_definition>
+       <!-- Year/Month/Day of time origin for NetCDF files; defaults to 1800-01-01 -->
+       <variable id="ref_year"  type="int"> 1900 </variable>
+       <variable id="ref_month" type="int"> 01 </variable>
+       <variable id="ref_day"   type="int"> 01 </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                     -->
+
+<!-- Files definition -->
+    <file_definition src="./file_def_nemo-oce.xml"/>     <!--  NEMO ocean dynamics                     -->
+
+<!-- Axis definition -->
+    <axis_definition src="./axis_def_nemo.xml"/>
+ 
+<!-- Domain definition -->
+    <domain_definition src="./domain_def_nemo.xml"/>
+
+<!-- Grids definition -->
+    <grid_definition   src="./grid_def_nemo.xml"/>
+  
+
+</context>
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/domain_def_nemo.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/domain_def_nemo.xml	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/domain_def_nemo.xml	(revision 14062)
@@ -0,0 +1,1 @@
+link ../../../cfgs/SHARED/domain_def_nemo.xml
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/field_def_nemo-oce.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/field_def_nemo-oce.xml	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/field_def_nemo-oce.xml	(revision 14062)
@@ -0,0 +1,1 @@
+link ../../../cfgs/SHARED/field_def_nemo-oce.xml
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/file_def_nemo-oce.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/file_def_nemo-oce.xml	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/file_def_nemo-oce.xml	(revision 14062)
@@ -0,0 +1,74 @@
+    <!-- 
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@_@startdate@_@enddate@" sync_freq="10d" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->
+     
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/> <!-- 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 id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+          <field field_ref="e3t"          name="e3t"       operation = "instant" />
+          <field field_ref="e3t_0"        name="e3t_0"     operation = "instant" />
+          <field field_ref="ht"           name="ht"        operation = "instant" />
+          <field field_ref="sKE"          name="sKE"       operation = "instant" />
+          <field field_ref="ssh"          name="sossheig"  operation = "instant" />
+          <field field_ref="wetdep"       name="hswe_wd"   operation = "instant" />
+        </file>
+
+        <file id="file2" name_suffix="_grid_U" description="ocean U grid variables" >
+          <field field_ref="e3u"          name="e3u"        operation = "instant" />
+          <field field_ref="e3u_0"        name="e3u_0"      operation = "instant" />
+          <field field_ref="hu"           name="hu"         operation = "instant" />
+          <field field_ref="ssu"          name="ssu"        operation = "instant"  />
+          <field field_ref="utau"         name="sozotaux"   operation = "instant"  />
+        </file>
+
+        <file id="file3" name_suffix="_grid_V" description="ocean V grid variables" >
+          <field field_ref="e3v"          name="e3v"        operation = "instant" />
+          <field field_ref="e3v_0"        name="e3v_0"      operation = "instant" />
+          <field field_ref="hv"           name="hv"         operation = "instant" />
+          <field field_ref="ssv"          name="ssv"        operation = "instant"  />
+          <field field_ref="vtau"         name="sometauy"   operation = "instant"  />
+        </file>
+        
+        <file id="file5" name_suffix="_grid_F" description="ocean F grid variables put on T grid" >
+          <field field_ref="e3f"            name="e3f"       operation = "instant" />
+          <field field_ref="e3f_0"          name="e3f_0"     operation = "instant" />
+          <field field_ref="hf"             name="hf"        operation = "instant" />
+          <field field_ref="sKEf"           name="sKEf"      operation = "instant" />
+          <field field_ref="relvor"         name="relvor"    operation = "instant" />
+          <field field_ref="plavor"         name="plavor"    operation = "instant" />
+          <field field_ref="abspotvor"      name="abspotvor" operation = "instant" />
+          <field field_ref="relpotvor"      name="relpotvor" operation = "instant" />
+          <field field_ref="Ens"            name="enstro"    operation = "instant" />
+        </file>
+      
+      </file_group>
+        
+      <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/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/grid_def_nemo.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/grid_def_nemo.xml	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/grid_def_nemo.xml	(revision 14062)
@@ -0,0 +1,1 @@
+link ../../../cfgs/SHARED/grid_def_nemo.xml
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/iodef.xml
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/iodef.xml	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/iodef.xml	(revision 14062)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<simulation> 
+
+<!-- ============================================================================================ -->
+<!-- XIOS context                                                                                 -->
+<!-- ============================================================================================ -->
+
+  <context id="xios">
+
+      <variable_definition>
+	
+	  <variable id="info_level"                type="int">0</variable>
+	  <variable id="using_server"              type="bool">false</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/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/namelist_cfg	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/namelist_cfg	(revision 14062)
@@ -0,0 +1,243 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/OCE  Configuration namelist : overwrite reference namelist
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!!                       SWG configuration                            !!
+!!======================================================================
+!!              ***  Domain & Run management namelists  ***           !!
+!!                                                                    !!
+!!   namrun       parameters of the run
+!!   namdom       space and time domain
+!!   namcfg       parameters of the configuration                       (default: user defined GYRE)
+!!   namwad       Wetting and drying                                    (default: OFF)
+!!   namtsd       data: temperature & salinity                          (default: OFF)
+!!   namcrs       coarsened grid (for outputs and/or TOP)               (ln_crs =T)
+!!   namc1d       1D configuration options                              ("key_c1d")
+!!   namc1d_dyndmp 1D newtonian damping applied on currents             ("key_c1d")
+!!   namc1d_uvd   1D data (currents)                                    ("key_c1d")
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namrun        !   parameters of the run
+!-----------------------------------------------------------------------
+   cn_exp      =  "SWG"    !  experience name
+   nn_it000    =       1   !  first time step
+   nn_itend    =   172800  !  10 ans  - 30 min - SWG 1/4deg
+!   nn_itend    =    86400  !  10 ans  - 1h
+   nn_leapy    =      30   !  Leap year calendar (1) or not (0)
+   nn_write    =     480   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   nn_istate   =       1   !  output the initial state (1) or not (0)
+/
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration                      (default: user defined GYRE)
+!-----------------------------------------------------------------------
+   ln_read_cfg = .false.   !  (=F) user defined configuration           (F => create/check namusr_def)
+/
+!-----------------------------------------------------------------------
+&namusr_def    !   SWG user defined namelist  
+!-----------------------------------------------------------------------
+   nn_SWG      =     4     !  SWG resolution [1/nn_SWG]
+   jpkglo      =     2     !  number of model levels
+   rn_theta    =     0.    !  rotation angle fo the grid [deg]
+   !
+   nn_gc       =        2        ! number of ghostcells 
+   rn_domsiz   =  2000000        ! size of the domain (default 2000km)  [m]
+   rn_dx       =   100000        ! gridspacing (default 100km)          [m]
+   !
+   rn_tau           = 0.20    ! wind stress on the surface    [N/m2]
+   rn_modified_grav = 0.02    ! modified gravity              [m/s2] 
+   rn_rfr           = 1.e-7   ! layer drag coefficient        [1/s] 
+   !
+   rn_beta = 2.e-11   ! beta-plan coriolis parameter  [1/m.s] 
+   rn_f0   = 0.7e-4   ! f-plan coriolis parameter     [1/s] 
+   !
+   nn_dynldf_lap_typ = 1        ! choose type of laplacian (ideally from namelist)
+   !                            !       = 1   divrot    laplacian
+   !                            !       = 2   symmetric laplacian (Griffies&Hallberg 2000)
+   !                            !       = 3   symmetric laplacian (cartesian)
+   !
+   rn_abp = 1.e-2     ! alpha boundary parameter                                       [-]
+   nn_cnp = 1         ! number of cell on which is smoothed the porosity (phi)         [-]
+   rn_fsp = 0.        ! friction parameter 1/epsilon of the permeability                 [1/s]
+   !
+/
+!-----------------------------------------------------------------------
+&namdom        !   time and space domain
+!-----------------------------------------------------------------------
+   ln_linssh   = .false.    !  =T  linear free surface  ==>>  model level are fixed in time
+   !
+!   rn_Dt      = 3600.     !  1h    - SWG 1 deg
+   rn_Dt       = 1800.     !  30min - SWG 1/4deg
+   ln_meshmask = .false.   !  =T create a mesh file
+/
+!!======================================================================
+!!            ***  Surface Boundary Condition namelists  ***          !!
+!!                                                                    !!
+!!   namsbc          surface boundary condition manager                 (default: NO selection)
+!!   namsbc_flx      flux               formulation                     (ln_flx     =T)
+!!   namsbc_blk      Bulk formulae formulation                          (ln_blk     =T)
+!!   namsbc_cpl      CouPLed            formulation                     ("key_oasis3" )
+!!   namsbc_sas      Stand-Alone Surface module                         (SAS_SRC  only)
+!!   namsbc_iif      Ice-IF: use observed ice cover                     (nn_ice = 1   )
+!!   namtra_qsr      penetrative solar radiation                        (ln_traqsr  =T)
+!!   namsbc_ssr      sea surface restoring term (for T and/or S)        (ln_ssr     =T)
+!!   namsbc_rnf      river runoffs                                      (ln_rnf     =T)
+!!   namsbc_apr      Atmospheric Pressure                               (ln_apr_dyn =T)
+!!   namsbc_isf      ice shelf melting/freezing                         (ln_isfcav  =T : read (ln_read_cfg=T) or set or usr_def_zgr )
+!!   namsbc_iscpl    coupling option between land ice model and ocean   (ln_isfcav  =T)
+!!   namsbc_wave     external fields from wave model                    (ln_wave    =T)
+!!   namberg         iceberg floats                                     (ln_icebergs=T)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namsbc        !   Surface Boundary Condition (surface module)          (default: NO selection)
+!-----------------------------------------------------------------------
+   nn_fsbc     = 1         !  frequency of SBC module call
+   ln_usr      = .true.    !  user defined formulation                  (T => check usrdef_sbc)
+   ln_traqsr   = .false.    !  Light penetration in the ocean            (T => fill namtra_qsr)
+/
+!!======================================================================
+!!               ***  Lateral boundary condition  ***                 !!
+!!                                                                    !!
+!!   namlbc        lateral momentum boundary condition                  (default: NO selection)
+!!   namagrif      agrif nested grid ( read by child model only )       ("key_agrif")
+!!   nam_tide      Tidal forcing                                        (default: OFF)
+!!   nambdy        Unstructured open boundaries                         (default: OFF)
+!!   nambdy_dta    Unstructured open boundaries - external data         (see  nambdy)
+!!   nambdy_tide   tidal forcing at open boundaries                     (default: OFF)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namlbc        !   lateral momentum boundary condition                  (default: NO selection)
+!-----------------------------------------------------------------------
+   !                       !  free slip  !   partial slip  !   no slip   ! strong slip
+   rn_shlat    =    0.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
+/
+!!======================================================================
+!!                ***  Top/Bottom boundary condition  ***             !!
+!!                                                                    !!
+!!   namdrg        top/bottom drag coefficient                          (default: NO selection)
+!!   namdrg_top    top    friction                                      (ln_OFF=F & ln_isfcav=T)
+!!   namdrg_bot    bottom friction                                      (ln_OFF=F)
+!!   nambbc        bottom temperature boundary condition                (default: OFF)
+!!   nambbl        bottom boundary layer scheme                         (default: OFF)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdrg        !   top/bottom drag coefficient                          (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_OFF = .true.     !  no bottom friction (but layer drag applied)
+/
+!!======================================================================
+!!                      ***  Dynamics namelists  ***                  !!
+!!                                                                    !!
+!!   nam_vvl       vertical coordinate options                          (default: z-star)
+!!   namdyn_adv    formulation of the momentum advection                (default: NO selection)
+!!   namdyn_vor    advection scheme                                     (default: NO selection)
+!!   namdyn_hpg    hydrostatic pressure gradient                        (default: NO selection)
+!!   namdyn_spg    surface pressure gradient                            (default: NO selection)
+!!   namdyn_ldf    lateral diffusion scheme                             (default: NO selection)
+!!   namdta_dyn    offline TOP: dynamics read in files                  (OFF_SRC only)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynadv_OFF = .false. !  linear dynamics (no momentum advection)
+   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
+   ln_dynadv_ubs = .false. !  flux form - 3rd order UBS      scheme
+/
+!-----------------------------------------------------------------------
+&namdyn_vor    !   Vorticity / Coriolis scheme                          (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynvor_ene = .false. !  energy    conserving scheme
+   ln_dynvor_ens = .true. !  enstrophy conserving scheme
+   ln_dynvor_enT = .false. !  energy conserving scheme (T-point)
+   ln_dynvor_eeT = .false. !  energy conserving scheme (een using e3t)
+   ln_dynvor_een = .false. !  energy & enstrophy scheme
+      nn_e3f_typ = 1          ! =0  e3f = mi(mj(e3t))/4
+      !                       ! =1  e3f = mi(mj(e3t))/mi(mj( tmask))
+   ln_dynvor_msk = .true.  !  vorticity multiplied by fmask (=T)        
+      !                    !  (f-point vorticity schemes only)
+/
+!-----------------------------------------------------------------------
+&namdyn_spg    !   surface pressure gradient                            (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynspg_exp  = .true.   ! explicit free surface
+/
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_dynldf_lap =  .true.     !    laplacian operator
+   ln_dynldf_lev =  .true.     !  iso-level
+   ! choisit telle que la friction laterale, au 1deg, egale celle de GYRE 
+   nn_ahm_ijk_t  = 0           !  = 0  constant = 1/2  Uv*Lv   (lap case) 
+      rn_Uv      = 2.0         !  lateral viscous velocity [m/s] 
+      rn_Lv      = 500         !  lateral viscous length   [m]  - at 1/4deg 
+!      rn_Lv      = 100.e+3     !  lateral viscous length   [m]  - 1 deg
+/
+!!======================================================================
+!!                     vertical physics namelists                     !!
+!!                                                                    !!
+!!    namzdf        vertical physics manager                            (default: NO selection)
+!!    namzdf_ric    richardson number vertical mixing                   (ln_zdfric=T)
+!!    namzdf_tke    TKE vertical mixing                                 (ln_zdftke=T)
+!!    namzdf_gls    GLS vertical mixing                                 (ln_zdfgls=T)
+!!    namzdf_osm    OSM vertical diffusion                              (ln_zdfosm=T)
+!!    namzdf_iwm    tidal mixing parameterization                       (ln_zdfiwm=T)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics                                     (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_zdftke   = .true.       !  Turbulent Kinetic Energy closure       (T =>   fill namzdf_tke)
+   ln_zdfevd   = .true.       !  enhanced vertical diffusion
+      nn_evdm     =    1         ! apply on tracer (=0) or on tracer and momentum (=1)
+      rn_evd      =  100.        ! mixing coefficient [m2/s]
+   !                       ! coefficients
+   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)
+   nn_avb      =    0         !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0         !  horizontal shape for avtb (=1) or not (=0)
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  (ln_zdftke =T)
+!-----------------------------------------------------------------------
+   nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to internal & intertial waves
+/
+!!======================================================================
+!!                  ***  Diagnostics namelists  ***                   !!
+!!                                                                    !!
+!!   namtrd       dynamics and/or tracer trends                         (default: OFF)
+!!   namptr       Poleward Transport Diagnostics                        (default: OFF)
+!!   namhsb       Heat and salt budgets                                 (default: OFF)
+!!   namdiu       Cool skin and warm layer models                       (default: OFF)
+!!   namdiu       Cool skin and warm layer models                       (default: OFF)
+!!   namflo       float parameters                                      (default: OFF)
+!!   nam_diadct   transports through some sections                      (default: OFF)
+!!   nam_dia25h   25h Mean Output                                       (default: OFF)
+!!   namnc4       netcdf4 chunking and compression settings             ("key_netcdf4")
+!!======================================================================
+!
+!!======================================================================
+!!                  ***  Miscellaneous namelists  ***                 !!
+!!                                                                    !!
+!!   nammpp            Massively Parallel Processing                    ("key_mpp_mpi")
+!!   namctl            Control prints                                   (default: OFF)
+!!   namsto            Stochastic parametrization of EOS                (default: OFF)
+!!======================================================================
+!
+!
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namctl        !   Control prints                                       (default: OFF)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsto        ! Stochastic parametrization of EOS                      (default: OFF)
+!-----------------------------------------------------------------------
+/
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/namelist_ref
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/namelist_ref	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/EXPREF/namelist_ref	(revision 14062)
@@ -0,0 +1,1 @@
+link ../../../cfgs/SHARED/namelist_ref
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_fmask.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_fmask.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_fmask.F90	(revision 14062)
@@ -0,0 +1,148 @@
+MODULE usrdef_fmask
+   !!======================================================================
+   !!                     ***  MODULE usrdef_fmask   ***
+   !!
+   !!                      ===  ORCA configuration  ===
+   !!                            (2 and 1 degrees)
+   !!
+   !! User defined : alteration of land/sea f-point mask in some straits
+   !!======================================================================
+   !! History :  4.0  ! 2016-06  (G. Madec, S. Flavoni)  Original code
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   usr_def_fmask  : alteration of f-point land/ocean mask in some straits
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   !
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp         ! Massively Parallel Processing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   usr_def_fmask    ! routine called by dommsk.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: usrdef_fmask.F90 10425 2018-12-19 21:54:16Z smasson $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE usr_def_fmask( cd_cfg, kcfg, pfmsk )
+      !!---------------------------------------------------------------------
+      !!                 ***  ROUTINE dom_msk  ***
+      !!
+      !! ** Purpose :   User defined alteration of the lateral boundary 
+      !!              condition on velocity.
+      !!
+      !! ** Method  :   Local change of the value of fmask at lateral ocean/land 
+      !!              boundary in straits in order to increase the viscous 
+      !!              boundary layer and thus reduce the transport through the 
+      !!              corresponding straits.
+      !!                Here only alterations in ORCA R2 and R1 cases
+      !!
+      !! ** Action :   fmask : land/ocean mask at f-point with increased value 
+      !!                       in some user defined straits
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*)          , INTENT(in   ) ::   cd_cfg   ! configuration name
+      INTEGER                   , INTENT(in   ) ::   kcfg     ! configuration identifier 
+      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pfmsk    ! Ocean/Land f-point mask including lateral boundary cond.
+      !
+      INTEGER  ::   iif, iil, ii0, ii1, ii   ! local integers
+      INTEGER  ::   ijf, ijl, ij0, ij1       !   -       -
+      INTEGER  ::   isrow                    ! index for ORCA1 starting row
+      !!----------------------------------------------------------------------
+      !
+      IF( TRIM( cd_cfg ) == "orca" ) THEN      !==  ORCA Configurations  ==!
+         !
+         SELECT CASE ( kcfg )
+         !
+         CASE( 2 )                           !  R2 case
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_fmask : ORCA_R2: increase lateral friction near the following straits:'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
+            !
+            IF(lwp) WRITE(numout,*) '      Gibraltar '
+            ij0 = 101   ;   ij1 = 101           ! Gibraltar strait  : partial slip (pfmsk=0.5)
+            ii0 = 139   ;   ii1 = 140   ;   pfmsk( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  0.5_wp
+            ij0 = 102   ;   ij1 = 102
+            ii0 = 139   ;   ii1 = 140   ;   pfmsk( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  0.5_wp
+            !
+            IF(lwp) WRITE(numout,*) '      Bab el Mandeb '
+            ij0 =  87   ;   ij1 =  88           ! Bab el Mandeb : partial slip (pfmsk=1)
+            ii0 = 160   ;   ii1 = 160   ;   pfmsk( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  1._wp
+            ij0 =  88   ;   ij1 =  88
+            ii0 = 159   ;   ii1 = 159   ;   pfmsk( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) =  1._wp
+            !
+            ! We keep this as an example but it is instable in this case 
+            !IF(lwp) WRITE(numout,*) '      Danish straits '
+            !         ij0 = 115   ;   ij1 = 115 ! Danish straits  : strong slip (pfmsk > 2)
+            !         ii0 = 145   ;   ii1 = 146   ;   pfmsk( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) = 4._wp
+            !         ij0 = 116   ;   ij1 = 116
+            !         ii0 = 145   ;   ii1 = 146   ;   pfmsk( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) , 1:jpk ) = 4._wp
+            !
+         CASE( 1 )                           ! R1 case
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_fmask : ORCA_R1: increase lateral friction near the following straits:'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'   
+!!gm    ! This dirty section will be suppressed by simplification process:
+!!gm    ! all this will come back in input files
+!!gm    ! Currently these hard-wired indices relate to configuration with extend grid (jpjglo=332)
+            !
+            isrow = 332 - jpjglo
+            !
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '   orca_r1: increase friction near the following straits : '
+            IF(lwp) WRITE(numout,*) '      Gibraltar '
+            ii0 = 282           ;   ii1 = 283        ! Gibraltar Strait 
+            ij0 = 241 - isrow   ;   ij1 = 241 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
+            !
+            IF(lwp) WRITE(numout,*) '      Bhosporus '
+            ii0 = 314           ;   ii1 = 315        ! Bhosporus Strait 
+            ij0 = 248 - isrow   ;   ij1 = 248 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
+            !
+            IF(lwp) WRITE(numout,*) '      Makassar (Top) '
+            ii0 =  48           ;   ii1 =  48        ! Makassar Strait (Top) 
+            ij0 = 189 - isrow   ;   ij1 = 190 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 3._wp  
+            !
+            IF(lwp) WRITE(numout,*) '      Lombok '
+            ii0 =  44           ;   ii1 =  44        ! Lombok Strait 
+            ij0 = 164 - isrow   ;   ij1 = 165 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
+            !
+            IF(lwp) WRITE(numout,*) '      Ombai '
+            ii0 =  53           ;   ii1 =  53        ! Ombai Strait 
+            ij0 = 164 - isrow   ;   ij1 = 165 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
+            !
+            IF(lwp) WRITE(numout,*) '      Timor Passage '
+            ii0 =  56           ;   ii1 =  56        ! Timor Passage 
+            ij0 = 164 - isrow   ;   ij1 = 165 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 2._wp  
+            !
+            IF(lwp) WRITE(numout,*) '      West Halmahera '
+            ii0 =  58           ;   ii1 =  58        ! West Halmahera Strait 
+            ij0 = 181 - isrow   ;   ij1 = 182 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 3._wp  
+            !
+            IF(lwp) WRITE(numout,*) '      East Halmahera '
+            ii0 =  55           ;   ii1 =  55        ! East Halmahera Strait 
+            ij0 = 181 - isrow   ;   ij1 = 182 - isrow   ;   pfmsk( mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),1:jpk ) = 3._wp  
+            !
+         CASE DEFAULT
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_fmask : ORCA_R', kcfg,' : NO alteration of fmask in specific straits '
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'   
+         END SELECT
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'usr_def_fmask : NO alteration of fmask in specific straits '
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~'
+      ENDIF
+      !
+      CALL lbc_lnk( 'usrdef_fmask', pfmsk, 'F', 1._wp )      ! Lateral boundary conditions on fmask
+      !
+   END SUBROUTINE usr_def_fmask
+   
+   !!======================================================================
+END MODULE usrdef_fmask
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_hgr.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_hgr.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_hgr.F90	(revision 14062)
@@ -0,0 +1,166 @@
+MODULE usrdef_hgr
+   !!======================================================================
+   !!                     ***  MODULE usrdef_hgr   ***
+   !!
+   !!                     ===  SWG configuration  ===
+   !!
+   !! User defined :   mesh and Coriolis parameter of a user configuration
+   !!======================================================================
+   !! History :  4.0  ! 2016-03  (S. Flavoni)
+   !!             -   ! 2020-03  (A. Nasser) Shallow Water Eq. configuration
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   usr_def_hgr   : initialize the horizontal mesh 
+   !!----------------------------------------------------------------------
+   USE dom_oce  , ONLY: nimpp, njmpp       ! ocean space and time domain
+   USE par_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   USE usrdef_nam     !
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   usr_def_hgr   ! called in domhgr.F90
+   
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: usrdef_hgr.F90 10069 2018-08-28 14:12:24Z nicolasmartin $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE usr_def_hgr( plamt , plamu , plamv  , plamf  ,   &   ! geographic position (required)
+      &                    pphit , pphiu , pphiv  , pphif  ,   &   !
+      &                    kff   , pff_f , pff_t  ,            &   ! Coriolis parameter  (if domain not on the sphere)
+      &                    pe1t  , pe1u  , pe1v   , pe1f   ,   &   ! scale factors       (required)
+      &                    pe2t  , pe2u  , pe2v   , pe2f   ,   &   !
+      &                    ke1e2u_v      , pe1e2u , pe1e2v     )   ! u- & v-surfaces (if gridsize reduction is used in strait(s))
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE usr_def_hgr  ***
+      !!
+      !! ** Purpose :   user defined mesh and Coriolis parameter
+      !!
+      !! ** Method  :   set all intent(out) argument to a proper value
+      !!
+      !!                Here SWG configuration :
+      !!          Rectangular mid-latitude domain 
+      !!          - with axes rotated by 45 degrees
+      !!          - a constant horizontal resolution of 106 km 
+      !!          - on a beta-plane
+      !!
+      !! ** Action  : - define longitude & latitude of t-, u-, v- and f-points (in degrees) 
+      !!              - define coriolis parameter at f-point if the domain in not on the sphere (on beta-plane)
+      !!              - define i- & j-scale factors at t-, u-, v- and f-points (in meters)
+      !!              - define u- & v-surfaces (if gridsize reduction is used in some straits) (in m2)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   plamt, plamu, plamv, plamf   ! longitude outputs                     [degrees]
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pphit, pphiu, pphiv, pphif   ! latitude outputs                      [degrees]
+      INTEGER                 , INTENT(out) ::   kff                          ! =1 Coriolis parameter computed here, =0 otherwise
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pff_f, pff_t                 ! Coriolis factor at f-point                [1/s]
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pe1t, pe1u, pe1v, pe1f       ! i-scale factors                             [m]
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pe2t, pe2u, pe2v, pe2f       ! j-scale factors                             [m]
+      INTEGER                 , INTENT(out) ::   ke1e2u_v                     ! =1 u- & v-surfaces computed here, =0 otherwise 
+      REAL(wp), DIMENSION(:,:), INTENT(out) ::   pe1e2u, pe1e2v               ! u- & v-surfaces (if reduction in strait)   [m2]
+      !
+      INTEGER  ::   ji, jj               ! dummy loop indices
+      REAL(wp) ::   zlam1, zlam0, zcos_theta, zim1 , zjm1 , ze1  , ze1deg ! local scalars
+      REAL(wp) ::   zphi1, zphi0, zsin_theta, zim05, zjm05, znorme        !   -      -
+      REAL(wp) ::   zgl, zbl      !   -      -
+
+      !!-------------------------------------------------------------------------------
+      !
+      !     !==  beta-plane with regular grid-spacing and rotated domain ==!  (SWG configuration)
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_hgr : SWG configuration (beta-plane with rotated regular grid-spacing)'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      !
+      !
+      !                       !==  grid point position  ==!
+      !
+      ze1 =  rn_dx / REAL(nn_SWG, wp)                    ! [m] gridspacing used
+      zgl =  rn_domsiz + 2._wp * REAL(nn_gc, wp) * ze1   ! [m] length of the square with ghostcells
+      ! fit the best square around the square + ghost cells 
+      zbl = zgl * ( COS( rn_theta * rad ) + SIN( rn_theta * rad ) )   ! length side bigger domain [m]                                 
+
+      ! unrotated (0deg) 
+      !zcos_theta = 1._wp
+      !zsin_theta = 0._wp
+      ! rotated case (45deg)
+      !zcos_theta =   1._wp / SQRT( 2._wp ) 
+      !zsin_theta =   1._wp / SQRT( 2._wp )  
+      ! rotation angle
+      zcos_theta = COS( rn_theta * rad)
+      zsin_theta = SIN( rn_theta * rad)   
+
+      ! exact origin in meters
+      zlam1 =  zbl * COS((rn_theta + 45 )* rad ) / SQRT( 2._wp )  - rn_domsiz/2._wp 
+      zphi1 =  zbl * SIN((rn_theta + 45 )* rad ) / SQRT( 2._wp )  - rn_domsiz/2._wp 
+      ! origin put in the true corner of a cell so there will be no cropping 
+      ! of the edge cells
+      zlam0 = REAL( anint( zlam1 / ze1 ), wp ) * ze1
+      zphi0 = REAl( anint( zphi1 / ze1 ), wp ) * ze1
+
+      IF(lwp) WRITE(numout,*) '                  origin position    zlam0   = ', zlam0/1000,   ' km'
+      IF(lwp) WRITE(numout,*) '                  origin position    zphi0   = ', zphi0/1000,   ' km'
+
+      ! O1M = OM x rotation_theta + OO1
+      ! zim1, zim05, zjm1, zjm05 fit for 2 ghost cells on each side
+      DO jj = 1, jpj 
+         DO ji = 1, jpi 
+            zim1 = REAL( ji + nimpp - 1 )   ;   zim05 = REAL( ji + nimpp - 1 ) - 0.5 
+            zjm1 = REAL( jj + njmpp - 1 )   ;   zjm05 = REAL( jj + njmpp - 1 ) - 0.5 
+            !   
+            !glamt(i,j) position (meters) at T-point 
+            !gphit(i,j) position (meters) at T-point  
+            plamt(ji,jj) =   zim05 * ze1 * zcos_theta - zjm05 * ze1 * zsin_theta - zlam0
+            pphit(ji,jj) = + zim05 * ze1 * zsin_theta + zjm05 * ze1 * zcos_theta - zphi0
+            !   
+            !glamu(i,j) position (meters) at U-point
+            !gphiu(i,j) position (meters) at U-point
+            plamu(ji,jj) =   zim1  * ze1 * zcos_theta - zjm05 * ze1 * zsin_theta - zlam0
+            pphiu(ji,jj) = + zim1  * ze1 * zsin_theta + zjm05 * ze1 * zcos_theta - zphi0
+            !   
+            !glamv(i,j) position (meters) at V-point
+            !gphiv(i,j) position (meters) at V-point
+            plamv(ji,jj) =   zim05 * ze1 * zcos_theta - zjm1  * ze1 * zsin_theta - zlam0
+            pphiv(ji,jj) = + zim05 * ze1 * zsin_theta + zjm1  * ze1 * zcos_theta - zphi0
+            !
+            !glamf(i,j) position (meters) at F-point
+            !gphif(i,j) position (meters) at F-point 
+            plamf(ji,jj) =   zim1  * ze1 * zcos_theta - zjm1  * ze1 * zsin_theta - zlam0
+            pphif(ji,jj) = + zim1  * ze1 * zsin_theta + zjm1  * ze1 * zcos_theta - zphi0
+         END DO
+      END DO
+      !
+      !                       !== Horizontal scale factors ==! (in meters)
+      !                     
+      !                                         ! constant grid spacing
+      pe1t(:,:) =  ze1     ;      pe2t(:,:) = ze1
+      pe1u(:,:) =  ze1     ;      pe2u(:,:) = ze1
+      pe1v(:,:) =  ze1     ;      pe2v(:,:) = ze1
+      pe1f(:,:) =  ze1     ;      pe2f(:,:) = ze1
+      !
+      !                                         ! NO reduction of grid size in some straits 
+      ke1e2u_v = 0                              !    ==>> u_ & v_surfaces will be computed in dom_ghr routine
+      pe1e2u(:,:) = 0._wp                       !    CAUTION: set to zero to avoid error with some compilers that
+      pe1e2v(:,:) = 0._wp                       !             require an initialization of INTENT(out) arguments
+      !
+      !
+      !                       !==  Coriolis parameter  ==!
+      kff = 1                                            !  indicate not to compute ff afterward
+      !
+      pff_f(:,:) =  REAL( rn_f0, wp ) + REAL( rn_beta, wp ) * ABS( pphif(:,:) ) ! f = f0 +beta* y
+      pff_t(:,:) =  REAL( rn_f0, wp ) + REAL( rn_beta, wp ) * ABS( pphit(:,:) ) ! f = f0 +beta* y
+      ! 
+      IF(lwp) WRITE(numout,*) '                           beta-plane used. f0   = ', rn_f0 ,  ' 1/s'
+      IF(lwp) WRITE(numout,*) '                           beta-plane used. beta = ', rn_beta, ' 1/(s.m)'
+      !
+   END SUBROUTINE usr_def_hgr
+
+   !!======================================================================
+END MODULE usrdef_hgr
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_istate.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -0,0 +1,91 @@
+MODULE usrdef_istate
+   !!======================================================================
+   !!                   ***  MODULE  usrdef_istate   ***
+   !!
+   !!                     ===  SWG configuration  ===
+   !!
+   !! User defined : set the initial state of a user configuration
+   !!======================================================================
+   !! History :  4.0  ! 2016-03  (S. Flavoni) Original code
+   !!             -   ! 2020-03  (A. Nasser) Shallow Water Eq. configuration
+   !!                 ! 2020-11  (S. Techene, G. Madec) separate tsuv from ssh
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!  usr_def_istate : initial state in Temperature and salinity
+   !!----------------------------------------------------------------------
+   USE par_oce        ! ocean space and time domain master parameters
+   USE phycst         ! physical constants
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   usr_def_istate       ! called in istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by domqco.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: usrdef_istate.F90 10069 2018-08-28 14:12:24Z nicolasmartin $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+  
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracers
+      !!                Here SWG configuration example : (double gyre with rotated domain)
+      !!
+      !! ** Method  : - set temprature field
+      !!              - set salinity   field
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   pdept   ! depth of t-point               [m]
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask             [m]
+      !
+      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(  out) ::   pts     ! T & S fields      [Celsius ; g/kg]
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
+      !
+      INTEGER :: ji, jj, jk  ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate : analytical definition of initial state '
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~   Ocean at rest, with an horizontally uniform T and S profiles'
+      !
+      pu  (:,:,:)   = 0._wp        ! ocean at rest
+      pv  (:,:,:)   = 0._wp
+      pts (:,:,:,:) = 0._wp            ! not used in SWE
+
+      IF(lwp) WRITE(numout,*) "end istate"
+      CALL FLUSH(numout)
+      !   
+   END SUBROUTINE usr_def_istate
+
+
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of ssh
+      !!                Here SWG configuration 
+      !!
+      !! ** Method  :   set ssh to 0
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask             [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : SWG configuration, analytical definition of initial state'
+      !
+      pssh(:,:)   = 0._wp        ! ocean at rest
+      !
+   END SUBROUTINE usr_def_istate_ssh
+
+   !!======================================================================
+END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_nam.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_nam.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_nam.F90	(revision 14062)
@@ -0,0 +1,139 @@
+MODULE usrdef_nam
+   !!======================================================================
+   !!                     ***  MODULE usrdef_nam   ***
+   !!
+   !!                     ===  SWG configuration  ===
+   !!
+   !! User defined : set the domain characteristics of a user configuration
+   !!======================================================================
+   !! History :  4.0  ! 2016-03  (S. Flavoni, G. Madec)  Original code
+   !!             -   ! 2020-03  (A. Nasser) Shallow Water Eq. configuration
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   usr_def_nam   : read user defined namelist and set global domain size
+   !!   usr_def_hgr   : initialize the horizontal mesh 
+   !!----------------------------------------------------------------------
+   USE dom_oce  , ONLY: nimpp, njmpp       ! ocean space and time domain
+   USE par_oce        ! ocean space and time domain
+   USE phycst         ! physical constants
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! MPP library
+   
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   usr_def_nam   ! called in nemogcm.F90 module
+   !                              !!* namusr_def namelist *!!
+   INTEGER , PUBLIC ::   nn_SWG             ! 1/nn_SWG = the resolution chosen in degrees and thus defining the horizontal domain size
+   REAL(wp), PUBLIC ::   rn_theta           ! rotation angle (in degree) of the grid 
+   INTEGER , PUBLIC ::   nn_gc              ! number of ghostcells
+   REAL(wp), PUBLIC ::   rn_domsiz          ! size of the domain (default 2000km)  [m]
+   REAL(wp), PUBLIC ::   rn_dx              ! gridspacing (default 100km)          [m]
+   REAL(wp), PUBLIC ::   rn_tau             ! wind stress on the surface           [N/m2]
+   REAL(wp), PUBLIC ::   rn_f0              !    f-plan coriolis parameter         [1/s] 
+   REAL(wp), PUBLIC ::   rn_beta            ! beta-plan coriolis parameter         [1/m.s] 
+   REAL(wp), PUBLIC ::   rn_modified_grav   ! modified gravity                     [m/s2] 
+   REAL(wp), PUBLIC ::   rn_rfr             ! layer friction                       [1/s]
+   !                              !!* temporary *!!
+   INTEGER , PUBLIC ::   nn_dynldf_lap_typ            ! choose type of laplacian (ideally from namelist)
+   !                                                  ! = 1   divrot    laplacian
+   !                                                  ! = 2   symmetric laplacian (Griffies&Hallberg 2000)
+   !                                                  ! = 3   symmetric laplacian (cartesian)
+   LOGICAL , PUBLIC ::   ln_dynldf_lap_PM             ! if True - apply the P.Marchand boundary condition on the laplacian
+   !                              !!* penalisation *!!
+   REAL(wp), PUBLIC ::   rn_abp             ! alpha boundary parameter                                       [-]
+   INTEGER , PUBLIC ::   nn_cnp             ! number of cell on which is smoothed the porosity (phi)         [-]
+   REAL(wp), PUBLIC ::   rn_fsp             ! friction parameter 1/epsilon of the permeability               [1/s]
+   !
+   REAL(wp), PUBLIC ::   r1_abp             ! inverse alpha boundary parameter                            [-]
+   !
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: usrdef_nam.F90 11536 2019-09-11 13:54:18Z smasson $ 
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE usr_def_nam( cd_cfg, kk_cfg, kpi, kpj, kpk, kperio )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE dom_nam  ***
+      !!                    
+      !! ** Purpose :   read user defined namelist and define the domain size
+      !!
+      !! ** Method  :   read in namusr_def containing all the user specific namelist parameter
+      !!
+      !!                Here SWG configuration
+      !!
+      !! ** input   : - namusr_def namelist found in namelist_cfg
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(out) ::   cd_cfg          ! configuration name
+      INTEGER         , INTENT(out) ::   kk_cfg          ! configuration resolution
+      INTEGER         , INTENT(out) ::   kpi, kpj, kpk   ! global domain sizes 
+      INTEGER         , INTENT(out) ::   kperio          ! lateral global domain b.c. 
+      !
+      INTEGER  ::   ios             ! Local integer
+      REAL(wp) ::   ze1, zgl, zbl   ! gridspacing, length of the biggest square
+      !!
+      NAMELIST/namusr_def/ nn_SWG, rn_theta, jpkglo,            &   ! 
+         &                 nn_gc ,rn_domsiz, rn_dx,             &   ! domain parameters
+         &                 rn_f0 ,rn_beta,                      &   ! coriolis parameter
+         &                 rn_modified_grav, rn_rfr , rn_tau,   &   ! reduced gravity, friction, wind
+         &                 nn_dynldf_lap_typ, ln_dynldf_lap_PM, &   ! temporary parameter
+         &                 rn_abp, nn_cnp, rn_fsp                   ! penalisation parameters
+      !!----------------------------------------------------------------------
+      !
+      READ  ( numnam_cfg, namusr_def, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namusr_def in configuration namelist' )
+      !
+      IF(lwm)   WRITE( numond, namusr_def )
+      !
+      cd_cfg = 'SWG'               ! name & resolution (not used)
+      
+#if defined key_agrif
+      IF (.NOT.Agrif_root()) nn_SWG = Agrif_parent(nn_SWG) * Agrif_irhox()
+#endif
+
+      kk_cfg = nn_SWG
+       !
+      ze1 =  rn_dx / REAL(nn_SWG, wp)                    ! [m] gridspacing used
+      zgl =  rn_domsiz + 2._wp * REAL(nn_gc, wp) * ze1   ! [m] length of the square with ghostcells
+      ! rotation
+      zbl = zgl * ( COS( rn_theta * rad ) + SIN( rn_theta * rad ) )   ! length side bigger domain [m]  
+      !
+      kpi = ceiling(zbl / ze1 )    ! Global Domain size + ghost cells                
+      kpj = ceiling(zbl / ze1 )    ! Global Domain size + ghost cells              
+      !
+      IF( rn_modified_grav /= 0._wp) grav = rn_modified_grav   ! update the gravity 
+      !
+      kpk = jpkglo
+      !                             ! Set the lateral boundary condition of the global domain
+      kperio = 0                    ! SWG configuration : closed domain
+      !
+# if defined key_bvp
+      r1_abp = 1._wp / rn_abp
+#endif
+      !                             ! control print
+      IF(lwp) THEN
+         WRITE(numout,*) '   '
+         WRITE(numout,*) 'usr_def_nam  : read the user defined namelist (namusr_def) in namelist_cfg'
+         WRITE(numout,*) '~~~~~~~~~~~ '
+         WRITE(numout,*) '   Namelist namusr_def : SWG case'
+         WRITE(numout,*) '                                   domain size       rn_domsiz   = ', rn_domsiz, 'm'
+         WRITE(numout,*) '                                   gridspacing           rn_dx   = ', rn_dx, 'm'
+         WRITE(numout,*) '      inverse resolution & implied domain size          nn_SWG   = ', nn_SWG
+         WRITE(numout,*) '                           implied gridspacing           rn_dx   = ', rn_dx, 'm'
+         WRITE(numout,*) '                          number of ghostcells           nn_gc   = ', nn_gc
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '                    rotation angle chosen             rn_theta   = ', rn_theta, 'deg'
+         WRITE(numout,*) '                    modified gravity          rn_modified_grav   = ', rn_modified_grav, 'm2/s'
+         WRITE(numout,*) '      number of model levels                              jpkglo = ', kpk
+         WRITE(numout,*) '   '
+         WRITE(numout,*) '   Lateral b.c. of the global domain set to closed        jperio = ', kperio
+      ENDIF
+      !
+   END SUBROUTINE usr_def_nam
+
+   !!======================================================================
+END MODULE usrdef_nam
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_sbc.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_sbc.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_sbc.F90	(revision 14062)
@@ -0,0 +1,123 @@
+MODULE usrdef_sbc
+   !!======================================================================
+   !!                     ***  MODULE  usrdef_sbc  ***
+   !!
+   !!                     ===  SWG configuration  ===
+   !!
+   !! User defined :   surface forcing of a user configuration
+   !!======================================================================
+   !! History :  4.0  ! 2016-03  (S. Flavoni, G. Madec)  user defined interface
+   !!             -   ! 2020-03  (A. Nasser) Shallow Water Eq. configuration
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   usrdef_sbc    : user defined surface bounday conditions in GYRE case
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers
+   USE dom_oce        ! ocean space and time domain
+   USE sbc_oce        ! Surface boundary condition: ocean fields
+   USE phycst         ! physical constants
+   USE usrdef_nam
+   !
+   USE in_out_manager ! I/O manager
+   USE lib_mpp        ! distribued memory computing library
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_fortran    ! Fortran library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   usrdef_sbc_oce       ! routine called in sbcmod module
+   PUBLIC   usrdef_sbc_ice_tau   ! routine called by icestp.F90 for ice dynamics
+   PUBLIC   usrdef_sbc_ice_flx   ! routine called by icestp.F90 for ice thermo
+      
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: usrdef_sbc.F90 10425 2018-12-19 21:54:16Z smasson $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE usrdef_sbc_oce( kt, Kbb )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE usrdef_sbc_oce  ***
+      !!              
+      !! ** Purpose :   provide at each time-step the GYRE surface boundary
+      !!              condition, i.e. the momentum, heat and freshwater fluxes.
+      !!
+      !! ** Method  :   analytical seasonal cycle for GYRE configuration.
+      !!                CAUTION : never mask the surface stress field !
+      !!
+      !! ** Action  : - set the ocean surface boundary condition, i.e.   
+      !!                   utau, vtau, taum, wndm, qns, qsr, emp, sfx
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
+      INTEGER, INTENT(in) ::   Kbb  ! ocean time index
+      !!
+      INTEGER  ::   ji, jj                ! dummy loop indices
+      REAL(wp) ::   ztauu, ztauv          ! wind intensity projeted
+      REAL(wp) ::   zrhoa  = 1.22         ! Air density kg/m3
+      REAL(wp) ::   zcdrag = 1.5e-3       ! drag coefficient
+      REAL(wp) ::   ztx, zty, zmod, zcoef ! temporary variables
+      !!---------------------------------------------------------------------
+
+      ! ---------------------------- !
+      !  heat and freshwater fluxes  !   (no fluxes)
+      ! ---------------------------- !
+      
+      emp (:,:) = 0._wp
+      sfx (:,:) = 0._wp
+      qns (:,:) = 0._wp
+
+      ! ---------------------------- !
+      !       momentum fluxes        !
+      ! ---------------------------- !
+      ! rotated case (45deg)
+      ! ztauu = 0.2_wp / SQRT( 2._wp )    ! N.m-2
+      ! ztauv = 0.2_wp / SQRT( 2._wp)     ! N.m-2
+      ! non rotated
+      !ztauu = 0.2_wp                    ! N.m-2
+      !ztauv = 0._wp                     ! N.m-2
+      ! general case
+      ztauu =   REAL( rn_tau, wp ) * COS( rn_theta * rad )   ! N.m-2
+      ztauv = - REAL( rn_tau, wp ) * SIN( rn_theta * rad )   ! N.m-2
+      
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+           ! length of the domain : 2000km x 2000km 
+           utau(ji,jj) = - ztauu * COS( rpi * gphiu(ji,jj) / 2000000._wp)
+           vtau(ji,jj) = - ztauv * COS( rpi * gphiv(ji,jj) / 2000000._wp)
+         END DO
+      END DO
+     
+      ! module of wind stress and wind speed at T-point
+      zcoef = 1. / ( zrhoa * zcdrag ) 
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            ztx = utau(ji-1,jj  ) + utau(ji,jj) 
+            zty = vtau(ji  ,jj-1) + vtau(ji,jj) 
+            zmod = 0.5 * SQRT( ztx * ztx + zty * zty )
+            taum(ji,jj) = zmod
+            wndm(ji,jj) = SQRT( zmod * zcoef )
+         END DO
+      END DO
+      
+      CALL lbc_lnk_multi( 'usrdef_sbc', taum(:,:), 'T', 1. , wndm(:,:), 'T', 1. )
+      !
+   END SUBROUTINE usrdef_sbc_oce
+
+
+   SUBROUTINE usrdef_sbc_ice_tau( kt )
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
+   END SUBROUTINE usrdef_sbc_ice_tau
+
+
+   SUBROUTINE usrdef_sbc_ice_flx( kt, phs, phi )
+      INTEGER, INTENT(in) ::   kt   ! ocean time step
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phs    ! snow thickness
+      REAL(wp), DIMENSION(:,:,:), INTENT(in)  ::   phi    ! ice thickness
+   END SUBROUTINE usrdef_sbc_ice_flx
+
+   !!======================================================================
+END MODULE usrdef_sbc
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_zgr.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_zgr.F90	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/MY_SRC/usrdef_zgr.F90	(revision 14062)
@@ -0,0 +1,267 @@
+MODULE usrdef_zgr
+   !!======================================================================
+   !!                       ***  MODULE  usrdef_zgr  ***
+   !!
+   !!                       ===  SWG configuration  ===
+   !!
+   !! User defined : vertical coordinate system of a user configuration
+   !!======================================================================
+   !! History :  4.0  ! 2016-06  (G. Madec)  Original code
+   !!             -   ! 2020-03  (A. Nasser) Shallow Water Eq. configuration
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   usr_def_zgr   : user defined vertical coordinate system
+   !!      zgr_z      : reference 1D z-coordinate 
+   !!      zgr_top_bot: ocean top and bottom level indices
+   !!      zgr_zco    : 3D verticl coordinate in pure z-coordinate case
+   !!---------------------------------------------------------------------
+   USE oce            ! ocean variables
+   USE dom_oce        ! ocean domain
+   USE depth_e3       ! depth <=> e3
+   USE usrdef_nam
+   !
+   USE in_out_manager ! I/O manager
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp        ! distributed memory computing library
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   usr_def_zgr        ! called by domzgr.F90
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
+   !! $Id: usrdef_zgr.F90 10425 2018-12-19 21:54:16Z smasson $
+   !! Software governed by the CeCILL license (see ./LICENSE)
+   !!----------------------------------------------------------------------
+CONTAINS             
+
+   SUBROUTINE usr_def_zgr( ld_zco  , ld_zps  , ld_sco  , ld_isfcav,    &   ! type of vertical coordinate
+      &                    pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d  ,    &   ! 1D reference vertical coordinate
+      &                    pdept , pdepw ,                             &   ! 3D t & w-points depth
+      &                    pe3t  , pe3u  , pe3v   , pe3f ,             &   ! vertical scale factors
+      &                    pe3w  , pe3uw , pe3vw         ,             &   !     -      -      -
+      &                    k_top , k_bot                 )                 ! top & bottom ocean level
+      !!---------------------------------------------------------------------
+      !!              ***  ROUTINE usr_def_zgr  ***
+      !!
+      !! ** Purpose :   User defined the vertical coordinates
+      !!
+      !!----------------------------------------------------------------------
+      LOGICAL                   , INTENT(out) ::   ld_zco, ld_zps, ld_sco      ! vertical coordinate flags
+      LOGICAL                   , INTENT(out) ::   ld_isfcav                   ! under iceshelf cavity flag
+      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pdept_1d, pdepw_1d          ! 1D grid-point depth     [m]
+      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pe3t_1d , pe3w_1d           ! 1D grid-point depth     [m]
+      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   pdept, pdepw                ! grid-point depth        [m]
+      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   pe3t , pe3u , pe3v , pe3f   ! vertical scale factors  [m]
+      REAL(wp), DIMENSION(:,:,:), INTENT(out) ::   pe3w , pe3uw, pe3vw         ! i-scale factors 
+      INTEGER , DIMENSION(:,:)  , INTENT(out) ::   k_top, k_bot                ! first & last ocean level
+      !
+      INTEGER  ::   inum   ! local logical unit
+      REAL(WP) ::   z_zco, z_zps, z_sco, z_cav
+      REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_zgr : SWG configuration (z-coordinate closed flat box ocean without cavities)'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      !
+      !
+      ! type of vertical coordinate
+      ! ---------------------------
+      ld_zco    = .FALSE.         ! SWG case:  z-coordinate without ocean cavities
+      ld_zps    = .FALSE.
+      ld_sco    = .TRUE.
+      ld_isfcav = .FALSE.
+      !
+      !
+      ! Build the vertical coordinate system
+      ! ------------------------------------
+      CALL zgr_z( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! Reference z-coordinate system
+      !
+      CALL zgr_msk_top_bot( k_top , k_bot)                 ! masked top and bottom ocean t-level indices
+      !
+      !                                                     ! z-coordinate (3D arrays) from the 1D z-coord.
+      CALL zgr_zco( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d,   &   ! in  : 1D reference vertical coordinate
+         &          pdept   , pdepw   ,                     &   ! out : 3D t & w-points depth
+         &          pe3t    , pe3u    , pe3v   , pe3f   ,   &   !       vertical scale factors
+         &          pe3w    , pe3uw   , pe3vw             )     !           -      -      -
+      !
+   END SUBROUTINE usr_def_zgr
+
+
+   SUBROUTINE zgr_z( pdept_1d, pdepw_1d, pe3t_1d , pe3w_1d )   ! 1D reference vertical coordinate
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE zgr_z  ***
+      !!
+      !! ** Purpose :   set the 1D depth of model levels and the resulting 
+      !!              vertical scale factors.
+      !!
+      !! ** Method  :   1D z-coordinate system (use in all type of coordinate)
+      !!       The depth of model levels is set from dep(k), an analytical function:
+      !!                   w-level: depw_1d  = dep(k)
+      !!                   t-level: dept_1d  = dep(k+0.5)
+      !!       The scale factors are the discrete derivative of the depth:
+      !!                   e3w_1d(jk) = dk[ dept_1d ] 
+      !!                   e3t_1d(jk) = dk[ depw_1d ]
+      !!           with at top and bottom :
+      !!                   e3w_1d( 1 ) = 2 * ( dept_1d( 1 ) - depw_1d( 1 ) )
+      !!                   e3t_1d(jpk) = 2 * ( dept_1d(jpk) - depw_1d(jpk) )
+      !!       The depth are then re-computed from the sum of e3. This ensures 
+      !!    that depths are identical when reading domain configuration file. 
+      !!    Indeed, only e3. are saved in this file, depth are compute by a call
+      !!    to the e3_to_depth subroutine.
+      !!
+      !!       Here the Madec & Imbard (1996) function is used.
+      !!
+      !! ** Action  : - pdept_1d, pdepw_1d : depth of T- and W-point (m)
+      !!              - pe3t_1d , pe3w_1d  : scale factors at T- and W-levels (m)
+      !!
+      !! Reference : Marti, Madec & Delecluse, 1992, JGR, 97, No8, 12,763-12,766.
+      !!             Madec and Imbard, 1996, Clim. Dyn.
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pdept_1d, pdepw_1d   ! 1D grid-point depth        [m]
+      REAL(wp), DIMENSION(:)    , INTENT(out) ::   pe3t_1d , pe3w_1d    ! 1D vertical scale factors  [m]
+      !
+      INTEGER  ::   jk       ! dummy loop indices
+        !!----------------------------------------------------------------------
+      !
+        !
+      IF(lwp) THEN            ! Parameter print
+         WRITE(numout,*)
+         WRITE(numout,*) '    zgr_z   : Reference vertical z-coordinates '
+         WRITE(numout,*) '    ~~~~~~~'
+      ENDIF
+
+      !
+      ! 1D Reference z-coordinate    (using Madec & Imbard 1996 function)
+      ! -------------------------
+      !
+      ! depth at T and W-points
+      pdepw_1d(1) =   0._wp
+      pdept_1d(1) = 250._wp
+      !
+      pdepw_1d(2) = 500._wp
+      pdept_1d(2) = 750._wp
+      !
+      !                       ! e3t and e3w from depth
+      CALL depth_to_e3( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d ) 
+      !
+      !                       ! recompute depths from SUM(e3)  <== needed
+      CALL e3_to_depth( pe3t_1d, pe3w_1d, pdept_1d, pdepw_1d ) 
+      !
+      IF(lwp) THEN                        ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) '              Reference 1D z-coordinate depth and scale factors:'
+         WRITE(numout, "(9x,' level  gdept_1d  gdepw_1d  e3t_1d   e3w_1d  ')" )
+         WRITE(numout, "(10x, i4, 4f9.2)" ) ( jk, pdept_1d(jk), pdepw_1d(jk), pe3t_1d(jk), pe3w_1d(jk), jk = 1, jpk )
+      ENDIF
+      !
+   END SUBROUTINE zgr_z
+
+
+   SUBROUTINE zgr_msk_top_bot( k_top , k_bot)
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE zgr_msk_top_bot  ***
+      !!
+      !! ** Purpose :   set the masked top and bottom ocean t-levels
+      !!
+      !! ** Method  :   SWG case = closed flat box ocean without ocean cavities
+      !!                   k_top = 1     except along north, south, east and west boundaries
+      !!                   k_bot = jpk-1 except along north, south, east and west boundaries
+      !!
+      !! ** Action  : - k_top : first wet ocean level index
+      !!              - k_bot : last  wet ocean level index
+      !!----------------------------------------------------------------------
+      INTEGER , DIMENSION(:,:), INTENT(out) ::   k_top , k_bot   ! first & last wet ocean level
+      !
+      REAL(wp), DIMENSION(jpi,jpj) ::   z2d   ! 2D local workspace
+      INTEGER  ::   ji, jj                    ! dummy loop indices
+      REAL(wp) ::   zylim0, zylim1, zxlim0, zxlim1 ! limit of the domain [m]
+      REAL(WP) ::   zcoeff    ! local scalar
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) '    zgr_top_bot : defines the top and bottom wet ocean levels.'
+      IF(lwp) WRITE(numout,*) '    ~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*) '       SWG case : closed flat box ocean without ocean cavities'
+      !
+      z2d(:,:) = REAL( jpkm1 , wp )          ! flat bottom
+      !
+      CALL lbc_lnk( 'usrdef_zgr', z2d, 'T', 1. )           ! set surrounding land to zero (here jperio=0 ==>> closed)
+      !
+      ! 
+      zylim0 =   10000._wp    ! +10km 
+      zylim1 = 2010000._wp    ! 2010km
+      zxlim0 =   10000._wp    ! +10km 
+      zxlim1 = 2010000._wp    ! 2010km
+      !
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+         ! if T point in the 2000 km x 2000 km domain
+         ! IF ( gphit(ji,jj) > zylim0 .AND. gphit(ji,jj) < zylim1 .AND. & 
+         !   & glamt(ji,jj) > zxlim0 .AND. glamt(ji,jj) < zxlim1       )  THEN
+         ! if U,V points are in the 2000 km x 2000 km domain
+         IF ( gphiv(ji,jj) > zylim0 .AND. gphiv(ji,jj) < zylim1 .AND. & 
+            & glamu(ji,jj) > zxlim0 .AND. glamu(ji,jj) < zxlim1       )  THEN
+         k_top(ji,jj) = 1    ! = ocean
+         k_bot(ji,jj) = NINT( z2d(ji,jj) )
+         ELSE
+         k_top(ji,jj) = 0    ! = land
+         k_bot(ji,jj) = 0
+         END IF
+         END DO
+      END DO
+      ! mask the lonely corners
+      DO jj = 2, jpim1
+         DO ji = 2, jpim1
+         zcoeff = k_top(ji+1,jj) + k_top(ji,jj+1)   &
+            +     k_top(ji-1,jj) + k_top(ji,jj-1)
+         IF ( zcoeff <= 1._wp )   THEN
+            k_top(ji,jj) = 0    ! = land
+            k_bot(ji,jj) = 0
+         END IF
+         END DO
+      END DO
+      !
+      !
+   END SUBROUTINE zgr_msk_top_bot
+   
+
+   SUBROUTINE zgr_zco( pdept_1d, pdepw_1d, pe3t_1d, pe3w_1d,   &   ! in : 1D reference vertical coordinate
+      &                pdept   , pdepw   ,                     &   ! out: 3D t & w-points depth
+      &                pe3t    , pe3u    , pe3v   , pe3f   ,   &   !      vertical scale factors
+      &                pe3w    , pe3uw   , pe3vw             )     !          -      -      -
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zgr_zco  ***
+      !!
+      !! ** Purpose :   define the reference z-coordinate system
+      !!
+      !! ** Method  :   set 3D coord. arrays to reference 1D array 
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:)    , INTENT(in   ) ::   pdept_1d, pdepw_1d          ! 1D grid-point depth       [m]
+      REAL(wp), DIMENSION(:)    , INTENT(in   ) ::   pe3t_1d , pe3w_1d           ! 1D vertical scale factors [m]
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pdept, pdepw                ! grid-point depth          [m]
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pe3t , pe3u , pe3v , pe3f   ! vertical scale factors    [m]
+      REAL(wp), DIMENSION(:,:,:), INTENT(  out) ::   pe3w , pe3uw, pe3vw         !    -       -      -
+      !
+      INTEGER  ::   jk
+      !!----------------------------------------------------------------------
+      !
+      DO jk = 1, jpk
+         pdept(:,:,jk) = pdept_1d(jk)
+         pdepw(:,:,jk) = pdepw_1d(jk)
+         pe3t (:,:,jk) = pe3t_1d (jk)
+         pe3u (:,:,jk) = pe3t_1d (jk)
+         pe3v (:,:,jk) = pe3t_1d (jk)
+         pe3f (:,:,jk) = pe3t_1d (jk)
+         pe3w (:,:,jk) = pe3w_1d (jk)
+         pe3uw(:,:,jk) = pe3w_1d (jk)
+         pe3vw(:,:,jk) = pe3w_1d (jk)
+      END DO
+      !
+   END SUBROUTINE zgr_zco
+
+   !!======================================================================
+END MODULE usrdef_zgr
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/cpp_SWG.fcm
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/cpp_SWG.fcm	(revision 14062)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/SWG/cpp_SWG.fcm	(revision 14062)
@@ -0,0 +1,1 @@
+bld::tool::fppkeys  key_mpp_mpi key_iomput key_qco 
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/EXPREF/1_namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/EXPREF/1_namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/EXPREF/1_namelist_cfg	(revision 14062)
@@ -195,5 +195,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/EXPREF/namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/EXPREF/namelist_cfg	(revision 14062)
@@ -188,5 +188,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/MY_SRC/domvvl.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/MY_SRC/domvvl.F90	(revision 14059)
+++ 	(revision )
@@ -1,1025 +1,0 @@
-MODULE domvvl
-   !!======================================================================
-   !!                       ***  MODULE domvvl   ***
-   !! Ocean : 
-   !!======================================================================
-   !! History :  2.0  !  2006-06  (B. Levier, L. Marie)  original code
-   !!            3.1  !  2009-02  (G. Madec, M. Leclair, R. Benshila)  pure z* coordinate
-   !!            3.3  !  2011-10  (M. Leclair) totally rewrote domvvl: vvl option includes z_star and z_tilde coordinates
-   !!            3.6  !  2014-11  (P. Mathiot) add ice shelf capability
-   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rename dom_vvl_sf_swp -> dom_vvl_sf_update for new timestepping
-   !!            4.x  ! 2020-02  (G. Madec, S. Techene) introduce ssh to h0 ratio
-   !!----------------------------------------------------------------------
-
-   USE oce             ! ocean dynamics and tracers
-   USE phycst          ! physical constant
-   USE dom_oce         ! ocean space and time domain
-   USE sbc_oce         ! ocean surface boundary condition
-   USE wet_dry         ! wetting and drying
-   USE usrdef_istate   ! user defined initial state (wad only)
-   USE restart         ! ocean restart
-   !
-   USE in_out_manager  ! I/O manager
-   USE iom             ! I/O manager library
-   USE lib_mpp         ! distributed memory computing library
-   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
-   USE timing          ! Timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   !                                                      !!* Namelist nam_vvl
-   LOGICAL , PUBLIC :: ln_vvl_zstar           = .FALSE.    ! zstar  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde          = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_layer           = .FALSE.    ! level  vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_ztilde_as_zstar = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_zstar_at_eqtor  = .FALSE.    ! ztilde vertical coordinate
-   LOGICAL , PUBLIC :: ln_vvl_kepe            = .FALSE.    ! kinetic/potential energy transfer
-   !                                                       ! conservation: not used yet
-   REAL(wp)         :: rn_ahe3                             ! thickness diffusion coefficient
-   REAL(wp)         :: rn_rst_e3t                          ! ztilde to zstar restoration timescale [days]
-   REAL(wp)         :: rn_lf_cutoff                        ! cutoff frequency for low-pass filter  [days]
-   REAL(wp)         :: rn_zdef_max                         ! maximum fractional e3t deformation
-   LOGICAL , PUBLIC :: ln_vvl_dbg = .FALSE.                ! debug control prints
-
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: un_td, vn_td                ! thickness diffusion transport
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: hdiv_lf                     ! low frequency part of hz divergence
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_b, tilde_e3t_n    ! baroclinic scale factors
-   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: tilde_e3t_a, dtilde_e3t_a   ! baroclinic scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_e3t                 ! retoring period for scale factors
-   REAL(wp)        , ALLOCATABLE, SAVE, DIMENSION(:,:)   :: frq_rst_hdv                 ! retoring period for low freq. divergence
-
-#if defined key_qco
-   !!----------------------------------------------------------------------
-   !!   'key_qco'      EMPTY MODULE      Quasi-Eulerian vertical coordonate
-   !!----------------------------------------------------------------------
-#else
-   !!----------------------------------------------------------------------
-   !!   Default key      Old management of time varying vertical coordinate
-   !!----------------------------------------------------------------------
-   
-   !!----------------------------------------------------------------------
-   !!   dom_vvl_init     : define initial vertical scale factors, depths and column thickness
-   !!   dom_vvl_sf_nxt   : Compute next vertical scale factors
-   !!   dom_vvl_sf_update   : Swap vertical scale factors and update the vertical grid
-   !!   dom_vvl_interpol : Interpolate vertical scale factors from one grid point to another
-   !!   dom_vvl_rst      : read/write restart file
-   !!   dom_vvl_ctl      : Check the vvl options
-   !!----------------------------------------------------------------------
-
-   PUBLIC  dom_vvl_init       ! called by domain.F90
-   PUBLIC  dom_vvl_zgr        ! called by isfcpl.F90
-   PUBLIC  dom_vvl_sf_nxt     ! called by step.F90
-   PUBLIC  dom_vvl_sf_update  ! called by step.F90
-   PUBLIC  dom_vvl_interpol   ! called by dynnxt.F90
-   
-   !! * Substitutions
-#  include "do_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
-   !! $Id$
-   !! Software governed by the CeCILL license (see ./LICENSE)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION dom_vvl_alloc()
-      !!----------------------------------------------------------------------
-      !!                ***  FUNCTION dom_vvl_alloc  ***
-      !!----------------------------------------------------------------------
-      IF( ln_vvl_zstar )   dom_vvl_alloc = 0
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         ALLOCATE( tilde_e3t_b(jpi,jpj,jpk)  , tilde_e3t_n(jpi,jpj,jpk) , tilde_e3t_a(jpi,jpj,jpk) ,   &
-            &      dtilde_e3t_a(jpi,jpj,jpk) , un_td  (jpi,jpj,jpk)     , vn_td  (jpi,jpj,jpk)     ,   &
-            &      STAT = dom_vvl_alloc        )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-         un_td = 0._wp
-         vn_td = 0._wp
-      ENDIF
-      IF( ln_vvl_ztilde ) THEN
-         ALLOCATE( frq_rst_e3t(jpi,jpj) , frq_rst_hdv(jpi,jpj) , hdiv_lf(jpi,jpj,jpk) , STAT= dom_vvl_alloc )
-         CALL mpp_sum ( 'domvvl', dom_vvl_alloc )
-         IF( dom_vvl_alloc /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_alloc: failed to allocate arrays' )
-      ENDIF
-      !
-   END FUNCTION dom_vvl_alloc
-
-
-   SUBROUTINE dom_vvl_init( Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Initialization of all scale factors, depths
-      !!               and water column heights
-      !!
-      !! ** Method  :  - use restart file and/or initialize
-      !!               - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3[u/v](:,:,:,Kmm)
-      !!                        e3[u/v](:,:,:,Kmm)       
-      !!                        e3w(:,:,:,Kmm)           
-      !!                        e3[u/v]w_b
-      !!                        e3[u/v]w_n      
-      !!                        gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm) and gde3w
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) 'dom_vvl_init : Variable volume activated'
-      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
-      !
-      CALL dom_vvl_ctl     ! choose vertical coordinate (z_star, z_tilde or layer)
-      !
-      !                    ! Allocate module arrays
-      IF( dom_vvl_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dom_vvl_init : unable to allocate arrays' )
-      !
-      !                    ! Read or initialize e3t_(b/n), tilde_e3t_(b/n) and hdiv_lf
-      CALL dom_vvl_rst( nit000, Kbb, Kmm, 'READ' )
-      e3t(:,:,jpk,Kaa) = e3t_0(:,:,jpk)  ! last level always inside the sea floor set one for all
-      !
-      CALL dom_vvl_zgr(Kbb, Kmm, Kaa) ! interpolation scale factor, depth and water column
-      !
-   END SUBROUTINE dom_vvl_init
-
-
-   SUBROUTINE dom_vvl_zgr(Kbb, Kmm, Kaa)
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_init  ***
-      !!                   
-      !! ** Purpose :  Interpolation of all scale factors, 
-      !!               depths and water column heights
-      !!
-      !! ** Method  :  - interpolate scale factors
-      !!
-      !! ** Action  : - e3t_(n/b) and tilde_e3t_(n/b)
-      !!              - Regrid: e3(u/v)_n
-      !!                        e3(u/v)_b       
-      !!                        e3w_n           
-      !!                        e3(u/v)w_b      
-      !!                        e3(u/v)w_n      
-      !!                        gdept_n, gdepw_n and gde3w_n
-      !!              - h(t/u/v)_0
-      !!              - frq_rst_e3t and frq_rst_hdv
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa
-      !!----------------------------------------------------------------------
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   ii0, ii1, ij0, ij1
-      REAL(wp)::   zcoef
-      !!----------------------------------------------------------------------
-      !
-      !                    !== Set of all other vertical scale factors  ==!  (now and before)
-      !                                ! Horizontal interpolation of e3t
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3u(:,:,:,Kbb), 'U' )    ! from T to U
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3u(:,:,:,Kmm), 'U' )
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3v(:,:,:,Kbb), 'V' )    ! from T to V 
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3v(:,:,:,Kmm), 'V' )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3f(:,:,:), 'F' )    ! from U to F
-      !                                ! Vertical interpolation of e3t,u,v 
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm), e3w (:,:,:,Kmm), 'W'  )  ! from T to W
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb), e3w (:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )  ! from U to UW
-      CALL dom_vvl_interpol( e3u(:,:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( e3v(:,:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )  ! from V to UW
-      CALL dom_vvl_interpol( e3v(:,:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! We need to define e3[tuv]_a for AGRIF initialisation (should not be a problem for the restartability...)
-      e3t(:,:,:,Kaa) = e3t(:,:,:,Kmm)
-      e3u(:,:,:,Kaa) = e3u(:,:,:,Kmm)
-      e3v(:,:,:,Kaa) = e3v(:,:,:,Kmm)
-      !
-      !                    !==  depth of t and w-point  ==!   (set the isf depth as it is in the initial timestep)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)       ! reference to the ocean surface (used for MLD and light penetration)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)  ! reference to a common level z=0 for hpg
-      gdept(:,:,1,Kbb) = 0.5_wp * e3w(:,:,1,Kbb)
-      gdepw(:,:,1,Kbb) = 0.0_wp
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-         !    zcoef = tmask - wmask    ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-         !                             ! 1 everywhere from mbkt to mikt + 1 or 1 (if no isf)
-         !                             ! 0.5 where jk = mikt     
-!!gm ???????   BUG ?  gdept(:,:,:,Kmm) as well as gde3w  does not include the thickness of ISF ??
-         zcoef = ( tmask(ji,jj,jk) - wmask(ji,jj,jk) )
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm)) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-         gdepw(ji,jj,jk,Kbb) = gdepw(ji,jj,jk-1,Kbb) + e3t(ji,jj,jk-1,Kbb)
-         gdept(ji,jj,jk,Kbb) =      zcoef  * ( gdepw(ji,jj,jk  ,Kbb) + 0.5 * e3w(ji,jj,jk,Kbb))  &
-            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kbb) +       e3w(ji,jj,jk,Kbb)) 
-      END_3D
-      !
-      !                    !==  thickness of the water column  !!   (ocean portion only)
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)   !!gm  BUG  :  this should be 1/2 * e3w(k=1) ....
-      hu(:,:,Kbb) = e3u(:,:,1,Kbb) * umask(:,:,1)
-      hu(:,:,Kmm) = e3u(:,:,1,Kmm) * umask(:,:,1)
-      hv(:,:,Kbb) = e3v(:,:,1,Kbb) * vmask(:,:,1)
-      hv(:,:,Kmm) = e3v(:,:,1,Kmm) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         hu(:,:,Kbb) = hu(:,:,Kbb) + e3u(:,:,jk,Kbb) * umask(:,:,jk)
-         hu(:,:,Kmm) = hu(:,:,Kmm) + e3u(:,:,jk,Kmm) * umask(:,:,jk)
-         hv(:,:,Kbb) = hv(:,:,Kbb) + e3v(:,:,jk,Kbb) * vmask(:,:,jk)
-         hv(:,:,Kmm) = hv(:,:,Kmm) + e3v(:,:,jk,Kmm) * vmask(:,:,jk)
-      END DO
-      !
-      !                    !==  inverse of water column thickness   ==!   (u- and v- points)
-      r1_hu(:,:,Kbb) = ssumask(:,:) / ( hu(:,:,Kbb) + 1._wp - ssumask(:,:) )    ! _i mask due to ISF
-      r1_hu(:,:,Kmm) = ssumask(:,:) / ( hu(:,:,Kmm) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kbb) = ssvmask(:,:) / ( hv(:,:,Kbb) + 1._wp - ssvmask(:,:) )
-      r1_hv(:,:,Kmm) = ssvmask(:,:) / ( hv(:,:,Kmm) + 1._wp - ssvmask(:,:) )
-
-      !                    !==   z_tilde coordinate case  ==!   (Restoring frequencies)
-      IF( ln_vvl_ztilde ) THEN
-!!gm : idea: add here a READ in a file of custumized restoring frequency
-         !                                   ! Values in days provided via the namelist
-         !                                   ! use rsmall to avoid possible division by zero errors with faulty settings
-         frq_rst_e3t(:,:) = 2._wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.0_wp )
-         frq_rst_hdv(:,:) = 2._wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.0_wp )
-         !
-         IF( ln_vvl_ztilde_as_zstar ) THEN   ! z-star emulation using z-tile
-            frq_rst_e3t(:,:) = 0._wp               !Ignore namelist settings
-            frq_rst_hdv(:,:) = 1._wp / rn_Dt
-         ENDIF
-         IF ( ln_vvl_zstar_at_eqtor ) THEN   ! use z-star in vicinity of the Equator
-            DO_2D( 1, 1, 1, 1 )
-!!gm  case |gphi| >= 6 degrees is useless   initialized just above by default
-               IF( ABS(gphit(ji,jj)) >= 6.) THEN
-                  ! values outside the equatorial band and transition zone (ztilde)
-                  frq_rst_e3t(ji,jj) =  2.0_wp * rpi / ( MAX( rn_rst_e3t  , rsmall ) * 86400.e0_wp )
-                  frq_rst_hdv(ji,jj) =  2.0_wp * rpi / ( MAX( rn_lf_cutoff, rsmall ) * 86400.e0_wp )
-               ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN    ! Equator strip ==> z-star
-                  ! values inside the equatorial band (ztilde as zstar)
-                  frq_rst_e3t(ji,jj) =  0.0_wp
-                  frq_rst_hdv(ji,jj) =  1.0_wp / rn_Dt
-               ELSE                                      ! transition band (2.5 to 6 degrees N/S)
-                  !                                      ! (linearly transition from z-tilde to z-star)
-                  frq_rst_e3t(ji,jj) = 0.0_wp + (frq_rst_e3t(ji,jj)-0.0_wp)*0.5_wp   &
-                     &            * (  1.0_wp - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-                  frq_rst_hdv(ji,jj) = (1.0_wp / rn_Dt)                                &
-                     &            + (  frq_rst_hdv(ji,jj)-(1.e0_wp / rn_Dt) )*0.5_wp   &
-                     &            * (  1._wp  - COS( rad*(ABS(gphit(ji,jj))-2.5_wp)  &
-                     &                                          * 180._wp / 3.5_wp ) )
-               ENDIF
-            END_2D
-            IF( cn_cfg == "orca" .OR. cn_cfg == "ORCA" ) THEN
-               IF( nn_cfg == 3 ) THEN   ! ORCA2: Suppress ztilde in the Foxe Basin for ORCA2
-                  ii0 = 103 + nn_hls - 1   ;   ii1 = 111 + nn_hls - 1      
-                  ij0 = 128 + nn_hls       ;   ij1 = 135 + nn_hls
-                  frq_rst_e3t( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  0.0_wp
-                  frq_rst_hdv( mi0(ii0):mi1(ii1) , mj0(ij0):mj1(ij1) ) =  1.e0_wp / rn_Dt
-               ENDIF
-            ENDIF
-         ENDIF
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_zgr
-
-
-   SUBROUTINE dom_vvl_sf_nxt( kt, Kbb, Kmm, Kaa, kcall ) 
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_nxt  ***
-      !!                   
-      !! ** Purpose :  - compute the after scale factors used in tra_zdf, dynnxt,
-      !!                 tranxt and dynspg routines
-      !!
-      !! ** Method  :  - z_star case:  Repartition of ssh INCREMENT proportionnaly to the level thickness.
-      !!               - z_tilde_case: after scale factor increment = 
-      !!                                    high frequency part of horizontal divergence
-      !!                                  + retsoring towards the background grid
-      !!                                  + thickness difusion
-      !!                               Then repartition of ssh INCREMENT proportionnaly
-      !!                               to the "baroclinic" level thickness.
-      !!
-      !! ** Action  :  - hdiv_lf    : restoring towards full baroclinic divergence in z_tilde case
-      !!               - tilde_e3t_a: after increment of vertical scale factor 
-      !!                              in z_tilde case
-      !!               - e3(t/u/v)_a
-      !!
-      !! Reference  : Leclair, M., and Madec, G. 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in )           ::   kt             ! time step
-      INTEGER, INTENT( in )           ::   Kbb, Kmm, Kaa  ! time step
-      INTEGER, INTENT( in ), OPTIONAL ::   kcall          ! optional argument indicating call sequence
-      !
-      INTEGER                ::   ji, jj, jk            ! dummy loop indices
-      INTEGER , DIMENSION(3) ::   ijk_max, ijk_min      ! temporary integers
-      REAL(wp)               ::   z_tmin, z_tmax        ! local scalars
-      LOGICAL                ::   ll_do_bclinic         ! local logical
-      REAL(wp), DIMENSION(jpi,jpj)     ::   zht, z_scale, zwu, zwv, zhdiv
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   ze3t
-      LOGICAL , DIMENSION(:,:,:), ALLOCATABLE ::   llmsk
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_nxt')
-      !
-      IF( kt == nit000 ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_nxt : compute after scale factors'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~'
-      ENDIF
-
-      ll_do_bclinic = .TRUE.
-      IF( PRESENT(kcall) ) THEN
-         IF( kcall == 2 .AND. ln_vvl_ztilde )   ll_do_bclinic = .FALSE.
-      ENDIF
-
-      ! ******************************* !
-      ! After acale factors at t-points !
-      ! ******************************* !
-      !                                                ! --------------------------------------------- !
-      !                                                ! z_star coordinate and barotropic z-tilde part !
-      !                                                ! --------------------------------------------- !
-      !
-      z_scale(:,:) = ( ssh(:,:,Kaa) - ssh(:,:,Kbb) ) * ssmask(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-      DO jk = 1, jpkm1
-         ! formally this is the same as e3t(:,:,:,Kaa) = e3t_0*(1+ssha/ht_0)
-         e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kbb) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-      END DO
-      !
-      IF( (ln_vvl_ztilde .OR. ln_vvl_layer) .AND. ll_do_bclinic ) THEN   ! z_tilde or layer coordinate !
-         !                                                               ! ------baroclinic part------ !
-         ! I - initialization
-         ! ==================
-
-         ! 1 - barotropic divergence
-         ! -------------------------
-         zhdiv(:,:) = 0._wp
-         zht(:,:)   = 0._wp
-         DO jk = 1, jpkm1
-            zhdiv(:,:) = zhdiv(:,:) + e3t(:,:,jk,Kmm) * hdiv(:,:,jk)
-            zht  (:,:) = zht  (:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         zhdiv(:,:) = zhdiv(:,:) / ( zht(:,:) + 1. - tmask_i(:,:) )
-
-         ! 2 - Low frequency baroclinic horizontal divergence  (z-tilde case only)
-         ! --------------------------------------------------
-         IF( ln_vvl_ztilde ) THEN
-            IF( kt > nit000 ) THEN
-               DO jk = 1, jpkm1
-                  hdiv_lf(:,:,jk) = hdiv_lf(:,:,jk) - rn_Dt * frq_rst_hdv(:,:)   &
-                     &          * ( hdiv_lf(:,:,jk) - e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) )
-               END DO
-            ENDIF
-         ENDIF
-
-         ! II - after z_tilde increments of vertical scale factors
-         ! =======================================================
-         tilde_e3t_a(:,:,:) = 0._wp  ! tilde_e3t_a used to store tendency terms
-
-         ! 1 - High frequency divergence term
-         ! ----------------------------------
-         IF( ln_vvl_ztilde ) THEN     ! z_tilde case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - ( e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) - hdiv_lf(:,:,jk) )
-            END DO
-         ELSE                         ! layer case
-            DO jk = 1, jpkm1
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) -   e3t(:,:,jk,Kmm) * ( hdiv(:,:,jk) - zhdiv(:,:) ) * tmask(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 2 - Restoring term (z-tilde case only)
-         ! ------------------
-         IF( ln_vvl_ztilde ) THEN
-            DO jk = 1, jpk
-               tilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - frq_rst_e3t(:,:) * tilde_e3t_b(:,:,jk)
-            END DO
-         ENDIF
-
-         ! 3 - Thickness diffusion term
-         ! ----------------------------
-         zwu(:,:) = 0._wp
-         zwv(:,:) = 0._wp
-         DO_3D( 1, 0, 1, 0, 1, jpkm1 )
-            un_td(ji,jj,jk) = rn_ahe3 * umask(ji,jj,jk) * e2_e1u(ji,jj)           &
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji+1,jj  ,jk) )
-            vn_td(ji,jj,jk) = rn_ahe3 * vmask(ji,jj,jk) * e1_e2v(ji,jj)           & 
-               &            * ( tilde_e3t_b(ji,jj,jk) - tilde_e3t_b(ji  ,jj+1,jk) )
-            zwu(ji,jj) = zwu(ji,jj) + un_td(ji,jj,jk)
-            zwv(ji,jj) = zwv(ji,jj) + vn_td(ji,jj,jk)
-         END_3D
-         DO_2D( 1, 1, 1, 1 )
-            un_td(ji,jj,mbku(ji,jj)) = un_td(ji,jj,mbku(ji,jj)) - zwu(ji,jj)
-            vn_td(ji,jj,mbkv(ji,jj)) = vn_td(ji,jj,mbkv(ji,jj)) - zwv(ji,jj)
-         END_2D
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            tilde_e3t_a(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) + (   un_td(ji-1,jj  ,jk) - un_td(ji,jj,jk)    &
-               &                                          +     vn_td(ji  ,jj-1,jk) - vn_td(ji,jj,jk)    &
-               &                                            ) * r1_e1e2t(ji,jj)
-         END_3D
-         !                       ! d - thickness diffusion transport: boundary conditions
-         !                             (stored for tracer advction and continuity equation)
-         CALL lbc_lnk_multi( 'domvvl', un_td , 'U' , -1._wp, vn_td , 'V' , -1._wp)
-
-         ! 4 - Time stepping of baroclinic scale factors
-         ! ---------------------------------------------
-         CALL lbc_lnk( 'domvvl', tilde_e3t_a(:,:,:), 'T', 1._wp )
-         tilde_e3t_a(:,:,:) = tilde_e3t_b(:,:,:) + rDt * tmask(:,:,:) * tilde_e3t_a(:,:,:)
-
-         ! Maximum deformation control
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         ALLOCATE( ze3t(jpi,jpj,jpk), llmsk(jpi,jpj,jpk) )
-         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            ze3t(ji,jj,jk) = tilde_e3t_a(ji,jj,jk) / e3t_0(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
-         END_3D
-         !
-         llmsk(   1:Nis1,:,:) = .FALSE.   ! exclude halos from the checked region
-         llmsk(Nie1: jpi,:,:) = .FALSE.
-         llmsk(:,   1:Njs1,:) = .FALSE.
-         llmsk(:,Nje1: jpj,:) = .FALSE.
-         !
-         llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp                  ! define only the inner domain
-         z_tmax = MAXVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_max( 'domvvl', z_tmax )   ! max over the global domain
-         z_tmin = MINVAL( ze3t(:,:,:), mask = llmsk )   ;   CALL mpp_min( 'domvvl', z_tmin )   ! min over the global domain
-         ! - ML - test: for the moment, stop simulation for too large e3_t variations
-         IF( ( z_tmax >  rn_zdef_max ) .OR. ( z_tmin < - rn_zdef_max ) ) THEN
-            CALL mpp_maxloc( 'domvvl', ze3t, llmsk, z_tmax, ijk_max )
-            CALL mpp_minloc( 'domvvl', ze3t, llmsk, z_tmin, ijk_min )
-            IF (lwp) THEN
-               WRITE(numout, *) 'MAX( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmax
-               WRITE(numout, *) 'at i, j, k=', ijk_max
-               WRITE(numout, *) 'MIN( tilde_e3t_a(:,:,:) / e3t_0(:,:,:) ) =', z_tmin
-               WRITE(numout, *) 'at i, j, k=', ijk_min            
-               CALL ctl_stop( 'STOP', 'MAX( ABS( tilde_e3t_a(:,:,: ) ) / e3t_0(:,:,:) ) too high')
-            ENDIF
-         ENDIF
-         DEALLOCATE( ze3t, llmsk )
-         ! - ML - end test
-         ! - ML - Imposing these limits will cause a baroclinicity error which is corrected for below
-         tilde_e3t_a(:,:,:) = MIN( tilde_e3t_a(:,:,:),   rn_zdef_max * e3t_0(:,:,:) )
-         tilde_e3t_a(:,:,:) = MAX( tilde_e3t_a(:,:,:), - rn_zdef_max * e3t_0(:,:,:) )
-
-         !
-         ! "tilda" change in the after scale factor
-         ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = tilde_e3t_a(:,:,jk) - tilde_e3t_b(:,:,jk)
-         END DO
-         ! III - Barotropic repartition of the sea surface height over the baroclinic profile
-         ! ==================================================================================
-         ! add ( ssh increment + "baroclinicity error" ) proportionly to e3t(n)
-         ! - ML - baroclinicity error should be better treated in the future
-         !        i.e. locally and not spread over the water column.
-         !        (keep in mind that the idea is to reduce Eulerian velocity as much as possible)
-         zht(:,:) = 0.
-         DO jk = 1, jpkm1
-            zht(:,:)  = zht(:,:) + tilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-         z_scale(:,:) =  - zht(:,:) / ( ht_0(:,:) + ssh(:,:,Kmm) + 1. - ssmask(:,:) )
-         DO jk = 1, jpkm1
-            dtilde_e3t_a(:,:,jk) = dtilde_e3t_a(:,:,jk) + e3t(:,:,jk,Kmm) * z_scale(:,:) * tmask(:,:,jk)
-         END DO
-
-      ENDIF
-
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer )  THEN   ! z_tilde or layer coordinate !
-      !                                           ! ---baroclinic part--------- !
-         DO jk = 1, jpkm1
-            e3t(:,:,jk,Kaa) = e3t(:,:,jk,Kaa) + dtilde_e3t_a(:,:,jk) * tmask(:,:,jk)
-         END DO
-      ENDIF
-
-      IF( ln_vvl_dbg .AND. .NOT. ll_do_bclinic ) THEN   ! - ML - test: control prints for debuging
-         !
-         IF( lwp ) WRITE(numout, *) 'kt =', kt
-         IF ( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-            z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( zht(:,:) ) )
-            CALL mpp_max( 'domvvl', z_tmax )                             ! max over the global domain
-            IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(SUM(tilde_e3t_a))) =', z_tmax
-         END IF
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kmm) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshn-SUM(e3t(:,:,:,Kmm)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kaa) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kaa) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+ssha-SUM(e3t(:,:,:,Kaa)))) =', z_tmax
-         !
-         zht(:,:) = 0.0_wp
-         DO jk = 1, jpkm1
-            zht(:,:) = zht(:,:) + e3t(:,:,jk,Kbb) * tmask(:,:,jk)
-         END DO
-         z_tmax = MAXVAL( tmask(:,:,1) * tmask_i(:,:) * ABS( ht_0(:,:) + ssh(:,:,Kbb) - zht(:,:) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ht_0+sshb-SUM(e3t(:,:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kbb) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kbb)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kmm) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kmm)))) =', z_tmax
-         !
-         z_tmax = MAXVAL( tmask(:,:,1) *  ABS( ssh(:,:,Kaa) ) )
-         CALL mpp_max( 'domvvl', z_tmax )                                ! max over the global domain
-         IF( lwp    ) WRITE(numout, *) kt,' MAXVAL(abs(ssh(:,:,Kaa)))) =', z_tmax
-      END IF
-
-      ! *********************************** !
-      ! After scale factors at u- v- points !
-      ! *********************************** !
-
-      CALL dom_vvl_interpol( e3t(:,:,:,Kaa), e3u(:,:,:,Kaa), 'U' )
-      CALL dom_vvl_interpol( e3t(:,:,:,Kaa), e3v(:,:,:,Kaa), 'V' )
-
-      ! *********************************** !
-      ! After depths at u- v points         !
-      ! *********************************** !
-
-      hu(:,:,Kaa) = e3u(:,:,1,Kaa) * umask(:,:,1)
-      hv(:,:,Kaa) = e3v(:,:,1,Kaa) * vmask(:,:,1)
-      DO jk = 2, jpkm1
-         hu(:,:,Kaa) = hu(:,:,Kaa) + e3u(:,:,jk,Kaa) * umask(:,:,jk)
-         hv(:,:,Kaa) = hv(:,:,Kaa) + e3v(:,:,jk,Kaa) * vmask(:,:,jk)
-      END DO
-      !                                        ! Inverse of the local depth
-!!gm BUG ?  don't understand the use of umask_i here .....
-      r1_hu(:,:,Kaa) = ssumask(:,:) / ( hu(:,:,Kaa) + 1._wp - ssumask(:,:) )
-      r1_hv(:,:,Kaa) = ssvmask(:,:) / ( hv(:,:,Kaa) + 1._wp - ssvmask(:,:) )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_nxt')
-      !
-   END SUBROUTINE dom_vvl_sf_nxt
-
-
-   SUBROUTINE dom_vvl_sf_update( kt, Kbb, Kmm, Kaa )
-      !!----------------------------------------------------------------------
-      !!                ***  ROUTINE dom_vvl_sf_update  ***
-      !!                   
-      !! ** Purpose :  for z tilde case: compute time filter and swap of scale factors 
-      !!               compute all depths and related variables for next time step
-      !!               write outputs and restart file
-      !!
-      !! ** Method  :  - swap of e3t with trick for volume/tracer conservation (ONLY FOR Z TILDE CASE)
-      !!               - reconstruct scale factor at other grid points (interpolate)
-      !!               - recompute depths and water height fields
-      !!
-      !! ** Action  :  - tilde_e3t_(b/n) ready for next time step
-      !!               - Recompute:
-      !!                    e3(u/v)_b       
-      !!                    e3w(:,:,:,Kmm)           
-      !!                    e3(u/v)w_b      
-      !!                    e3(u/v)w_n      
-      !!                    gdept(:,:,:,Kmm), gdepw(:,:,:,Kmm)  and gde3w
-      !!                    h(u/v) and h(u/v)r
-      !!
-      !! Reference  : Leclair, M., and G. Madec, 2009, Ocean Modelling.
-      !!              Leclair, M., and G. Madec, 2011, Ocean Modelling.
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) ::   kt              ! time step
-      INTEGER, INTENT( in ) ::   Kbb, Kmm, Kaa   ! time level indices
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      REAL(wp) ::   zcoef        ! local scalar
-      !!----------------------------------------------------------------------
-      !
-      IF( ln_linssh )   RETURN      ! No calculation in linear free surface
-      !
-      IF( ln_timing )   CALL timing_start('dom_vvl_sf_update')
-      !
-      IF( kt == nit000 )   THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'dom_vvl_sf_update : - interpolate scale factors and compute depths for next time step'
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
-      ENDIF
-      !
-      ! Time filter and swap of scale factors
-      ! =====================================
-      ! - ML - e3(t/u/v)_b are allready computed in dynnxt.
-      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
-         IF( l_1st_euler ) THEN
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:)
-         ELSE
-            tilde_e3t_b(:,:,:) = tilde_e3t_n(:,:,:) & 
-            &         + rn_atfp * ( tilde_e3t_b(:,:,:) - 2.0_wp * tilde_e3t_n(:,:,:) + tilde_e3t_a(:,:,:) )
-         ENDIF
-         tilde_e3t_n(:,:,:) = tilde_e3t_a(:,:,:)
-      ENDIF
-
-      ! Compute all missing vertical scale factor and depths
-      ! ====================================================
-      ! Horizontal scale factor interpolations
-      ! --------------------------------------
-      ! - ML - e3u(:,:,:,Kbb) and e3v(:,:,:,Kbb) are already computed in dynnxt
-      ! - JC - hu(:,:,:,Kbb), hv(:,:,:,:,Kbb), hur_b, hvr_b also
-      
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3f(:,:,:), 'F'  )
-      
-      ! Vertical scale factor interpolations
-      CALL dom_vvl_interpol( e3t(:,:,:,Kmm),  e3w(:,:,:,Kmm), 'W'  )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kmm), e3uw(:,:,:,Kmm), 'UW' )
-      CALL dom_vvl_interpol( e3v(:,:,:,Kmm), e3vw(:,:,:,Kmm), 'VW' )
-      CALL dom_vvl_interpol( e3t(:,:,:,Kbb),  e3w(:,:,:,Kbb), 'W'  )
-      CALL dom_vvl_interpol( e3u(:,:,:,Kbb), e3uw(:,:,:,Kbb), 'UW' )
-      CALL dom_vvl_interpol( e3v(:,:,:,Kbb), e3vw(:,:,:,Kbb), 'VW' )
-
-      ! t- and w- points depth (set the isf depth as it is in the initial step)
-      gdept(:,:,1,Kmm) = 0.5_wp * e3w(:,:,1,Kmm)
-      gdepw(:,:,1,Kmm) = 0.0_wp
-      gde3w(:,:,1) = gdept(:,:,1,Kmm) - ssh(:,:,Kmm)
-      DO_3D( 1, 1, 1, 1, 2, jpk )
-        !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere tmask = wmask, ie everywhere expect at jk = mikt
-                                                           ! 1 for jk = mikt
-         zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))
-         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm)
-         gdept(ji,jj,jk,Kmm) =    zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm) )  &
-             &             + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) +       e3w(ji,jj,jk,Kmm) ) 
-         gde3w(ji,jj,jk) = gdept(ji,jj,jk,Kmm) - ssh(ji,jj,Kmm)
-      END_3D
-
-      ! Local depth and Inverse of the local depth of the water
-      ! -------------------------------------------------------
-      !
-      ht(:,:) = e3t(:,:,1,Kmm) * tmask(:,:,1)
-      DO jk = 2, jpkm1
-         ht(:,:) = ht(:,:) + e3t(:,:,jk,Kmm) * tmask(:,:,jk)
-      END DO
-
-      ! write restart file
-      ! ==================
-      IF( lrst_oce  )   CALL dom_vvl_rst( kt, Kbb, Kmm, 'WRITE' )
-      !
-      IF( ln_timing )   CALL timing_stop('dom_vvl_sf_update')
-      !
-   END SUBROUTINE dom_vvl_sf_update
-
-
-   SUBROUTINE dom_vvl_interpol( pe3_in, pe3_out, pout )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl__interpol  ***
-      !!
-      !! ** Purpose :   interpolate scale factors from one grid point to another
-      !!
-      !! ** Method  :   e3_out = e3_0 + interpolation(e3_in - e3_0)
-      !!                - horizontal interpolation: grid cell surface averaging
-      !!                - vertical interpolation: simple averaging
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::  pe3_in    ! input e3 to be interpolated
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::  pe3_out   ! output interpolated e3
-      CHARACTER(LEN=*)                , INTENT(in   ) ::  pout      ! grid point of out scale factors
-      !                                                             !   =  'U', 'V', 'W, 'F', 'UW' or 'VW'
-      !
-      INTEGER ::   ji, jj, jk                                       ! dummy loop indices
-      REAL(wp) ::  zlnwd                                            ! =1./0. when ln_wd_il = T/F
-      !!----------------------------------------------------------------------
-      !
-      IF(ln_wd_il) THEN
-        zlnwd = 1.0_wp
-      ELSE
-        zlnwd = 0.0_wp
-      END IF
-      !
-      SELECT CASE ( pout )    !==  type of interpolation  ==!
-         !
-      CASE( 'U' )                   !* from T- to U-point : hor. surface weighted mean
-         DO_3D( 1, 0, 1, 0, 1, jpk )
-            pe3_out(ji,jj,jk) = 0.5_wp * (  umask(ji,jj,jk) * (1.0_wp - zlnwd) + zlnwd ) * r1_e1e2u(ji,jj)   &
-               &                       * (   e1e2t(ji  ,jj) * ( pe3_in(ji  ,jj,jk) - e3t_0(ji  ,jj,jk) )     &
-               &                           + e1e2t(ji+1,jj) * ( pe3_in(ji+1,jj,jk) - e3t_0(ji+1,jj,jk) ) )
-         END_3D
-         CALL lbc_lnk( 'domvvl', pe3_out(:,:,:), 'U', 1._wp )
-         pe3_out(:,:,:) = pe3_out(:,:,:) + e3u_0(:,:,:)
-         !
-      CASE( 'V' )                   !* from T- to V-point : hor. surface weighted mean
-         DO_3D( 1, 0, 1, 0, 1, jpk )
-            pe3_out(ji,jj,jk) = 0.5_wp * ( vmask(ji,jj,jk)  * (1.0_wp - zlnwd) + zlnwd ) * r1_e1e2v(ji,jj)   &
-               &                       * (   e1e2t(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3t_0(ji,jj  ,jk) )     &
-               &                           + e1e2t(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3t_0(ji,jj+1,jk) ) )
-         END_3D
-         CALL lbc_lnk( 'domvvl', pe3_out(:,:,:), 'V', 1._wp )
-         pe3_out(:,:,:) = pe3_out(:,:,:) + e3v_0(:,:,:)
-         !
-      CASE( 'F' )                   !* from U-point to F-point : hor. surface weighted mean
-         DO_3D( 1, 0, 1, 0, 1, jpk )
-            pe3_out(ji,jj,jk) = 0.5_wp * (  umask(ji,jj,jk) * umask(ji,jj+1,jk) * (1.0_wp - zlnwd) + zlnwd ) &
-               &                       *    r1_e1e2f(ji,jj)                                                  &
-               &                       * (   e1e2u(ji,jj  ) * ( pe3_in(ji,jj  ,jk) - e3u_0(ji,jj  ,jk) )     &
-               &                           + e1e2u(ji,jj+1) * ( pe3_in(ji,jj+1,jk) - e3u_0(ji,jj+1,jk) ) )
-         END_3D
-         CALL lbc_lnk( 'domvvl', pe3_out(:,:,:), 'F', 1._wp )
-         pe3_out(:,:,:) = pe3_out(:,:,:) + e3f_0(:,:,:)
-         !
-      CASE( 'W' )                   !* from T- to W-point : vertical simple mean
-         !
-         pe3_out(:,:,1) = e3w_0(:,:,1) + pe3_in(:,:,1) - e3t_0(:,:,1)
-         ! - ML - The use of mask in this formulea enables the special treatment of the last w-point without indirect adressing
-!!gm BUG? use here wmask in case of ISF ?  to be checked
-         DO jk = 2, jpk
-            pe3_out(:,:,jk) = e3w_0(:,:,jk) + ( 1.0_wp - 0.5_wp * ( tmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd ) )   &
-               &                            * ( pe3_in(:,:,jk-1) - e3t_0(:,:,jk-1) )                               &
-               &                            +            0.5_wp * ( tmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd )     &
-               &                            * ( pe3_in(:,:,jk  ) - e3t_0(:,:,jk  ) )
-         END DO
-         !
-      CASE( 'UW' )                  !* from U- to UW-point : vertical simple mean
-         !
-         pe3_out(:,:,1) = e3uw_0(:,:,1) + pe3_in(:,:,1) - e3u_0(:,:,1)
-         ! - ML - The use of mask in this formaula enables the special treatment of the last w- point without indirect adressing
-!!gm BUG? use here wumask in case of ISF ?  to be checked
-         DO jk = 2, jpk
-            pe3_out(:,:,jk) = e3uw_0(:,:,jk) + ( 1.0_wp - 0.5_wp * ( umask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd ) )  &
-               &                             * ( pe3_in(:,:,jk-1) - e3u_0(:,:,jk-1) )                              &
-               &                             +            0.5_wp * ( umask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd )    &
-               &                             * ( pe3_in(:,:,jk  ) - e3u_0(:,:,jk  ) )
-         END DO
-         !
-      CASE( 'VW' )                  !* from V- to VW-point : vertical simple mean
-         !
-         pe3_out(:,:,1) = e3vw_0(:,:,1) + pe3_in(:,:,1) - e3v_0(:,:,1)
-         ! - ML - The use of mask in this formaula enables the special treatment of the last w- point without indirect adressing
-!!gm BUG? use here wvmask in case of ISF ?  to be checked
-         DO jk = 2, jpk
-            pe3_out(:,:,jk) = e3vw_0(:,:,jk) + ( 1.0_wp - 0.5_wp * ( vmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd ) )  &
-               &                             * ( pe3_in(:,:,jk-1) - e3v_0(:,:,jk-1) )                              &
-               &                             +            0.5_wp * ( vmask(:,:,jk) * (1.0_wp - zlnwd) + zlnwd )    &
-               &                             * ( pe3_in(:,:,jk  ) - e3v_0(:,:,jk  ) )
-         END DO
-      END SELECT
-      !
-   END SUBROUTINE dom_vvl_interpol
-
-
-   SUBROUTINE dom_vvl_rst( kt, Kbb, Kmm, cdrw )
-      !!---------------------------------------------------------------------
-      !!                   ***  ROUTINE dom_vvl_rst  ***
-      !!                     
-      !! ** Purpose :   Read or write VVL file in restart file
-      !!
-      !! ** Method  :   use of IOM library
-      !!                if the restart does not contain vertical scale factors,
-      !!                they are set to the _0 values
-      !!                if the restart does not contain vertical scale factors increments (z_tilde),
-      !!                they are set to 0.
-      !!----------------------------------------------------------------------
-      INTEGER         , INTENT(in) ::   kt        ! ocean time-step
-      INTEGER         , INTENT(in) ::   Kbb, Kmm  ! ocean time level indices
-      CHARACTER(len=*), INTENT(in) ::   cdrw      ! "READ"/"WRITE" flag
-      !
-      INTEGER ::   ji, jj, jk
-      INTEGER ::   id1, id2, id3, id4, id5     ! local integers
-      !!----------------------------------------------------------------------
-      !
-      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise 
-         !                                   ! ===============
-         IF( ln_rstart ) THEN                   !* Read the restart file
-            CALL rst_read_open                  !  open the restart file if necessary
-            CALL iom_get( numror, jpdom_auto, 'sshn'   , ssh(:,:,Kmm)    )
-            !
-            id1 = iom_varid( numror, 'e3t_b', ldstop = .FALSE. )
-            id2 = iom_varid( numror, 'e3t_n', ldstop = .FALSE. )
-            id3 = iom_varid( numror, 'tilde_e3t_b', ldstop = .FALSE. )
-            id4 = iom_varid( numror, 'tilde_e3t_n', ldstop = .FALSE. )
-            id5 = iom_varid( numror, 'hdiv_lf', ldstop = .FALSE. )
-            !
-            !                             ! --------- !
-            !                             ! all cases !
-            !                             ! --------- !
-            !
-            IF( MIN( id1, id2 ) > 0 ) THEN       ! all required arrays exist
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               ! needed to restart if land processor not computed 
-               IF(lwp) write(numout,*) 'dom_vvl_rst : e3t(:,:,:,Kbb) and e3t(:,:,:,Kmm) found in restart files'
-               WHERE ( tmask(:,:,:) == 0.0_wp ) 
-                  e3t(:,:,:,Kmm) = e3t_0(:,:,:)
-                  e3t(:,:,:,Kbb) = e3t_0(:,:,:)
-               END WHERE
-               IF( l_1st_euler ) THEN
-                  e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               ENDIF
-            ELSE IF( id1 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_n set equal to e3t_b.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_b', e3t(:,:,:,Kbb) )
-               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               l_1st_euler = .true.
-            ELSE IF( id2 > 0 ) THEN
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kbb) not found in restart files'
-               IF(lwp) write(numout,*) 'e3t_b set equal to e3t_n.'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               CALL iom_get( numror, jpdom_auto, 'e3t_n', e3t(:,:,:,Kmm) )
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ELSE
-               IF(lwp) write(numout,*) 'dom_vvl_rst WARNING : e3t(:,:,:,Kmm) not found in restart file'
-               IF(lwp) write(numout,*) 'Compute scale factor from sshn'
-               IF(lwp) write(numout,*) 'l_1st_euler is forced to true'
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm) ) &
-                      &                          / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                      &          + e3t_0(:,:,jk)                               * (1._wp -tmask(:,:,jk))
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-               l_1st_euler = .true.
-            ENDIF
-            !                             ! ----------- !
-            IF( ln_vvl_zstar ) THEN       ! z_star case !
-               !                          ! ----------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN
-                  CALL ctl_stop( 'dom_vvl_rst: z_star cannot restart from a z_tilde or layer run' )
-               ENDIF
-               !                          ! ----------------------- !
-            ELSE                          ! z_tilde and layer cases !
-               !                          ! ----------------------- !
-               IF( MIN( id3, id4 ) > 0 ) THEN  ! all required arrays exist
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_b', tilde_e3t_b(:,:,:) )
-                  CALL iom_get( numror, jpdom_auto, 'tilde_e3t_n', tilde_e3t_n(:,:,:) )
-               ELSE                            ! one at least array is missing
-                  tilde_e3t_b(:,:,:) = 0.0_wp
-                  tilde_e3t_n(:,:,:) = 0.0_wp
-               ENDIF
-               !                          ! ------------ !
-               IF( ln_vvl_ztilde ) THEN   ! z_tilde case !
-                  !                       ! ------------ !
-                  IF( id5 > 0 ) THEN  ! required array exists
-                     CALL iom_get( numror, jpdom_auto, 'hdiv_lf', hdiv_lf(:,:,:) )
-                  ELSE                ! array is missing
-                     hdiv_lf(:,:,:) = 0.0_wp
-                  ENDIF
-               ENDIF
-            ENDIF
-            !
-         ELSE                                   !* Initialize at "rest"
-            !
-
-            IF( ll_wd ) THEN   ! MJB ll_wd edits start here - these are essential 
-               !
-               IF( cn_cfg == 'wad' ) THEN
-                  ! Wetting and drying test case
-                  CALL usr_def_istate( gdept(:,:,:,Kbb), tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )
-                  ts  (:,:,:,:,Kmm) = ts (:,:,:,:,Kbb)       ! set now values from to before ones
-                  ssh (:,:,Kmm)     = ssh(:,:,Kbb)
-                  uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
-                  vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
-               ELSE
-                  ! if not test case
-                  ssh(:,:,Kmm) = -ssh_ref
-                  ssh(:,:,Kbb) = -ssh_ref
-
-                  DO_2D( 1, 1, 1, 1 )
-                     IF( ht_0(ji,jj)-ssh_ref <  rn_wdmin1 ) THEN ! if total depth is less than min depth
-                        ssh(ji,jj,Kbb) = rn_wdmin1 - (ht_0(ji,jj) )
-                        ssh(ji,jj,Kmm) = rn_wdmin1 - (ht_0(ji,jj) )
-                     ENDIF
-                  END_2D
-               ENDIF !If test case else
-
-               ! Adjust vertical metrics for all wad
-               DO jk = 1, jpk
-                  e3t(:,:,jk,Kmm) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kmm)  ) &
-                    &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )
-               END DO
-               e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
-
-               DO_2D( 1, 1, 1, 1 )
-                  IF ( ht_0(ji,jj) .LE. 0.0 .AND. NINT( ssmask(ji,jj) ) .EQ. 1) THEN
-                     CALL ctl_stop( 'dom_vvl_rst: ht_0 must be positive at potentially wet points' )
-                  ENDIF
-               END_2D
-               !
-            ELSE
-               !
-               ! usr_def_istate called here only to get ssh(Kbb) needed to initialize e3t(Kbb) and e3t(Kmm)
-               !
-               CALL usr_def_istate( gdept_0, tmask, ts(:,:,:,:,Kbb), uu(:,:,:,Kbb), vv(:,:,:,Kbb), ssh(:,:,Kbb)  )  
-               !
-               ! usr_def_istate will be called again in istate_init to initialize ts, ssh, u and v
-               !
-               DO jk=1,jpk
-                  e3t(:,:,jk,Kbb) =  e3t_0(:,:,jk) * ( ht_0(:,:) + ssh(:,:,Kbb) ) &
-                    &                            / ( ht_0(:,:) + 1._wp - ssmask(:,:) ) * tmask(:,:,jk)   &
-                    &            + e3t_0(:,:,jk) * ( 1._wp - tmask(:,:,jk) )   ! make sure e3t(:,:,:,Kbb) != 0 on land points
-               END DO
-               e3t(:,:,:,Kmm) = e3t(:,:,:,Kbb)
-               ssh(:,:,Kmm) = ssh(:,:,Kbb)                                     ! needed later for gde3w
-               !
-            END IF           ! end of ll_wd edits
-
-            IF( ln_vvl_ztilde .OR. ln_vvl_layer) THEN
-               tilde_e3t_b(:,:,:) = 0._wp
-               tilde_e3t_n(:,:,:) = 0._wp
-               IF( ln_vvl_ztilde ) hdiv_lf(:,:,:) = 0._wp
-            END IF
-         ENDIF
-         !
-      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
-         !                                   ! ===================
-         IF(lwp) WRITE(numout,*) '---- dom_vvl_rst ----'
-         !                                           ! --------- !
-         !                                           ! all cases !
-         !                                           ! --------- !
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_b', e3t(:,:,:,Kbb) )
-         CALL iom_rstput( kt, nitrst, numrow, 'e3t_n', e3t(:,:,:,Kmm) )
-         !                                           ! ----------------------- !
-         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN  ! z_tilde and layer cases !
-            !                                        ! ----------------------- !
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_b', tilde_e3t_b(:,:,:))
-            CALL iom_rstput( kt, nitrst, numrow, 'tilde_e3t_n', tilde_e3t_n(:,:,:))
-         END IF
-         !                                           ! -------------!    
-         IF( ln_vvl_ztilde ) THEN                    ! z_tilde case !
-            !                                        ! ------------ !
-            CALL iom_rstput( kt, nitrst, numrow, 'hdiv_lf', hdiv_lf(:,:,:))
-         ENDIF
-         !
-      ENDIF
-      !
-   END SUBROUTINE dom_vvl_rst
-
-
-   SUBROUTINE dom_vvl_ctl
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_vvl_ctl  ***
-      !!                
-      !! ** Purpose :   Control the consistency between namelist options
-      !!                for vertical coordinate
-      !!----------------------------------------------------------------------
-      INTEGER ::   ioptio, ios
-      !!
-      NAMELIST/nam_vvl/ ln_vvl_zstar, ln_vvl_ztilde, ln_vvl_layer, ln_vvl_ztilde_as_zstar, &
-         &              ln_vvl_zstar_at_eqtor      , rn_ahe3     , rn_rst_e3t            , &
-         &              rn_lf_cutoff               , rn_zdef_max , ln_vvl_dbg                ! not yet implemented: ln_vvl_kepe
-      !!---------------------------------------------------------------------- 
-      !
-      READ  ( numnam_ref, nam_vvl, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_vvl in reference namelist' )
-      READ  ( numnam_cfg, nam_vvl, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 ) CALL ctl_nam ( ios , 'nam_vvl in configuration namelist' )
-      IF(lwm) WRITE ( numond, nam_vvl )
-      !
-      IF(lwp) THEN                    ! Namelist print
-         WRITE(numout,*)
-         WRITE(numout,*) 'dom_vvl_ctl : choice/control of the variable vertical coordinate'
-         WRITE(numout,*) '~~~~~~~~~~~'
-         WRITE(numout,*) '   Namelist nam_vvl : chose a vertical coordinate'
-         WRITE(numout,*) '      zstar                      ln_vvl_zstar   = ', ln_vvl_zstar
-         WRITE(numout,*) '      ztilde                     ln_vvl_ztilde  = ', ln_vvl_ztilde
-         WRITE(numout,*) '      layer                      ln_vvl_layer   = ', ln_vvl_layer
-         WRITE(numout,*) '      ztilde as zstar   ln_vvl_ztilde_as_zstar  = ', ln_vvl_ztilde_as_zstar
-         WRITE(numout,*) '      ztilde near the equator    ln_vvl_zstar_at_eqtor  = ', ln_vvl_zstar_at_eqtor
-         WRITE(numout,*) '      !'
-         WRITE(numout,*) '      thickness diffusion coefficient                      rn_ahe3      = ', rn_ahe3
-         WRITE(numout,*) '      maximum e3t deformation fractional change            rn_zdef_max  = ', rn_zdef_max
-         IF( ln_vvl_ztilde_as_zstar ) THEN
-            WRITE(numout,*) '      ztilde running in zstar emulation mode (ln_vvl_ztilde_as_zstar=T) '
-            WRITE(numout,*) '         ignoring namelist timescale parameters and using:'
-            WRITE(numout,*) '            hard-wired : z-tilde to zstar restoration timescale (days)'
-            WRITE(numout,*) '                         rn_rst_e3t     = 0.e0'
-            WRITE(numout,*) '            hard-wired : z-tilde cutoff frequency of low-pass filter (days)'
-            WRITE(numout,*) '                         rn_lf_cutoff   = 1.0/rn_Dt'
-         ELSE
-            WRITE(numout,*) '      z-tilde to zstar restoration timescale (days)        rn_rst_e3t   = ', rn_rst_e3t
-            WRITE(numout,*) '      z-tilde cutoff frequency of low-pass filter (days)   rn_lf_cutoff = ', rn_lf_cutoff
-         ENDIF
-         WRITE(numout,*) '         debug prints flag                                 ln_vvl_dbg   = ', ln_vvl_dbg
-      ENDIF
-      !
-      ioptio = 0                      ! Parameter control
-      IF( ln_vvl_ztilde_as_zstar )   ln_vvl_ztilde = .true.
-      IF( ln_vvl_zstar           )   ioptio = ioptio + 1
-      IF( ln_vvl_ztilde          )   ioptio = ioptio + 1
-      IF( ln_vvl_layer           )   ioptio = ioptio + 1
-      !
-      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE vertical coordinate in namelist nam_vvl' )
-      !
-      IF(lwp) THEN                   ! Print the choice
-         WRITE(numout,*)
-         IF( ln_vvl_zstar           ) WRITE(numout,*) '      ==>>>   zstar vertical coordinate is used'
-         IF( ln_vvl_ztilde          ) WRITE(numout,*) '      ==>>>   ztilde vertical coordinate is used'
-         IF( ln_vvl_layer           ) WRITE(numout,*) '      ==>>>   layer vertical coordinate is used'
-         IF( ln_vvl_ztilde_as_zstar ) WRITE(numout,*) '      ==>>>   to emulate a zstar coordinate'
-      ENDIF
-      !
-#if defined key_agrif
-      IF( (.NOT.Agrif_Root()).AND.(.NOT.ln_vvl_zstar) )   CALL ctl_stop( 'AGRIF is implemented with zstar coordinate only' )
-#endif
-      !
-   END SUBROUTINE dom_vvl_ctl
-
-#endif
-
-   !!======================================================================
-END MODULE domvvl
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/MY_SRC/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -8,4 +8,5 @@
    !!======================================================================
    !! History :  NEMO ! 2017-11  (J. Chanut) Original code
+   !!                 ! 2020-11  (S. Techene, G. Madec) separate tsuv from ssh
    !!----------------------------------------------------------------------
 
@@ -26,5 +27,6 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called by istate.F90
+   PUBLIC   usr_def_istate       ! called by istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called by domqco.F90
 
    !! * Substitutions
@@ -37,5 +39,5 @@
 CONTAINS
   
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -52,5 +54,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
       !
       INTEGER  :: ji, jj, jk  ! dummy loop indices
@@ -67,18 +68,9 @@
       zf0   = 2._wp * omega * SIN( rad * rn_ppgphi0 )
       zumax = 1._wp * SIGN(1._wp, zf0) ! Here Anticyclonic: set zumax=-1 for cyclonic
-      zlambda = SQRT(2._wp)*60.e3      ! Horizontal scale in meters 
+      zlambda = SQRT(2._wp)*60.e3      ! Horizontal scale in meters
       zn2 = 3.e-3**2
       zH = 0.5_wp * 5000._wp
       !
       zP0 = rho0 * zf0 * zumax * zlambda * SQRT(EXP(1._wp)/2._wp)
-      !
-      ! Sea level:
-      za = -zP0 * (1._wp-EXP(-zH)) / (grav*(zH-1._wp + EXP(-zH)))
-      DO_2D( 1, 1, 1, 1 )
-         zx = glamt(ji,jj) * 1.e3
-         zy = gphit(ji,jj) * 1.e3
-         zrho1 = rho0 + za * EXP(-(zx**2+zy**2)/zlambda**2)
-         pssh(ji,jj) = zP0 * EXP(-(zx**2+zy**2)/zlambda**2)/(zrho1*grav) * ptmask(ji,jj,1)
-      END_2D
       !
       ! temperature:         
@@ -134,4 +126,46 @@
    END SUBROUTINE usr_def_istate
 
+
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate  ***
+      !! 
+      !! ** Purpose :   Initialization of ssh
+      !!                Here VORTEX configuration 
+      !!
+      !! ** Method  :   Set ssh according to a gaussian anomaly of pressure and associated
+      !!                geostrophic velocities
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask   [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height   [m]
+      !
+      INTEGER  :: ji, jj ! dummy loop indices
+      REAL(wp) :: zx, zy, zP0, zumax, zlambda, zf0, zH, zrho1, za
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'usr_def_istate_ssh : VORTEX configuration, analytical definition of initial state'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~   '
+      !
+      !
+      !
+      zf0   = 2._wp * omega * SIN( rad * rn_ppgphi0 )
+      zumax = 1._wp * SIGN(1._wp, zf0) ! Here Anticyclonic: set zumax=-1 for cyclonic
+      zlambda = SQRT(2._wp)*60.e3      ! Horizontal scale in meters 
+      zH = 0.5_wp * 5000._wp
+      !
+      zP0 = rho0 * zf0 * zumax * zlambda * SQRT(EXP(1._wp)/2._wp)
+      !
+      ! Sea level:
+      za = -zP0 * (1._wp-EXP(-zH)) / (grav*(zH-1._wp + EXP(-zH)))
+      DO_2D( 1, 1, 1, 1 )
+         zx = glamt(ji,jj) * 1.e3
+         zy = gphit(ji,jj) * 1.e3
+         zrho1 = rho0 + za * EXP(-(zx**2+zy**2)/zlambda**2)
+         pssh(ji,jj) = zP0 * EXP(-(zx**2+zy**2)/zlambda**2)/(zrho1*grav) * ptmask(ji,jj,1)
+      END_2D
+      
+   END SUBROUTINE usr_def_istate_ssh
+
    !!======================================================================
 END MODULE usrdef_istate
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/cpp_VORTEX.fcm
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/cpp_VORTEX.fcm	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/VORTEX/cpp_VORTEX.fcm	(revision 14062)
@@ -1,1 +1,1 @@
- bld::tool::fppkeys key_iomput key_mpp_mpi key_agrif
+ bld::tool::fppkeys key_iomput key_mpp_mpi key_agrif 
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/WAD/EXPREF/namelist_cfg
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/WAD/EXPREF/namelist_cfg	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/WAD/EXPREF/namelist_cfg	(revision 14062)
@@ -330,5 +330,4 @@
    ln_dynvor_mix = .false. !  mixed scheme
    ln_dynvor_een = .true.  !  energy & enstrophy scheme
-      nn_een_e3f = 0             !  e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/WAD/MY_SRC/usrdef_istate.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/WAD/MY_SRC/usrdef_istate.F90	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/WAD/MY_SRC/usrdef_istate.F90	(revision 14062)
@@ -7,5 +7,6 @@
    !! User defined : set the initial state of a user configuration
    !!======================================================================
-   !! History :  4.0 ! 2016-03  (S. Flavoni) Original code
+   !! History :  4.0  ! 2016-03  (S. Flavoni) Original code
+   !!                 ! 2020-11  (S. Techene, G. Madec) separate tsuv from ssh
    !!----------------------------------------------------------------------
 
@@ -24,5 +25,6 @@
    PRIVATE
 
-   PUBLIC   usr_def_istate   ! called in istate.F90
+   PUBLIC   usr_def_istate       ! called in istate.F90
+   PUBLIC   usr_def_istate_ssh   ! called in sshwzv.F90
 
    !! * Substitutions
@@ -34,6 +36,7 @@
    !!----------------------------------------------------------------------
 CONTAINS
-  
-   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv, pssh )
+
+
+   SUBROUTINE usr_def_istate( pdept, ptmask, pts, pu, pv )
       !!----------------------------------------------------------------------
       !!                   ***  ROUTINE usr_def_istate  ***
@@ -42,5 +45,5 @@
       !!                Here WAD_TEST_CASES configuration 
       !!
-      !! ** Method  : - set temprature field
+q      !! ** Method  : - set temprature field
       !!              - set salinity   field
       !!----------------------------------------------------------------------
@@ -50,5 +53,4 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pu      ! i-component of the velocity  [m/s] 
       REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(  out) ::   pv      ! j-component of the velocity  [m/s] 
-      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
       INTEGER  ::   ji, jj            ! dummy loop indices
       REAL(wp) ::   zi, zj
@@ -66,6 +68,4 @@
       pu  (:,:,:) = 0._wp        ! ocean at rest
       pv  (:,:,:) = 0._wp
-      pssh(:,:)   = 0._wp
-      !
       !                          ! T & S profiles
       pts(:,:,:,jp_tem) = 10._wp * ptmask(:,:,:)
@@ -83,34 +83,108 @@
          CASE ( 1 )                               ! WAD 1 configuration
             !                                     ! ====================
-            !
             IF(lwp) WRITE(numout,*)
             IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Closed box with EW linear bottom slope'
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            do ji = 1,jpi
-             pssh(ji,:) = ( -5.5_wp + 7.4_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
-            end do
             !                                     ! ====================
          CASE ( 2, 8 )                            ! WAD 2 configuration
             !                                     ! ====================
-            !
             IF(lwp) WRITE(numout,*)
             IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel, mid-range initial ssh slope'
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            do ji = 1,jpi
-             pssh(ji,:) = ( -1.5_wp + 5.0_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
-            end do
             !                                     ! ====================
          CASE ( 3 )                               ! WAD 3 configuration
             !                                     ! ====================
-            !
             IF(lwp) WRITE(numout,*)
             IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel, extreme initial ssh slope' 
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            do ji = 1,jpi
-             pssh(ji,:) = ( -4.5_wp + 6.8_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
-            end do
+            !                                     ! ====================
+         CASE ( 4 )                               ! WAD 4 configuration
+            !                                     ! ====================
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic bowl, mid-range initial ssh slope' 
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+            !                                    ! ===========================
+         CASE ( 5, 7 )                           ! WAD 5 and 7 configurations
+            !                                    ! ===========================
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Double slope with shelf'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+            !                                     ! ====================
+         CASE ( 6 )                               ! WAD 6 configuration
+            !                                     ! ====================
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel with gaussian ridge' 
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+            !
+            DO ji = mi0(jpiglo/2), mi0(jpiglo)
+               pts(ji,:,:,jp_sal) = 30._wp
+            END DO
+            !
+            !
+            !                                    ! ===========================
+         CASE DEFAULT                            ! NONE existing configuration
+            !                                    ! ===========================
+            WRITE(ctmp1,*) 'WAD test with a ', nn_cfg,' option is not coded'
+            !
+            CALL ctl_stop( ctmp1 )
+            !
+      END SELECT
+      !
+   END SUBROUTINE usr_def_istate
+
+     
+   SUBROUTINE usr_def_istate_ssh( ptmask, pssh )
+      !!----------------------------------------------------------------------
+      !!                   ***  ROUTINE usr_def_istate_ssh  ***
+      !! 
+      !! ** Purpose :   Initialization of the dynamics and tracers
+      !!                Here WAD_TEST_CASES configuration 
+      !!
+      !! ** Method  : - set ssh
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk)     , INTENT(in   ) ::   ptmask  ! t-point ocean mask             [m]
+      REAL(wp), DIMENSION(jpi,jpj)         , INTENT(  out) ::   pssh    ! sea-surface height
+      INTEGER  ::   ji, jj            ! dummy loop indices
+      REAL(wp) ::   zi, zj
+      !
+      INTEGER  ::   jk     ! dummy loop indices
+      REAL(wp) ::   zdam   ! location of dam [Km]
+      !!----------------------------------------------------------------------
+      !
+      !
+      SELECT CASE ( nn_cfg ) 
+         !                                        ! ====================
+         CASE ( 1 )                               ! WAD 1 configuration
+            !                                     ! ====================
+            !
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Closed box with EW linear bottom slope'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+            !
+            DO ji = 1,jpi
+               pssh(ji,:) = ( -5.5_wp + 7.4_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
+            END DO
+            !                                     ! ====================
+         CASE ( 2, 8 )                            ! WAD 2 configuration
+            !                                     ! ====================
+            !
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel, mid-range initial ssh slope'
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+            !
+            DO ji = 1,jpi
+               pssh(ji,:) = ( -1.5_wp + 5.0_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
+            END DO
+            !                                     ! ====================
+         CASE ( 3 )                               ! WAD 3 configuration
+            !                                     ! ====================
+            !
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel, extreme initial ssh slope' 
+            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
+            !
+            DO ji = 1,jpi
+               pssh(ji,:) = ( -4.5_wp + 6.8_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
+            END DO
 
             !
@@ -140,7 +214,7 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
-            do ji = 1,jpi
-             pssh(ji,:) = ( -2.5_wp + 5.5_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
-            end do
+            DO ji = 1,jpi
+               pssh(ji,:) = ( -2.5_wp + 5.5_wp*glamt(ji,1)/50._wp)*ptmask(ji,:,1)
+            END DO
 
             !
@@ -153,12 +227,11 @@
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
-            do ji = 1,jpi
-             pssh(ji,:) = ( -2.5_wp + 5.5_wp*(50._wp-glamt(ji,1))/50._wp)*ptmask(ji,:,1)
-            end do
-            !
-            do ji = mi0(jpiglo/2), mi0(jpiglo)
-             pts(ji,:,:,jp_sal) = 30._wp
-             pssh(ji,:) = -0.1*ptmask(ji,:,1)
-            end do
+            DO ji = 1,jpi
+               pssh(ji,:) = ( -2.5_wp + 5.5_wp*(50._wp-glamt(ji,1))/50._wp)*ptmask(ji,:,1)
+            END DO
+            !
+            DO ji = mi0(jpiglo/2), mi0(jpiglo)
+               pssh(ji,:) = -0.1*ptmask(ji,:,1)
+            END DO
             !
             !
@@ -182,5 +255,5 @@
       END_2D
       !
-   END SUBROUTINE usr_def_istate
+   END SUBROUTINE usr_def_istate_ssh
 
    !!======================================================================
Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/demo_cfgs.txt
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/demo_cfgs.txt	(revision 14059)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/tests/demo_cfgs.txt	(revision 14062)
@@ -12,4 +12,5 @@
 STATION_ASF OCE
 CPL_OASIS  OCE TOP ICE NST
+SWG OCE SWE
 C1D_ASICS OCE
 ICE_RHEO OCE SAS ICE
