Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_cfg
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_cfg	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_cfg	(revision 15121)
@@ -20,42 +20,74 @@
    !                       !      only there for backward compatibility test with v3.6
    !                       !      
-   cp_cfg      =  "orca"   !  name of the configuration
-   jp_cfg      =       2   !  resolution of the configuration
-   jpidta      =     182   !  1st lateral dimension ( >= jpi )
-   jpjdta      =     149   !  2nd    "         "    ( >= jpj )
-   jpkdta      =      31   !  number of levels      ( >= jpk )
-   jpiglo      =     182   !  1st dimension of global domain --> i =jpidta
-   jpjglo      =     149   !  2nd    -                  -    --> j  =jpjdta
-   jpizoom     =       1   !  left bottom (i,j) indices of the zoom
-   jpjzoom     =       1   !  in data domain indices
-   jperio      =       4   !  lateral cond. type (between 0 and 6)
+   cp_cfg      = 'eorca'
+   jp_cfg      = 25
+   jperio      = 4
+   jpidta      = 1442
+   jpiglo      = 1442
+   jpjdta      = 1207
+   jpjglo      = 1207
+   jpkdta      = 75
+   jpizoom     = 1
+   jpjzoom     = 1
 /
 !-----------------------------------------------------------------------
 &namzgr        !   vertical coordinate
 !-----------------------------------------------------------------------
-   ln_zps      = .true.    !  z-coordinate - partial steps
+   ln_mes      = .true.    !  Multi-Envelope s-coordinate
    ln_linssh   = .true.    !  linear free surface
 /
 !-----------------------------------------------------------------------
+&namzgr_mes    !   MEs-coordinate                     
+!-----------------------------------------------------------------------
+   ln_envl     =   .TRUE. , .TRUE. , .TRUE. , .TRUE., .TRUE.   ! (T/F) If the envelope is used
+   nn_strt     =     1    ,   1    ,    1   ,   1    ,   1     ! Stretch. funct.: Madec 1996 (0) or
+                                                               ! Song & Haidvogel 1994 (1) or                    
+                                                               ! Siddorn & Furner 2012 (2)
+   rn_ebot_min =     2.0  ,   27.0 ,  670.0 , 2700.0 , 7000.0  ! minimum depth of envelopes (>0, in m)
+   rn_ebot_max =     2.0  ,  570.0 , 2300.0 , 5900.0 , 7000.0  ! maximum depth of envelopes (>0, in m)
+   nn_slev     =     3    ,   33   ,   21   ,   18   ,    0    ! number of s-lev between env(n-1)                     
+                                                               ! and env(n)
+   rn_e_hc     =     0.0  ,    0.0 ,   0.0  ,   0.0  ,   0.0   ! critical depth for transition to                     
+                                                               ! stretch. coord.
+   rn_e_th     =     1.0  ,    1.2 ,   2.0  ,   0.0  ,   0.0   ! surf. control param.:                     
+                                                               ! SH94 or MD96: 0<=th<=20
+                                                               ! SF12: thickness surf. cell
+   rn_e_bb     =     0.9  ,    0.9 ,   0.85 ,   0.0  ,   0.0   ! bot. control param.:                     
+                                                               ! SH94 or MD96: 0<=bb<=1
+                                                               ! SF12: offset for calculating Zb
+   rn_e_al     =     0.0  ,    0.0 ,   0.0  ,   0.0  ,   0.0   ! alpha stretching param with SF12
+   rn_e_ba     =     0.0  ,    0.0 ,   0.0  ,   0.0  ,   0.0   ! SF12 bathymetry scaling factor for 
+                                                               ! calculating Zb
+   rn_bot_min  = 10.0       ! minimum depth of the ocean bottom (>0) (m)
+   rn_bot_max  = 5900.0     ! maximum depth of the ocean bottom (= ocean depth) (>0) (m)
+/
+!-----------------------------------------------------------------------
 &namdom        !   space and time domain (bathymetry, mesh, timestep)
 !-----------------------------------------------------------------------
-   jphgr_msh   =       0               !  type of horizontal mesh
-   ppglam0     =  999999.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
-   ppgphi0     =  999999.0             ! latitude  of first raw and column T-point (jphgr_msh = 1)
-   ppe1_deg    =  999999.0             !  zonal      grid-spacing (degrees)
-   ppe2_deg    =  999999.0             !  meridional grid-spacing (degrees)
-   ppe1_m      =  999999.0             !  zonal      grid-spacing (degrees)
-   ppe2_m      =  999999.0             !  meridional grid-spacing (degrees)
-   ppsur       =   -4762.96143546300   !  ORCA r4, r2 and r05 coefficients
-   ppa0        =     255.58049070440   ! (default coefficients)
-   ppa1        =     245.58132232490   !
-   ppkth       =      21.43336197938   !
-   ppacr       =       3.0             !
-   ppdzmin     =  999999.              !  Minimum vertical spacing
-   pphmax      =  999999.              !  Maximum depth
-   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
-   ppa2        =  999999.              !  Double tanh function parameters
-   ppkth2      =  999999.              !
-   ppacr2      =  999999.              !
+   nn_bathy    =  1
+   nn_msh      =  1
+   jphgr_msh   =  0
+   ldbletanh   = .TRUE.
+   ppglam0     =  999999.d0
+   ppgphi0     =  999999.d0
+   ppe1_deg    =  999999.d0
+   ppe2_deg    =  999999.d0
+   ppe1_m      =  999999.d0
+   ppe2_m      =  999999.d0                 
+   ppa0        =  103.9530096000000
+   ppa1        =  2.415951269000000
+   ppa2        =  100.7609285000000
+   ppacr       =  7.0
+   ppacr2      =  13.0
+   ppdzmin     =  999999.0
+   pphmax      =  999999.0
+   ppkth       =  15.35101370000000
+   ppkth2      =  48.02989372000000
+   ppsur       = -3958.951371276829
+   rn_atfp     =  0.1
+   rn_e3zps_min=  25.0
+   rn_e3zps_rat=  0.2
+   rn_hmin     = -8.0
+   rn_rdt      =  1350.0
 /
 !-----------------------------------------------------------------------
@@ -99,4 +131,6 @@
 &namlbc        !   lateral momentum boundary condition
 !-----------------------------------------------------------------------
+   rn_shlat    = 0.
+   ln_vorlat   = .false.
 /
 !-----------------------------------------------------------------------
@@ -107,5 +141,4 @@
 &nambbc        !   bottom temperature boundary condition                (default: NO)
 !-----------------------------------------------------------------------
-   ln_trabbc   = .true.    !  Apply a geothermal heating at the ocean bottom
 /
 !-----------------------------------------------------------------------
@@ -116,14 +149,10 @@
 &nameos        !   ocean physical parameters
 !-----------------------------------------------------------------------
-   ln_teos10    = .true.         !  = Use TEOS-10 equation of state
+   ln_teos10   = .true.
+   ln_eos80    = .false.
 /
 !-----------------------------------------------------------------------
 &namtra_adv    !   advection scheme for tracer
 !-----------------------------------------------------------------------
-   ln_traadv_fct =  .true.    !  FCT scheme
-      nn_fct_h   =  2               !  =2/4, horizontal 2nd / 4th order 
-      nn_fct_v   =  2               !  =2/4, vertical   2nd / COMPACT 4th order 
-      nn_fct_zts =  0               !  > 1 , 2nd order FCT scheme with vertical sub-timestepping
-      !                             !        (number of sub-timestep = nn_fct_zts)
 /
 !-----------------------------------------------------------------------
@@ -134,45 +163,8 @@
 &namtra_ldf    !   lateral diffusion scheme for tracers
 !----------------------------------------------------------------------------------
-   !                       !  Operator type:
-   ln_traldf_lap   =  .true.   !    laplacian operator
-   ln_traldf_blp   =  .false.  !  bilaplacian operator
-   !                       !  Direction of action:
-   ln_traldf_lev   =  .false.  !  iso-level
-   ln_traldf_hor   =  .false.  !  horizontal (geopotential)
-   ln_traldf_iso   =  .true.   !  iso-neutral (standard operator)
-   ln_traldf_triad =  .false.  !  iso-neutral (triad    operator)
-   !
-   !		       	         !  iso-neutral options:        
-   ln_traldf_msc   =  .true.   !  Method of Stabilizing Correction (both operators)
-   rn_slpmax       =   0.01    !  slope limit                      (both operators)
-   ln_triad_iso    =  .false.  !  pure horizontal mixing in ML              (triad only)
-   rn_sw_triad     =  1        !  =1 switching triad ; =0 all 4 triads used (triad only)
-   ln_botmix_triad =  .false.  !  lateral mixing on bottom                  (triad only)
-   !
-   !                       !  Coefficients:
-   nn_aht_ijk_t    = 20        !  space/time variation of eddy coef
-   !                                !   =-20 (=-30)    read in eddy_diffusivity_2D.nc (..._3D.nc) file
-   !                                !   =  0           constant
-   !                                !   = 10 F(k)      =ldf_c1d
-   !                                !   = 20 F(i,j)    =ldf_c2d
-   !                                !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
-   !                                !   = 30 F(i,j,k)  =ldf_c2d + ldf_c1d
-   !                                !   = 31 F(i,j,k,t)=F(local velocity)
-   rn_aht_0        = 2000.     !  lateral eddy diffusivity   (lap. operator) [m2/s]
-   rn_bht_0        = 1.e+12    !  lateral eddy diffusivity (bilap. operator) [m4/s]
 /
 !----------------------------------------------------------------------------------
 &namtra_ldfeiv !   eddy induced velocity param.
 !----------------------------------------------------------------------------------
-   ln_ldfeiv     =.true.   ! use eddy induced velocity parameterization
-   ln_ldfeiv_dia =.true.   ! diagnose eiv stream function and velocities
-   rn_aeiv_0     = 2000.   ! eddy induced velocity coefficient   [m2/s]
-   nn_aei_ijk_t  = 21      ! space/time variation of the eiv coeficient
-   !                                !   =-20 (=-30)    read in eddy_induced_velocity_2D.nc (..._3D.nc) file
-   !                                !   =  0           constant
-   !                                !   = 10 F(k)      =ldf_c1d
-   !                                !   = 20 F(i,j)    =ldf_c2d
-   !                                !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
-   !                                !   = 30 F(i,j,k)  =ldf_c2d + ldf_c1d
 /
 !-----------------------------------------------------------------------
@@ -187,9 +179,4 @@
 &namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
 !-----------------------------------------------------------------------
-   ln_dynvor_ene = .false. !  enstrophy conserving scheme
-   ln_dynvor_ens = .false. !  energy conserving scheme
-   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)
 /
 !-----------------------------------------------------------------------
@@ -200,29 +187,8 @@
 &namdyn_spg    !   Surface pressure gradient
 !-----------------------------------------------------------------------
-   ln_dynspg_ts = .true.   !  Split-explicit free surface
 /
 !-----------------------------------------------------------------------
 &namdyn_ldf    !   lateral diffusion on momentum
 !-----------------------------------------------------------------------
-   !                       !  Type of the operator :
-   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
-   ln_dynldf_lap =  .true.     !    laplacian operator
-   ln_dynldf_blp =  .false.    !  bilaplacian operator
-   !                       !  Direction of action  :
-   ln_dynldf_lev =  .true.     !  iso-level
-   ln_dynldf_hor =  .false.    !  horizontal (geopotential)
-   ln_dynldf_iso =  .false.    !  iso-neutral
-   !                       !  Coefficient
-   nn_ahm_ijk_t  = -30         !  space/time variation of eddy coef
-   !                                !  =-30  read in eddy_viscosity_3D.nc file
-   !                                !  =-20  read in eddy_viscosity_2D.nc file
-   !                                !  =  0  constant 
-   !                                !  = 10  F(k)=c1d
-   !                                !  = 20  F(i,j)=F(grid spacing)=c2d
-   !                                !  = 30  F(i,j,k)=c2d*c1d
-   !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
-   rn_ahm_0      =  40000.     !  horizontal laplacian eddy viscosity   [m2/s]
-   rn_ahm_b      =      0.     !  background eddy viscosity for ldf_iso [m2/s]
-   rn_bhm_0      = 1.e+12      !  horizontal bilaplacian eddy viscosity [m4/s]
 /
 !-----------------------------------------------------------------------
@@ -249,4 +215,15 @@
 &namctl        !   Control prints & Benchmark
 !-----------------------------------------------------------------------
+   ln_ctl      = .false.   !  trends control print (expensive!)
+   nn_print    =    0      !  level of print (0 no extra print)
+   nn_ictls    =    1      !  start i indice of control sum (use to compare mono versus
+   nn_ictle    =    1      !  end   i indice of control sum        multi processor runs
+   nn_jctls    =    1      !  start j indice of control               over a subdomain)
+   nn_jctle    =    1      !  end   j indice of control
+   nn_isplt    =    1      !  number of processors in i-direction
+   nn_jsplt    =    1      !  number of processors in j-direction
+   nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
+   nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+   nn_diacfl   =    0      !  Write out CFL diagnostics (=1) in cfl_diagnostics.ascii, or not (=0)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_cfg.ORI
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_cfg.ORI	(revision 15121)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_cfg.ORI	(revision 15121)
@@ -0,0 +1,219 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/OPA  Configuration namelist : used to overwrite defaults values defined in SHARED/namelist_ref
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!-----------------------------------------------------------------------
+&namrun        !   parameters of the run
+!-----------------------------------------------------------------------
+   nn_no       =       0   !  job number (no more used...)
+   cn_exp      =  "domaincfg"  !  experience name
+   nn_it000    =       1   !  first time step
+   nn_itend    =      75   !  last  time step (std 5475)
+/
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   !
+   ln_e3_dep   = .true.    ! =T : e3=dk[depth] in discret sens. 
+   !                       !      ===>>> will become the only possibility in v4.0
+   !                       ! =F : e3 analytical derivative of depth function
+   !                       !      only there for backward compatibility test with v3.6
+   !                       !      
+   cp_cfg      = 'eorca'
+   jp_cfg      = 25
+   jperio      = 4
+   jpidta      = 1442
+   jpiglo      = 1442
+   jpjdta      = 1207
+   jpjglo      = 1207
+   jpkdta      = 75
+   jpizoom     = 1
+   jpjzoom     = 1
+/
+!-----------------------------------------------------------------------
+&namzgr        !   vertical coordinate
+!-----------------------------------------------------------------------
+   ln_zps      = .true.    !  z-coordinate - partial steps
+   ln_linssh   = .true.    !  linear free surface
+/
+!-----------------------------------------------------------------------
+&namdom        !   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+   nn_bathy    =  1
+   nn_msh      =  1
+   jphgr_msh   =  0
+   ldbletanh   = .TRUE.
+   ppglam0     =  999999.d0
+   ppgphi0     =  999999.d0
+   ppe1_deg    =  999999.d0
+   ppe2_deg    =  999999.d0
+   ppe1_m      =  999999.d0
+   ppe2_m      =  999999.d0                 
+   ppa0        =  103.9530096000000
+   ppa1        =  2.415951269000000
+   ppa2        =  100.7609285000000
+   ppacr       =  7.0
+   ppacr2      =  13.0
+   ppdzmin     =  999999.0
+   pphmax      =  999999.0
+   ppkth       =  15.35101370000000
+   ppkth2      =  48.02989372000000
+   ppsur       = -3958.951371276829
+   rn_atfp     =  0.1
+   rn_e3zps_min=  25.0
+   rn_e3zps_rat=  0.2
+   rn_hmin     = -8.0
+   rn_rdt      =  1350.0
+/
+!-----------------------------------------------------------------------
+&namcrs        !   Grid coarsening for dynamics output and/or
+               !   passive tracer coarsened online simulations
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtsd    !   data : Temperature  & Salinity
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc        !   Surface Boundary Condition (surface module)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_core   !   namsbc_core  CORE bulk formulae
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_qsr    !   penetrative solar radiation
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_ssr    !   surface boundary condition : sea surface restoring
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_alb    !   albedo parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namberg       !   iceberg parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namlbc        !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+   rn_shlat    = 0.
+   ln_vorlat   = .false.
+/
+!-----------------------------------------------------------------------
+&nambfr        !   bottom friction
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nameos        !   ocean physical parameters
+!-----------------------------------------------------------------------
+   ln_teos10   = .true.
+   ln_eos80    = .false.
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
+!-----------------------------------------------------------------------
+/
+!----------------------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers
+!----------------------------------------------------------------------------------
+/
+!----------------------------------------------------------------------------------
+&namtra_ldfeiv !   eddy induced velocity param.
+!----------------------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_dmp    !   tracer: T & S newtonian damping
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_hpg    !   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_spg    !   Surface pressure gradient
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namctl        !   Control prints & Benchmark
+!-----------------------------------------------------------------------
+   ln_ctl      = .false.   !  trends control print (expensive!)
+   nn_print    =    0      !  level of print (0 no extra print)
+   nn_ictls    =    1      !  start i indice of control sum (use to compare mono versus
+   nn_ictle    =    1      !  end   i indice of control sum        multi processor runs
+   nn_jctls    =    1      !  start j indice of control               over a subdomain)
+   nn_jctle    =    1      !  end   j indice of control
+   nn_isplt    =    1      !  number of processors in i-direction
+   nn_jsplt    =    1      !  number of processors in j-direction
+   nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
+   nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+   nn_diacfl   =    0      !  Write out CFL diagnostics (=1) in cfl_diagnostics.ascii, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namptr       !   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namhsb       !  Heat and salt budgets
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namobs       !  observation usage
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nam_asminc   !   assimilation increments                               ('key_asminc')
+!-----------------------------------------------------------------------
+/
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_ref
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_ref	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_ref	(revision 15121)
@@ -104,4 +104,5 @@
    ln_zps      = .false.   !  z-coordinate - partial steps
    ln_sco      = .false.   !  s- or hybrid z-s-coordinate
+   ln_mes      = .false.   !  MES-coordinate 
    ln_isfcav   = .false.   !  ice shelf cavity
    ln_linssh   = .false.   !  linear free surface
@@ -131,4 +132,33 @@
                         !!!!!!!! Other stretching (not SH94 or SF12) [also uses rn_theta above]
    rn_thetb    =    1.0    !  bottom control parameter  (0<=thetb<= 1)
+/
+!-----------------------------------------------------------------------
+&namzgr_mes    !   MEs-coordinate                                       (default F)
+!-----------------------------------------------------------------------
+!                ! env. 1 ! env. 2 ! env. 3 ! env. 4 ! env. 5  !
+!                !        !        !        !        !         !
+   ln_envl     =   .TRUE. , .TRUE. , .TRUE. , .FALSE., .FALSE. ! (T/F) If the envelope is used
+   nn_strt     =     1    ,   1    ,    1   ,   0    ,   0     ! Stretch. funct.: Madec 1996 (0) or 
+                                                               ! Song & Haidvogel 1994 (1) or 
+                                                               ! Siddorn & Furner 2012 (2)
+   rn_ebot_min =    15.0  , 1000.0 , 1800.0 ,   0.0  ,   0.0   ! minimum depth of envelopes (>0, in m)
+   rn_ebot_max =   200.0  , 1000.0 , 2230.0 ,   0.0  ,   0.0   ! maximum depth of envelopes (>0, in m)
+   nn_slev     =    11    ,   10   ,   10   ,   0    ,   0     ! number of s-lev between env(n-1) 
+                                                               ! and env(n)
+   rn_e_hc     =    20.0  ,   10.0 ,   0.0  ,   0.0  ,   0.0   ! critical depth for transition to 
+                                                               ! stretch. coord.
+   rn_e_th     =     3.9  ,    2.98,   2.8  ,   0.0  ,   0.0   ! surf. control param.: 
+                                                               ! SH94 or MD96: 0<=th<=20
+                                                               ! SF12: thickness surf. cell
+   rn_e_bb     =     0.77 ,    0.15,   0.8  ,   0.0  ,   0.0   ! bot. control param.: 
+                                                               ! SH94 or MD96: 0<=bb<=1
+                                                               ! SF12: offset for calculating Zb
+   rn_e_al     =     0.0  ,    0.0 ,   0.0  ,   0.0  ,   0.0   ! alpha stretching param with SF12 
+   rn_e_ba     =     0.0  ,    0.0 ,   0.0  ,   0.0  ,   0.0   ! SF12 bathymetry scaling factor for 
+                                                               ! calculating Zb
+
+
+   rn_bot_min  = 5.0       ! minimum depth of the ocean bottom (>0) (m)
+   rn_bot_max  = 2201.5    ! maximum depth of the ocean bottom (= ocean depth) (>0) (m)
 /
 !-----------------------------------------------------------------------
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_ref.ORI
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_ref.ORI	(revision 15121)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/namelist_ref.ORI	(revision 15121)
@@ -0,0 +1,1279 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!!                            namelist_ref
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/OPA  :  1 - run manager      (namrun)
+!! namelists    2 - Domain           (namcfg, namzgr, namzgr_sco, namdom, namtsd, namcrs, namc1d, namc1d_uvd)
+!!              3 - Surface boundary (namsbc, namsbc_ana, namsbc_flx, namsbc_clio, namsbc_core, namsbc_sas
+!!                                    namsbc_cpl, namtra_qsr, namsbc_rnf,
+!!                                    namsbc_apr, namsbc_ssr, namsbc_alb, namsbc_wave)
+!!              4 - lateral boundary (namlbc, namagrif, nambdy, nambdy_tide)
+!!              5 - bottom  boundary (nambfr, nambbc, nambbl)
+!!              6 - Tracer           (nameos, namtra_adv, namtra_ldf, namtra_ldfeiv, namtra_dmp)
+!!              7 - dynamics         (namdyn_adv, namdyn_vor, namdyn_hpg, namdyn_spg, namdyn_ldf)
+!!              8 - Verical physics  (namzdf, namzdf_ric, namzdf_tke, namzdf_ddm, namzdf_tmx)
+!!              9 - diagnostics      (namnc4, namtrd, namspr, namflo, namhsb, namsto)
+!!             10 - miscellaneous    (nammpp, namctl)
+!!             11 - Obs & Assim      (namobs, nam_asminc)
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+!!======================================================================
+!!                   ***  Run management namelists  ***
+!!======================================================================
+!!   namrun       parameters of the run
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namrun        !   parameters of the run
+!-----------------------------------------------------------------------
+   nn_no       =       0   !  job number (no more used...)
+   cn_exp      =  "ORCA2"  !  experience name
+   nn_it000    =       1   !  first time step
+   nn_itend    =    5475   !  last  time step (std 5475)
+   nn_date0    =  010101   !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_time0    =       0   !  initial time of day in hhmm
+   nn_leapy    =       0   !  Leap year calendar (1) or not (0)
+   ln_rstart   = .false.   !  start from rest (F) or from a restart file (T)
+      nn_euler    =    1            !  = 0 : start with forward time step if ln_rstart=T
+      nn_rstctl   =    0            !  restart control ==> activated only if ln_rstart=T
+      !                             !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
+      !                             !    = 1 nn_date0 read in namelist ; nn_it000 : check consistancy between namelist and restart
+      !                             !    = 2 nn_date0 read in restart  ; nn_it000 : check consistancy between namelist and restart
+      cn_ocerst_in    = "restart"   !  suffix of ocean restart name (input)
+      cn_ocerst_indir = "."         !  directory from which to read input ocean restarts
+      cn_ocerst_out   = "restart"   !  suffix of ocean restart name (output)
+      cn_ocerst_outdir= "."         !  directory in which to write output ocean restarts
+   ln_iscpl    = .false.   !  cavity evolution forcing or coupling to ice sheet model
+   nn_istate   =       0   !  output the initial state (1) or not (0)
+   ln_rst_list = .false.   !  output restarts at list of times using nn_stocklist (T) or at set frequency with nn_stock (F)
+   nn_stock    =    5475   !  frequency of creation of a restart file (modulo referenced to 1)
+   nn_stocklist = 0,0,0,0,0,0,0,0,0,0 ! List of timesteps when a restart file is to be written
+   nn_write    =    5475   !  frequency of write in the output file   (modulo referenced to nn_it000)
+   ln_mskland  = .false.   !  mask land points in NetCDF outputs (costly: + ~15%)
+   ln_cfmeta   = .false.   !  output additional data to netCDF files required for compliance with the CF metadata standard
+   ln_clobber  = .true.    !  clobber (overwrite) an existing file
+   nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
+/
+!
+!!======================================================================
+!!                      ***  Domain namelists  ***
+!!======================================================================
+!!   namcfg       parameters of the configuration
+!!   namzgr       vertical coordinate                                   (default: NO selection)
+!!   namzgr_sco   s-coordinate or hybrid z-s-coordinate
+!!   namdom       space and time domain (bathymetry, mesh, timestep)
+!!   namwad       Wetting and drying                                    (default F)
+!!   namtsd       data: temperature & salinity
+!!   namcrs       coarsened grid (for outputs and/or TOP)               ("key_crs")
+!!   namc1d       1D configuration options                              ("key_c1d")
+!!   namc1d_dyndmp 1D newtonian damping applied on currents             ("key_c1d")
+!!   namc1d_uvd   1D data (currents)                                    ("key_c1d")
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   !
+   ln_e3_dep   = .true.    ! =T : e3=dk[depth] in discret sens. 
+   !                       !      ===>>> will become the only possibility in v4.0
+   !                       ! =F : e3 analytical derivative of depth function
+   !                       !      only there for backward compatibility test with v3.6
+   !
+   cp_cfg      = "default" !  name of the configuration
+   cp_cfz      = "no zoom" !  name of the zoom of configuration
+   jp_cfg      =      0    !  resolution of the configuration
+   jpidta      =     10    !  1st lateral dimension ( >= jpi )
+   jpjdta      =     12    !  2nd    "         "    ( >= jpj )
+   jpkdta      =     31    !  number of levels      ( >= jpk )
+   jpiglo      =     10    !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     12    !  2nd    -                  -    --> j =jpjdta
+   jpizoom     =      1    !  left bottom (i,j) indices of the zoom
+   jpjzoom     =      1    !  in data domain indices
+   jperio      =      0    !  lateral cond. type (between 0 and 6)
+                                 !  = 0 closed                 ;   = 1 cyclic East-West
+                                 !  = 2 equatorial symmetric   ;   = 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
+   ln_use_jattr = .false.  !  use (T) the file attribute: open_ocean_jstart, if present
+                           !  in netcdf input files, as the start j-row for reading
+/
+!-----------------------------------------------------------------------
+&namzgr        !   vertical coordinate                                  (default: NO selection)
+!-----------------------------------------------------------------------
+   ln_zco      = .false.   !  z-coordinate - full    steps
+   ln_zps      = .false.   !  z-coordinate - partial steps
+   ln_sco      = .false.   !  s- or hybrid z-s-coordinate
+   ln_isfcav   = .false.   !  ice shelf cavity
+   ln_linssh   = .false.   !  linear free surface
+/
+!-----------------------------------------------------------------------
+&namzgr_sco    !   s-coordinate or hybrid z-s-coordinate                (default F)
+!-----------------------------------------------------------------------
+   ln_s_sh94   = .false.    !  Song & Haidvogel 1994 hybrid S-sigma   (T)|
+   ln_s_sf12   = .false.   !  Siddorn & Furner 2012 hybrid S-z-sigma (T)| if both are false the NEMO tanh stretching is applied
+   ln_sigcrit  = .false.   !  use sigma coordinates below critical depth (T) or Z coordinates (F) for Siddorn & Furner stretch
+                           !  stretching coefficients for all functions
+   rn_sbot_min =   10.0    !  minimum depth of s-bottom surface (>0) (m)
+   rn_sbot_max = 7000.0    !  maximum depth of s-bottom surface (= ocean depth) (>0) (m)
+   rn_hc       =  150.0    !  critical depth for transition to stretched coordinates
+                        !!!!!!!  Envelop bathymetry
+   rn_rmax     =    0.3    !  maximum cut-off r-value allowed (0<r_max<1)
+                        !!!!!!!  SH94 stretching coefficients  (ln_s_sh94 = .true.)
+   rn_theta    =    6.0    !  surface control parameter (0<=theta<=20)
+   rn_bb       =    0.8    !  stretching with SH94 s-sigma
+                        !!!!!!!  SF12 stretching coefficient  (ln_s_sf12 = .true.)
+   rn_alpha    =    4.4    !  stretching with SF12 s-sigma
+   rn_efold    =    0.0    !  efold length scale for transition to stretched coord
+   rn_zs       =    1.0    !  depth of surface grid box
+                           !  bottom cell depth (Zb) is a linear function of water depth Zb = H*a + b
+   rn_zb_a     =    0.024  !  bathymetry scaling factor for calculating Zb
+   rn_zb_b     =   -0.2    !  offset for calculating Zb
+                        !!!!!!!! Other stretching (not SH94 or SF12) [also uses rn_theta above]
+   rn_thetb    =    1.0    !  bottom control parameter  (0<=thetb<= 1)
+/
+!-----------------------------------------------------------------------
+&namdom        !   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+   nn_bathy    =    1      !  compute (=0) or read (=1) the bathymetry file
+   rn_bathy    =    0.     !  value of the bathymetry. if (=0) bottom flat at jpkm1
+   nn_closea   =    0      !  remove (=0) or keep (=1) closed seas and lakes (ORCA)
+   nn_msh      =    1      !  create (=1) a mesh file or not (=0)
+   rn_hmin     =   -3.     !  min depth of the ocean (>0) or min number of ocean level (<0)
+   rn_isfhmin  =    1.00   !  treshold (m) to discriminate grounding ice to floating ice
+   rn_e3zps_min=   20.     !  partial step thickness is set larger than the minimum of
+   rn_e3zps_rat=    0.1    !  rn_e3zps_min and rn_e3zps_rat*e3t, with 0<rn_e3zps_rat<1
+                           !
+   rn_rdt      = 5760.     !  time step for the dynamics (and tracer if nn_acc=0)
+   rn_atfp     =    0.1    !  asselin time filter parameter
+   ln_crs      = .false.      !  Logical switch for coarsening module
+   jphgr_msh   =       0               !  type of horizontal mesh
+                                       !  = 0 curvilinear coordinate on the sphere read in coordinate.nc
+                                       !  = 1 geographical mesh on the sphere with regular grid-spacing
+                                       !  = 2 f-plane with regular grid-spacing
+                                       !  = 3 beta-plane with regular grid-spacing
+                                       !  = 4 Mercator grid with T/U point at the equator
+   ppglam0     =       0.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
+   ppgphi0     =     -35.0             ! latitude  of first raw and column T-point (jphgr_msh = 1)
+   ppe1_deg    =       1.0             !  zonal      grid-spacing (degrees)
+   ppe2_deg    =       0.5             !  meridional grid-spacing (degrees)
+   ppe1_m      =    5000.0             !  zonal      grid-spacing (degrees)
+   ppe2_m      =    5000.0             !  meridional grid-spacing (degrees)
+   ppsur       =    -4762.96143546300  !  ORCA r4, r2 and r05 coefficients
+   ppa0        =      255.58049070440  ! (default coefficients)
+   ppa1        =      245.58132232490  !
+   ppkth       =       21.43336197938  !
+   ppacr       =        3.0            !
+   ppdzmin     =       10.             !  Minimum vertical spacing
+   pphmax      =     5000.             !  Maximum depth
+   ldbletanh   =    .TRUE.             !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =      100.760928500000 !  Double tanh function parameters
+   ppkth2      =       48.029893720000 !
+   ppacr2      =       13.000000000000 !
+/
+!-----------------------------------------------------------------------
+&namwad        !   Wetting and drying                                   (default F)
+!-----------------------------------------------------------------------
+   ln_wd       = .false.   !  T/F activation of wetting and drying
+   rn_wdmin1   =  0.1      !  Minimum wet depth on dried cells
+   rn_wdmin2   =  0.01     !  Tolerance of min wet depth on dried cells
+   rn_wdld     =  20.0     !  Land elevation below which wetting/drying is allowed
+   nn_wdit     =  10       !  Max iterations for W/D limiter
+/
+!-----------------------------------------------------------------------
+&namtsd        !   data : Temperature  & Salinity
+!-----------------------------------------------------------------------
+!              !  file name                 ! frequency (hours) ! variable ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                            !  (if <0  months)  !   name   !  (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_tem = 'data_1m_potential_temperature_nomask',     -1      ,'votemper',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_sal = 'data_1m_salinity_nomask'             ,     -1      ,'vosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   !
+   cn_dir      = './'      !  root directory for the location of the runoff files
+   ln_tsd_init = .true.    !  Initialisation of ocean T & S with T & S input data (T) or not (F)
+   ln_tsd_tradmp = .true.  !  damping of ocean T & S toward T & S input data (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namcrs        !   coarsened grid (for outputs and/or TOP)              ("key_crs")
+!-----------------------------------------------------------------------
+   nn_factx    = 3         !  Reduction factor of x-direction
+   nn_facty    = 3         !  Reduction factor of y-direction
+   nn_binref   = 0         !  Bin centering preference: NORTH or EQUAT
+                           !  0, coarse grid is binned with preferential treatment of the north fold
+                           !  1, coarse grid is binned with centering at the equator
+                           !    Symmetry with nn_facty being odd-numbered. Asymmetry with even-numbered nn_facty.
+   nn_msh_crs  = 1         !  create (=1) a mesh file or not (=0)
+   nn_crs_kz   = 0         ! 0, MEAN of volume boxes
+                           ! 1, MAX of boxes
+                           ! 2, MIN of boxes
+   ln_crs_wn   = .true.    ! wn coarsened (T) or computed using horizontal divergence ( F )
+/
+!-----------------------------------------------------------------------
+&namc1d        !   1D configuration options                             ("key_c1d")
+!-----------------------------------------------------------------------
+   rn_lat1d    =      50   !  Column latitude (default at PAPA station)
+   rn_lon1d    =    -145   !  Column longitude (default at PAPA station)
+   ln_c1d_locpt=  .true.   ! Localization of 1D config in a grid (T) or independant point (F)
+/
+!-----------------------------------------------------------------------
+&namc1d_dyndmp !   U & V newtonian damping                              ("key_c1d")
+!-----------------------------------------------------------------------
+   ln_dyndmp   =  .false.  !  add a damping term (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namc1d_uvd    !   data: U & V currents                                 ("key_c1d")
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_ucur     = 'ucurrent'  ,         -1        ,'u_current',   .false.    , .true. , 'monthly' ,  ''      ,  'Ume'   , ''
+   sn_vcur     = 'vcurrent'  ,         -1        ,'v_current',   .false.    , .true. , 'monthly' ,  ''      ,  'Vme'   , ''
+!
+   cn_dir        = './'    !  root directory for the location of the files
+   ln_uvd_init   = .false. !  Initialisation of ocean U & V with U & V input data (T) or not (F)
+   ln_uvd_dyndmp = .false. !  damping of ocean U & V toward U & V input data (T) or not (F)
+/
+
+!!======================================================================
+!!            ***  Surface Boundary Condition namelists  ***
+!!======================================================================
+!!   namsbc          surface boundary condition
+!!   namsbc_ana      analytical         formulation                     (ln_ana     =T)
+!!   namsbc_flx      flux               formulation                     (ln_flx     =T)
+!!   namsbc_clio     CLIO bulk formulae formulation                     (ln_blk_clio=T)
+!!   namsbc_core     CORE bulk formulae formulation                     (ln_blk_core=T)
+!!   namsbc_mfs      MFS  bulk formulae formulation                     (ln_blk_mfs =T)
+!!   namsbc_cpl      CouPLed            formulation                     ("key_oasis3" )
+!!   namsbc_sas      StAndalone Surface module
+!!   namtra_qsr      penetrative solar radiation                        (ln_traqsr  =T)
+!!   namsbc_rnf      river runoffs                                      (ln_rnf     =T)
+!!   namsbc_isf      ice shelf melting/freezing                         (nn_isf     >0)
+!!   namsbc_iscpl    coupling option between land ice model and ocean
+!!   namsbc_apr      Atmospheric Pressure                               (ln_apr_dyn =T)
+!!   namsbc_ssr      sea surface restoring term (for T and/or S)        (ln_ssr     =T)
+!!   namsbc_alb      albedo parameters
+!!   namsbc_wave     external fields from wave model                    (ln_wave    =T)
+!!   namberg         iceberg floats                                     (ln_icebergs=T)
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namsbc        !   Surface Boundary Condition (surface module)
+!-----------------------------------------------------------------------
+   nn_fsbc     = 5         !  frequency of surface boundary condition computation
+                           !     (also = the frequency of sea-ice & iceberg model call)
+                     ! Type of air-sea fluxes 
+   ln_ana      = .false.   !  analytical formulation                    (T => fill namsbc_ana )
+   ln_flx      = .false.   !  flux formulation                          (T => fill namsbc_flx )
+   ln_blk_clio = .false.   !  CLIO bulk formulation                     (T => fill namsbc_clio)
+   ln_blk_core = .true.    !  CORE bulk formulation                     (T => fill namsbc_core)
+   ln_blk_mfs  = .false.   !  MFS bulk formulation                      (T => fill namsbc_mfs )
+                     ! Type of coupling (Ocean/Ice/Atmosphere) :
+   ln_cpl      = .false.   !  atmosphere coupled   formulation          ( requires key_oasis3 )
+   ln_mixcpl   = .false.   !  forced-coupled mixed formulation          ( requires key_oasis3 )
+   nn_components = 0       !  configuration of the opa-sas OASIS coupling
+                           !  =0 no opa-sas OASIS coupling: default single executable configuration
+                           !  =1 opa-sas OASIS coupling: multi executable configuration, OPA component
+                           !  =2 opa-sas OASIS coupling: multi executable configuration, SAS component 
+   nn_limflx = -1          !  LIM3 Multi-category heat flux formulation (use -1 if LIM3 is not used)
+                           !  =-1  Use per-category fluxes, bypass redistributor, forced mode only, not yet implemented coupled
+                           !  = 0  Average per-category fluxes (forced and coupled mode)
+                           !  = 1  Average and redistribute per-category fluxes, forced mode only, not yet implemented coupled
+                           !  = 2  Redistribute a single flux over categories (coupled mode only)
+                     ! Sea-ice :
+   nn_ice      = 2         !  =0 no ice boundary condition   ,
+                           !  =1 use observed ice-cover      ,
+                           !  =2 ice-model used                         ("key_lim3", "key_lim2", "key_cice")
+   nn_ice_embd = 1         !  =0 levitating ice (no mass exchange, concentration/dilution effect)
+                           !  =1 levitating ice with mass and salt exchange but no presure effect
+                           !  =2 embedded sea-ice (full salt and mass exchanges and pressure)
+                     ! Misc. options of sbc : 
+   ln_traqsr   = .true.    !  Light penetration in the ocean            (T => fill namtra_qsr )
+   ln_dm2dc    = .false.   !  daily mean to diurnal cycle on short wave
+   ln_rnf      = .true.    !  runoffs                                   (T => fill namsbc_rnf)
+   ln_ssr      = .true.    !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
+   nn_fwb      = 2         !  FreshWater Budget: =0 unchecked
+                           !     =1 global mean of e-p-r set to zero at each time step
+                           !     =2 annual global mean of e-p-r set to zero
+   ln_apr_dyn  = .false.   !  Patm gradient added in ocean & ice Eqs.   (T => fill namsbc_apr )
+   ln_isf      = .false.   !  ice shelf                                 (T   => fill namsbc_isf)
+   ln_wave     = .false.   !  coupling with surface wave                (T => fill namsbc_wave)
+   nn_lsm      = 0         !  =0 land/sea mask for input fields is not applied (keep empty land/sea mask filename field) ,
+                           !  =1:n number of iterations of land/sea mask application for input fields (fill land/sea mask filename field)
+/
+!-----------------------------------------------------------------------
+&namsbc_ana    !   analytical surface boundary condition
+!-----------------------------------------------------------------------
+   nn_tau000   =   0       !  gently increase the stress over the first ntau_rst time-steps
+   rn_utau0    =   0.5     !  uniform value for the i-stress
+   rn_vtau0    =   0.e0    !  uniform value for the j-stress
+   rn_qns0     =   0.e0    !  uniform value for the total heat flux
+   rn_qsr0     =   0.e0    !  uniform value for the solar radiation
+   rn_emp0     =   0.e0    !  uniform value for the freswater budget (E-P)
+/
+!-----------------------------------------------------------------------
+&namsbc_flx    !   surface boundary condition : flux formulation
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_utau     = 'utau'      ,        24         , 'utau'    , .false.      , .false., 'yearly'  , ''       , ''       , ''
+   sn_vtau     = 'vtau'      ,        24         , 'vtau'    , .false.      , .false., 'yearly'  , ''       , ''       , ''
+   sn_qtot     = 'qtot'      ,        24         , 'qtot'    , .false.      , .false., 'yearly'  , ''       , ''       , ''
+   sn_qsr      = 'qsr'       ,        24         , 'qsr'     , .false.      , .false., 'yearly'  , ''       , ''       , ''
+   sn_emp      = 'emp'       ,        24         , 'emp'     , .false.      , .false., 'yearly'  , ''       , ''       , ''
+
+   cn_dir      = './'      !  root directory for the location of the flux files
+/
+!-----------------------------------------------------------------------
+&namsbc_clio   !   namsbc_clio  CLIO bulk formulae
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_utau     = 'taux_1m'   ,       -1          , 'sozotaux',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_vtau     = 'tauy_1m'   ,       -1          , 'sometauy',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_wndm     = 'flx'       ,       -1          , 'socliowi',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_tair     = 'flx'       ,       -1          , 'socliot2',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_humi     = 'flx'       ,       -1          , 'socliohu',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_ccov     = 'flx'       ,       -1          , 'socliocl',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_prec     = 'flx'       ,       -1          , 'socliopl',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+
+   cn_dir      = './'      !  root directory for the location of the bulk files are
+/
+!-----------------------------------------------------------------------
+&namsbc_core   !   namsbc_core  CORE bulk formulae
+!-----------------------------------------------------------------------
+!              !  file name                   ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights                               ! rotation ! land/sea mask !
+!              !                              !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename                              ! pairing  ! filename      !
+   sn_wndi     = 'u_10.15JUNE2009_fill'       ,         6         , 'U_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Uwnd'   , ''
+   sn_wndj     = 'v_10.15JUNE2009_fill'       ,         6         , 'V_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bicubic_noc.nc'   , 'Vwnd'   , ''
+   sn_qsr      = 'ncar_rad.15JUNE2009_fill'   ,        24         , 'SWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_qlw      = 'ncar_rad.15JUNE2009_fill'   ,        24         , 'LWDN_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_tair     = 't_10.15JUNE2009_fill'       ,         6         , 'T_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_humi     = 'q_10.15JUNE2009_fill'       ,         6         , 'Q_10_MOD',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_prec     = 'ncar_precip.15JUNE2009_fill',        -1         , 'PRC_MOD1',   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_snow     = 'ncar_precip.15JUNE2009_fill',        -1         , 'SNOW'    ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+   sn_tdif     = 'taudif_core'                ,        24         , 'taudif'  ,   .false.    , .true. , 'yearly'  , 'weights_core_orca2_bilinear_noc.nc'  , ''       , ''
+
+   cn_dir      = './'      !  root directory for the location of the bulk files
+   ln_taudif   = .false.   !  HF tau contribution: use "mean of stress module - module of the mean stress" data
+   rn_zqt      = 10.       !  Air temperature and humidity reference height (m)
+   rn_zu       = 10.       !  Wind vector reference height (m)
+   rn_pfac     = 1.        !  multiplicative factor for precipitation (total & snow)
+   rn_efac     = 1.        !  multiplicative factor for evaporation (0. or 1.)
+   rn_vfac     = 0.        !  multiplicative factor for ocean/ice velocity
+                           !  in the calculation of the wind stress (0.=absolute winds or 1.=relative winds)
+/
+!-----------------------------------------------------------------------
+&namsbc_mfs   !   namsbc_mfs  MFS bulk formulae
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable ! time interp. !  clim  ! 'yearly'/ ! weights     ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name   !   (logical)  !  (T/F) ! 'monthly' ! filename    ! pairing  ! filename      !
+   sn_wndi     =   'ecmwf'   ,        6          , 'u10'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_wndj     =   'ecmwf'   ,        6          , 'v10'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_clc      =   'ecmwf'   ,        6          , 'clc'    ,    .true.    , .false., 'daily'   ,'bilinear.nc',   ''     ,   ''
+   sn_msl      =   'ecmwf'   ,        6          , 'msl'    ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_tair     =   'ecmwf'   ,        6          , 't2'     ,    .true.    , .false., 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+   sn_rhm      =   'ecmwf'   ,        6          , 'rh'     ,    .true.    , .false., 'daily'   ,'bilinear.nc',   ''     ,   ''
+   sn_prec     =   'ecmwf'   ,        6          , 'precip' ,    .true.    , .true. , 'daily'   ,'bicubic.nc' ,   ''     ,   ''
+
+   cn_dir      = './ECMWF/'      !  root directory for the location of the bulk files
+/
+!-----------------------------------------------------------------------
+&namsbc_cpl    !   coupled ocean/atmosphere model                       ("key_oasis3")
+!-----------------------------------------------------------------------
+!                    !     description      !  multiple  !    vector   !      vector          ! vector !
+!                    !                      ! categories !  reference  !    orientation       ! grids  !
+! send
+   sn_snd_temp   =   'weighted oce and ice' ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_alb    =   'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_thick  =   'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+   sn_snd_crt    =   'none'                 ,    'no'    , 'spherical' , 'eastward-northward' ,  'T'
+   sn_snd_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''           ,   ''
+! receive
+   sn_rcv_w10m   =   'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_taumod =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_tau    =   'oce only'             ,    'no'    , 'cartesian' , 'eastward-northward',  'U,V'
+   sn_rcv_dqnsdt =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_qsr    =   'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_qns    =   'oce and ice'          ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_emp    =   'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_rnf    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_cal    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+   sn_rcv_co2    =   'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+!
+   nn_cplmodel   =     1   !  Maximum number of models to/from which NEMO is potentialy sending/receiving data
+   ln_usecplmask = .false. !  use a coupling mask file to merge data received from several models
+   !                       !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
+/
+!-----------------------------------------------------------------------
+&namsbc_sas    !   analytical surface boundary condition
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !  (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_usp      = 'sas_grid_U',     120           , 'vozocrtx',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_vsp      = 'sas_grid_V',     120           , 'vomecrty',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_tem      = 'sas_grid_T',     120           , 'sosstsst',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_sal      = 'sas_grid_T',     120           , 'sosaline',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_ssh      = 'sas_grid_T',     120           , 'sossheig',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_e3t      = 'sas_grid_T',     120           , 'e3t_m'   ,   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+   sn_frq      = 'sas_grid_T',     120           , 'frq_m'   ,   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,    ''
+
+   ln_3d_uve   = .true.    !  specify whether we are supplying a 3D u,v and e3 field
+   ln_read_frq = .false.   !  specify whether we must read frq or not
+   cn_dir      = './'      !  root directory for the location of the bulk files are
+/
+!-----------------------------------------------------------------------
+&namtra_qsr    !   penetrative solar radiation                          (ln_traqsr=T)
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_chl      ='chlorophyll',        -1         , 'CHLA'    ,   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+
+   cn_dir      = './'      !  root directory for the location of the runoff files
+   ln_qsr_rgb  = .true.    !  RGB (Red-Green-Blue) light penetration
+   ln_qsr_2bd  = .false.   !  2 bands              light penetration
+   ln_qsr_bio  = .false.   !  bio-model light penetration
+   nn_chldta   =      1    !  RGB : Chl data (=1) or cst value (=0)
+   rn_abs      =   0.58    !  RGB & 2 bands: fraction of light (rn_si1)
+   rn_si0      =   0.35    !  RGB & 2 bands: shortess depth of extinction
+   rn_si1      =   23.0    !  2 bands: longest depth of extinction
+   ln_qsr_ice  = .true.    !  light penetration for ice-model LIM3
+/
+!-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition          (ln_rnf=T)
+!-----------------------------------------------------------------------
+!              !  file name           ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                      !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_rnf      = 'runoff_core_monthly',        -1         , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'runoff_core_monthly',         0         , 'socoefr0',   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_s_rnf    = 'runoffs'            ,        24         , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_t_rnf    = 'runoffs'            ,        24         , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_dep_rnf  = 'runoffs'            ,         0         , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+
+   cn_dir      = './'      !  root directory for the location of the runoff files
+   ln_rnf_mouth= .true.    !  specific treatment at rivers mouths
+      rn_hrnf     =  15.e0    !  depth over which enhanced vertical mixing is used    (ln_rnf_mouth=T)
+      rn_avt_rnf  =   1.e-3   !  value of the additional vertical mixing coef. [m2/s] (ln_rnf_mouth=T)
+   rn_rfact    =   1.e0    !  multiplicative factor for runoff
+   ln_rnf_depth= .false.   !  read in depth information for runoff
+   ln_rnf_tem  = .false.   !  read in temperature information for runoff
+   ln_rnf_sal  = .false.   !  read in salinity information for runoff
+   ln_rnf_depth_ini = .false. ! compute depth at initialisation from runoff file
+      rn_rnf_max  = 5.735e-4  !  max value of the runoff climatologie over global domain ( ln_rnf_depth_ini = .true )
+      rn_dep_max  = 150.      !  depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
+      nn_rnf_depth_file = 0   !  create (=1) a runoff depth file or not (=0)
+/
+!-----------------------------------------------------------------------
+&namsbc_isf    !  Top boundary layer (ISF)                              (nn_isf >0)
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours) ! variable ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !           !  (if <0  months)  !   name   !  (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+! nn_isf == 4
+   sn_fwfisf   = 'rnfisf'  ,         -12       ,'sowflisf',   .false.   , .true. , 'yearly'  ,    ''    ,   ''     ,    ''
+! nn_isf == 3
+   sn_rnfisf   = 'rnfisf'  ,         -12       ,'sofwfisf',   .false.   , .true. , 'yearly'  ,    ''    ,   ''     ,    ''
+! nn_isf == 2 and 3
+   sn_depmax_isf='rnfisf'  ,         -12       ,'sozisfmax',  .false.   , .true. , 'yearly'  ,    ''    ,   ''     ,    ''
+   sn_depmin_isf='rnfisf'  ,         -12       ,'sozisfmin',  .false.   , .true. , 'yearly'  ,    ''    ,   ''     ,    ''
+! nn_isf == 2
+   sn_Leff_isf = 'rnfisf'  ,         -12       ,'Leff'    ,   .false.   , .true. , 'yearly'  ,    ''    ,   ''     ,    ''
+!
+! for all case
+   nn_isf      = 1         !  ice shelf melting/freezing
+                           !  1 = presence of ISF    2 = bg03 parametrisation 
+                           !  3 = rnf file for isf   4 = ISF fwf specified
+                           !  option 1 and 4 need ln_isfcav = .true. (domzgr)
+! only for nn_isf = 1 or 2
+   rn_gammat0  = 1.e-4     ! gammat coefficient used in blk formula
+   rn_gammas0  = 1.e-4     ! gammas coefficient used in blk formula
+! only for nn_isf = 1 or 4
+   rn_hisf_tbl =  30.      ! thickness of the top boundary layer    (Losh et al. 2008)
+   !                       ! 0 => thickness of the tbl = thickness of the first wet cell
+! only for nn_isf = 1
+   nn_isfblk   = 1         ! 1 ISOMIP  like: 2 equations formulation (Hunter et al., 2006)
+   !                       ! 2 ISOMIP+ like: 3 equations formulation (Asay-Davis et al., 2015)
+   nn_gammablk = 1         ! 0 = cst Gammat (= gammat/s)
+   !                       ! 1 = velocity dependend Gamma (u* * gammat/s)  (Jenkins et al. 2010)
+   !                       ! 2 = velocity and stability dependent Gamma    (Holland et al. 1999)
+/
+!-----------------------------------------------------------------------
+&namsbc_iscpl  !   land ice / ocean coupling option                     
+!-----------------------------------------------------------------------
+   nn_drown    = 10        ! number of iteration of the extrapolation loop (fill the new wet cells)
+   ln_hsb      = .false.   ! activate conservation module (conservation exact after a time of rn_fiscpl)
+   nn_fiscpl   = 43800     ! (number of time step) conservation period (maybe should be fix to the coupling frequencey of restart frequency)
+/
+!-----------------------------------------------------------------------
+&namsbc_apr    !   Atmospheric pressure used as ocean forcing or in bulk
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours) ! variable ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !           !  (if <0  months)  !   name   !  (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_apr      = 'patm'    ,         -1        ,'somslpre',   .true.    , .true. , 'yearly'  ,    ''    ,    ''    ,      ''
+
+   cn_dir      = './'      !  root directory for the location of the bulk files
+   rn_pref     = 101000.   !  reference atmospheric pressure   [N/m2]/
+   ln_ref_apr  = .false.   !  ref. pressure: global mean Patm (T) or a constant (F)
+   ln_apr_obc  = .false.   !  inverse barometer added to OBC ssh data
+/
+!-----------------------------------------------------------------------
+&namsbc_ssr    !   surface boundary condition : sea surface restoring   (ln_ssr=T)
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours) ! variable ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !           !  (if <0  months)  !   name   !   (logical) !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_sst      = 'sst_data',        24         ,  'sst'   ,    .false.  , .false., 'yearly'  ,    ''    ,    ''    ,     ''
+   sn_sss      = 'sss_data',        -1         ,  'sss'   ,    .true.   , .true. , 'yearly'  ,    ''    ,    ''    ,     ''
+
+   cn_dir      = './'      !  root directory for the location of the runoff files
+   nn_sstr     =     0     !  add a retroaction term in the surface heat       flux (=1) or not (=0)
+   nn_sssr     =     2     !  add a damping     term in the surface freshwater flux (=2)
+                           !  or to SSS only (=1) or no damping term (=0)
+   rn_dqdt     =   -40.    !  magnitude of the retroaction on temperature   [W/m2/K]
+   rn_deds     =  -166.67  !  magnitude of the damping on salinity   [mm/day]
+   ln_sssr_bnd =  .true.   !  flag to bound erp term (associated with nn_sssr=2)
+   rn_sssr_bnd =   4.e0    !  ABS(Max/Min) value of the damping erp term [mm/day]
+/
+!-----------------------------------------------------------------------
+&namsbc_alb    !   albedo parameters
+!-----------------------------------------------------------------------
+   nn_ice_alb  =    0      !  parameterization of ice/snow albedo
+                           !     0: Shine & Henderson-Sellers (JGR 1985)
+                           !     1: "home made" based on Brandt et al. (J. Climate 2005)
+                           !                         and Grenfell & Perovich (JGR 2004)
+   rn_albice   =  0.53     !  albedo of bare puddled ice (values from 0.49 to 0.58)
+                           !     0.53 (default) => if nn_ice_alb=0
+                           !     0.50 (default) => if nn_ice_alb=1
+/
+!-----------------------------------------------------------------------
+&namsbc_wave   ! External fields from wave model                        (ln_wave=T)
+!-----------------------------------------------------------------------
+!              ! file name ! frequency (hours) ! variable    ! time interp.!  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !           !  (if <0  months)  !   name      !  (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_cdg      = 'cdg_wave',        1          , 'drag_coeff',   .true.    , .false., 'daily'   ,    ''      , ''       , ''
+   sn_usd      = 'sdw_wave',        1          , 'u_sd2d'    ,   .true.    , .false., 'daily'   ,    ''      , ''       , ''
+   sn_vsd      = 'sdw_wave',        1          , 'v_sd2d'    ,   .true.    , .false., 'daily'   ,    ''      , ''       , ''
+   sn_wn       = 'sdw_wave',        1          , 'wave_num'  ,   .true.    , .false., 'daily'   ,    ''      , ''       , ''
+!
+   cn_dir_cdg  = './'      !  root directory for the location of drag coefficient files
+   ln_cdgw     = .false.   !  Neutral drag coefficient read from wave model
+   ln_sdw      = .false.   !  Computation of 3D stokes drift               
+/
+!-----------------------------------------------------------------------
+&namberg       !   iceberg parameters                                   (default: No iceberg)
+!-----------------------------------------------------------------------
+      ln_icebergs              = .false.              ! iceberg floats or not
+      ln_bergdia               = .true.               ! Calculate budgets
+      nn_verbose_level         = 1                    ! Turn on more verbose output if level > 0
+      nn_verbose_write         = 15                   ! Timesteps between verbose messages
+      nn_sample_rate           = 1                    ! Timesteps between sampling for trajectory storage
+                                                      ! Initial mass required for an iceberg of each class
+      rn_initial_mass          = 8.8e7, 4.1e8, 3.3e9, 1.8e10, 3.8e10, 7.5e10, 1.2e11, 2.2e11, 3.9e11, 7.4e11
+                                                      ! Proportion of calving mass to apportion to each class
+      rn_distribution          = 0.24, 0.12, 0.15, 0.18, 0.12, 0.07, 0.03, 0.03, 0.03, 0.02
+                                                      ! Ratio between effective and real iceberg mass (non-dim)
+                                                      ! i.e. number of icebergs represented at a point
+      rn_mass_scaling          = 2000, 200, 50, 20, 10, 5, 2, 1, 1, 1
+                                                      ! thickness of newly calved bergs (m)
+      rn_initial_thickness     = 40., 67., 133., 175., 250., 250., 250., 250., 250., 250.
+      rn_rho_bergs             = 850.                 ! Density of icebergs
+      rn_LoW_ratio             = 1.5                  ! Initial ratio L/W for newly calved icebergs
+      ln_operator_splitting    = .true.               ! Use first order operator splitting for thermodynamics
+      rn_bits_erosion_fraction = 0.                   ! Fraction of erosion melt flux to divert to bergy bits
+      rn_sicn_shift            = 0.                   ! Shift of sea-ice concn in erosion flux (0<sicn_shift<1)
+      ln_passive_mode          = .false.              ! iceberg - ocean decoupling
+      nn_test_icebergs         =  10                  ! Create test icebergs of this class (-1 = no)
+                                                      ! Put a test iceberg at each gridpoint in box (lon1,lon2,lat1,lat2)
+      rn_test_box              = 108.0,  116.0, -66.0, -58.0
+      rn_speed_limit           = 0.                   ! CFL speed limit for a berg
+
+!            ! file name ! frequency (hours) !   variable   ! time interp.!  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!            !           !  (if <0  months)  !     name     !  (logical)  !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+      sn_icb =  'calving',       -1          , 'calvingmask',   .true.    , .true.  , 'yearly'  ,    ''    ,    ''    ,     ''
+
+      cn_dir = './'
+/
+
+!!======================================================================
+!!               ***  Lateral boundary condition  ***
+!!======================================================================
+!!   namlbc        lateral momentum boundary condition
+!!   namagrif      agrif nested grid ( read by child model only )       ("key_agrif")
+!!   nam_tide      Tidal forcing 
+!!   nambdy        Unstructured open boundaries                         ("key_bdy")
+!!   nambdy_dta    Unstructured open boundaries - external data         ("key_bdy")
+!!   nambdy_tide   tidal forcing at open boundaries                     ("key_bdy_tides")
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namlbc        !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+   !                       !  free slip  !   partial slip  !   no slip   ! strong slip
+   rn_shlat    =    2.     !  shlat = 0  !  0 < shlat < 2  !  shlat = 2  !  2 < shlat
+   ln_vorlat   = .false.   !  consistency of vorticity boundary condition with analytical Eqs.
+/
+!-----------------------------------------------------------------------
+&namagrif      !  AGRIF zoom                                            ("key_agrif")
+!-----------------------------------------------------------------------
+   nn_cln_update =    3    !  baroclinic update frequency
+   ln_spc_dyn    = .true.  !  use 0 as special value for dynamics
+   rn_sponge_tra = 2880.   !  coefficient for tracer   sponge layer [m2/s]
+   rn_sponge_dyn = 2880.   !  coefficient for dynamics sponge layer [m2/s]
+   ln_chk_bathy  = .FALSE. !
+/
+!-----------------------------------------------------------------------
+&nam_tide      !   tide parameters                                      ("key_tide")
+!-----------------------------------------------------------------------
+   ln_tide_pot = .true.    !  use tidal potential forcing
+   ln_tide_ramp= .false.   !
+   rdttideramp =    0.     !
+   clname(1)   = 'DUMMY'   !  name of constituent - all tidal components must be set in namelist_cfg
+/
+!-----------------------------------------------------------------------
+&nambdy        !  unstructured open boundaries                          ("key_bdy")
+!-----------------------------------------------------------------------
+    nb_bdy         = 0                    !  number of open boundary sets
+    ln_coords_file = .true.               !  =T : read bdy coordinates from file
+    cn_coords_file = 'coordinates.bdy.nc' !  bdy coordinates files
+    ln_mask_file   = .false.              !  =T : read mask from file
+    cn_mask_file   = ''                   !  name of mask file (if ln_mask_file=.TRUE.)
+    cn_dyn2d       = 'none'               !
+    nn_dyn2d_dta   =  0                   !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+                                          !  = 2, use tidal harmonic forcing data from files
+                                          !  = 3, use external data AND tidal harmonic forcing
+    cn_dyn3d      =  'none'               !
+    nn_dyn3d_dta  =  0                    !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    cn_tra        =  'none'               !
+    nn_tra_dta    =  0                    !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    cn_ice_lim      =  'none'             !
+    nn_ice_lim_dta  =  0                  !  = 0, bdy data are equal to the initial state
+                                          !  = 1, bdy data are read in 'bdydata   .nc' files
+    rn_ice_tem      = 270.                !  lim3 only: arbitrary temperature of incoming sea ice
+    rn_ice_sal      = 10.                 !  lim3 only:      --   salinity           --
+    rn_ice_age      = 30.                 !  lim3 only:      --   age                --
+
+    ln_tra_dmp    =.false.                !  open boudaries conditions for tracers
+    ln_dyn3d_dmp  =.false.                !  open boundary condition for baroclinic velocities
+    rn_time_dmp   =  1.                   ! Damping time scale in days
+    rn_time_dmp_out =  1.                 ! Outflow damping time scale
+    nn_rimwidth   = 10                    !  width of the relaxation zone
+    ln_vol        = .false.               !  total volume correction (see nn_volctl parameter)
+    nn_volctl     = 1                     !  = 0, the total water flux across open boundaries is zero
+/
+!-----------------------------------------------------------------------
+&nambdy_dta    !  open boundaries - external data                       ("key_bdy")
+!-----------------------------------------------------------------------
+!              !  file name      ! frequency (hours) ! variable  ! time interp.!  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                 !  (if <0  months)  !   name    !  (logical)  !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+   bn_ssh      = 'amm12_bdyT_u2d',         24        , 'sossheig',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+   bn_u2d      = 'amm12_bdyU_u2d',         24        , 'vobtcrtx',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+   bn_v2d      = 'amm12_bdyV_u2d',         24        , 'vobtcrty',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+   bn_u3d      = 'amm12_bdyU_u3d',         24        , 'vozocrtx',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+   bn_v3d      = 'amm12_bdyV_u3d',         24        , 'vomecrty',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+   bn_tem      = 'amm12_bdyT_tra',         24        , 'votemper',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+   bn_sal      = 'amm12_bdyT_tra',         24        , 'vosaline',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+! for lim2
+!   bn_frld    = 'amm12_bdyT_ice',         24        , 'ileadfra',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+!   bn_hicif   = 'amm12_bdyT_ice',         24        , 'iicethic',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+!   bn_hsnif   = 'amm12_bdyT_ice',         24        , 'isnowthi',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+! for lim3
+!   bn_a_i     = 'amm12_bdyT_ice',         24        , 'ileadfra',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+!   bn_ht_i    = 'amm12_bdyT_ice',         24        , 'iicethic',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+!   bn_ht_s    = 'amm12_bdyT_ice',         24        , 'isnowthi',    .true.   , .false. ,  'daily'  ,    ''    ,   ''     ,     ''
+
+   cn_dir      = 'bdydta/' !  root directory for the location of the bulk files
+   ln_full_vel = .false.   !  
+/
+!-----------------------------------------------------------------------
+&nambdy_tide   !  tidal forcing at open boundaries
+!-----------------------------------------------------------------------
+   filtide          = 'bdydta/amm12_bdytide_'   !  file name root of tidal forcing files
+   ln_bdytide_2ddta = .false.                   !
+   ln_bdytide_conj  = .false.                   ! 
+/
+
+!!======================================================================
+!!                 ***  Bottom boundary condition  ***
+!!======================================================================
+!!   nambfr        bottom friction
+!!   nambbc        bottom temperature boundary condition
+!!   nambbl        bottom boundary layer scheme                         ("key_trabbl")
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&nambfr        !   bottom friction                                      (default: linear)
+!-----------------------------------------------------------------------
+   nn_bfr      =    1      !  type of bottom friction :   = 0 : free slip,  = 1 : linear friction
+                           !                              = 2 : nonlinear friction
+   rn_bfri1    =    4.e-4  !  bottom drag coefficient (linear case)
+   rn_bfri2    =    1.e-3  !  bottom drag coefficient (non linear case). Minimum coeft if ln_loglayer=T
+   rn_bfri2_max=    1.e-1  !  max. bottom drag coefficient (non linear case and ln_loglayer=T)
+   rn_bfeb2    =    2.5e-3 !  bottom turbulent kinetic energy background  (m2/s2)
+   rn_bfrz0    =    3.e-3  !  bottom roughness [m] if ln_loglayer=T
+   ln_bfr2d    = .false.   !  horizontal variation of the bottom friction coef (read a 2D mask file )
+   rn_bfrien   =    50.    !  local multiplying factor of bfr (ln_bfr2d=T)
+   rn_tfri1    =    4.e-4  !  top drag coefficient (linear case)
+   rn_tfri2    =    2.5e-3 !  top drag coefficient (non linear case). Minimum coeft if ln_loglayer=T
+   rn_tfri2_max=    1.e-1  !  max. top drag coefficient (non linear case and ln_loglayer=T)
+   rn_tfeb2    =    0.0    !  top turbulent kinetic energy background  (m2/s2)
+   rn_tfrz0    =    3.e-3  !  top roughness [m] if ln_loglayer=T
+   ln_tfr2d    = .false.   !  horizontal variation of the top friction coef (read a 2D mask file )
+   rn_tfrien   =   50.     !  local multiplying factor of tfr (ln_tfr2d=T)
+
+   ln_bfrimp   = .true.    !  implicit bottom friction (requires ln_zdfexp = .false. if true)
+   ln_loglayer = .false.   !  logarithmic formulation (non linear case)
+/
+!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition                (default: NO)
+!-----------------------------------------------------------------------
+!              !  file name      ! frequency (hours) ! variable  ! time interp.!  clim   ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                 !  (if <0  months)  !   name    !  (logical)  !  (T/F ) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_qgh      ='geothermal_heating.nc',  -12.       , 'heatflow',   .false.   , .true.  , 'yearly'  ,   ''     ,   ''     ,   ''
+   !
+   ln_trabbc   = .false.   !  Apply a geothermal heating at the ocean bottom
+   nn_geoflx   =    2      !  geothermal heat flux: = 0 no flux
+                           !     = 1 constant flux
+                           !     = 2 variable flux (read in geothermal_heating.nc in mW/m2)
+   rn_geoflx_cst = 86.4e-3 !  Constant value of geothermal heat flux [W/m2]
+   cn_dir      = './'      !  root directory for the location of the runoff files 
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme                         ("key_trabbl")
+!-----------------------------------------------------------------------
+   nn_bbl_ldf  =  1        !  diffusive bbl (=1)   or not (=0)
+   nn_bbl_adv  =  0        !  advective bbl (=1/2) or not (=0)
+   rn_ahtbbl   =  1000.    !  lateral mixing coefficient in the bbl  [m2/s]
+   rn_gambbl   =  10.      !  advective bbl coefficient                 [s]
+/
+
+!!======================================================================
+!!                        Tracer (T & S ) namelists
+!!======================================================================
+!!   nameos           equation of state
+!!   namtra_adv       advection scheme
+!!   namtra_adv_mle   mixed layer eddy param. (Fox-Kemper param.)
+!!   namtra_ldf       lateral diffusion scheme
+!!   namtra_ldfeiv    eddy induced velocity param.
+!!   namtra_dmp       T & S newtonian damping
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&nameos        !   ocean physical parameters
+!-----------------------------------------------------------------------
+   ln_teos10   = .false.         !  = Use TEOS-10 equation of state
+   ln_eos80    = .false.         !  = Use EOS80 equation of state
+   ln_seos     = .false.         !  = Use simplified equation of state (S-EOS)
+                                 !
+   !                     ! S-EOS coefficients (ln_seos=T):
+   !                             !  rd(T,S,Z)*rau0 = -a0*(1+.5*lambda*dT+mu*Z+nu*dS)*dT+b0*dS
+   rn_a0       =  1.6550e-1      !  thermal expension coefficient (nn_eos= 1)
+   rn_b0       =  7.6554e-1      !  saline  expension coefficient (nn_eos= 1)
+   rn_lambda1  =  5.9520e-2      !  cabbeling coeff in T^2  (=0 for linear eos)
+   rn_lambda2  =  7.4914e-4      !  cabbeling coeff in S^2  (=0 for linear eos)
+   rn_mu1      =  1.4970e-4      !  thermobaric coeff. in T (=0 for linear eos)
+   rn_mu2      =  1.1090e-5      !  thermobaric coeff. in S (=0 for linear eos)
+   rn_nu       =  2.4341e-3      !  cabbeling coeff in T*S  (=0 for linear eos)
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer                          (default: NO advection)
+!-----------------------------------------------------------------------
+   ln_traadv_cen = .false. !  2nd order centered scheme
+      nn_cen_h   =  4            !  =2/4, horizontal 2nd order CEN / 4th order CEN
+      nn_cen_v   =  4            !  =2/4, vertical   2nd order CEN / 4th order COMPACT
+   ln_traadv_fct = .false. !  FCT scheme
+      nn_fct_h   =  2            !  =2/4, horizontal 2nd / 4th order 
+      nn_fct_v   =  2            !  =2/4, vertical   2nd / COMPACT 4th order 
+      nn_fct_zts =  0            !  >=1,  2nd order FCT scheme with vertical sub-timestepping
+      !                          !        (number of sub-timestep = nn_fct_zts)
+   ln_traadv_mus = .false. !  MUSCL scheme
+      ln_mus_ups = .false.       !  use upstream scheme near river mouths
+   ln_traadv_ubs = .false. !  UBS scheme
+      nn_ubs_v   =  2            !  =2  , vertical 2nd order FCT / COMPACT 4th order
+   ln_traadv_qck = .false. !  QUICKEST scheme
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !   mixed layer eddy parametrisation (Fox-Kemper param) (default: NO)
+!-----------------------------------------------------------------------
+   ln_mle      = .false.   ! (T) use the Mixed Layer Eddy (MLE) parameterisation
+   rn_ce       = 0.06      ! magnitude of the MLE (typical value: 0.06 to 0.08)
+   nn_mle      = 1         ! MLE type: =0 standard Fox-Kemper ; =1 new formulation
+   rn_lf       = 5.e+3     ! typical scale of mixed layer front (meters)                      (case rn_mle=0)
+   rn_time     = 172800.   ! time scale for mixing momentum across the mixed layer (seconds)  (case rn_mle=0)
+   rn_lat      = 20.       ! reference latitude (degrees) of MLE coef.                        (case rn_mle=1)
+   nn_mld_uv   = 0         ! space interpolation of MLD at u- & v-pts (0=min,1=averaged,2=max)
+   nn_conv     = 0         ! =1 no MLE in case of convection ; =0 always MLE
+   rn_rho_c_mle= 0.01      ! delta rho criterion used to calculate MLD for FK
+/
+!-----------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers                 (default: NO diffusion)
+!-----------------------------------------------------------------------
+   !                       !  Operator type:
+   !                           !  no diffusion: set ln_traldf_lap=..._blp=F 
+   ln_traldf_lap   =  .false.  !    laplacian operator
+   ln_traldf_blp   =  .false.  !  bilaplacian operator
+   !
+   !                       !  Direction of action:
+   ln_traldf_lev   =  .false.  !  iso-level
+   ln_traldf_hor   =  .false.  !  horizontal (geopotential)
+   ln_traldf_iso   =  .false.  !  iso-neutral (standard operator)
+   ln_traldf_triad =  .false.  !  iso-neutral (triad    operator)
+   !
+   !		       	         !  iso-neutral options:        
+   ln_traldf_msc   =  .false.  !  Method of Stabilizing Correction (both operators)
+   rn_slpmax       =   0.01    !  slope limit                      (both operators)
+   ln_triad_iso    =  .false.  !  pure horizontal mixing in ML              (triad only)
+   rn_sw_triad     =  1        !  =1 switching triad ; =0 all 4 triads used (triad only)
+   ln_botmix_triad =  .false.  !  lateral mixing on bottom                  (triad only)
+   !
+   !                       !  Coefficients:
+   nn_aht_ijk_t    = 0         !  space/time variation of eddy coef
+   !                                !   =-20 (=-30)    read in eddy_diffusivity_2D.nc (..._3D.nc) file
+   !                                !   =  0           constant 
+   !                                !   = 10 F(k)      =ldf_c1d 
+   !                                !   = 20 F(i,j)    =ldf_c2d 
+   !                                !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
+   !                                !   = 30 F(i,j,k)  =ldf_c2d * ldf_c1d
+   !                                !   = 31 F(i,j,k,t)=F(local velocity and grid-spacing)
+   rn_aht_0        = 2000.     !  lateral eddy diffusivity   (lap. operator) [m2/s]
+   rn_bht_0        = 1.e+12    !  lateral eddy diffusivity (bilap. operator) [m4/s]
+/
+!-----------------------------------------------------------------------
+&namtra_ldfeiv !   eddy induced velocity param.                         (default: NO)
+!-----------------------------------------------------------------------
+   ln_ldfeiv     =.false.  ! use eddy induced velocity parameterization
+   ln_ldfeiv_dia =.false.  ! diagnose eiv stream function and velocities
+   rn_aeiv_0     = 2000.   ! eddy induced velocity coefficient   [m2/s]
+   nn_aei_ijk_t  = 21      ! space/time variation of the eiv coeficient
+   !                                !   =-20 (=-30)    read in eddy_induced_velocity_2D.nc (..._3D.nc) file
+   !                                !   =  0           constant 
+   !                                !   = 10 F(k)      =ldf_c1d 
+   !                                !   = 20 F(i,j)    =ldf_c2d 
+   !                                !   = 21 F(i,j,t)  =Treguier et al. JPO 1997 formulation
+   !                                !   = 30 F(i,j,k)  =ldf_c2d + ldf_c1d
+/
+!-----------------------------------------------------------------------
+&namtra_dmp    !   tracer: T & S newtonian damping                      (default: NO)
+!-----------------------------------------------------------------------
+   ln_tradmp   =  .true.   !  add a damping termn (T) or not (F)
+   nn_zdmp     =    0      !  vertical   shape =0    damping throughout the water column
+                           !                   =1 no damping in the mixing layer (kz  criteria)
+                           !                   =2 no damping in the mixed  layer (rho crieria)
+   cn_resto    ='resto.nc' !  Name of file containing restoration coeff. field (use dmp_tools to create this)
+/
+
+!!======================================================================
+!!                      ***  Dynamics namelists  ***
+!!======================================================================
+!!   namdyn_adv    formulation of the momentum advection
+!!   namdyn_vor    advection scheme
+!!   namdyn_hpg    hydrostatic pressure gradient
+!!   namdyn_spg    surface pressure gradient
+!!   namdyn_ldf    lateral diffusion scheme
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection                (default: vector form)
+!-----------------------------------------------------------------------
+   ln_dynadv_vec = .true.  !  vector form (T) or flux form (F)
+   nn_dynkeg     = 0       ! scheme for grad(KE): =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
+   ln_dynzad_zts = .false. !  Use (T) sub timestepping for vertical momentum advection
+/
+!-----------------------------------------------------------------------
+&nam_vvl    !   vertical coordinate options                             (default: zstar)
+!-----------------------------------------------------------------------
+   ln_vvl_zstar  = .true.           !  zstar vertical coordinate
+   ln_vvl_ztilde = .false.          !  ztilde vertical coordinate: only high frequency variations
+   ln_vvl_layer  = .false.          !  full layer vertical coordinate
+   ln_vvl_ztilde_as_zstar = .false. !  ztilde vertical coordinate emulating zstar
+   ln_vvl_zstar_at_eqtor  = .false. !  ztilde near the equator
+   rn_ahe3       = 0.0e0            !  thickness diffusion coefficient
+   rn_rst_e3t    = 30.e0            !  ztilde to zstar restoration timescale [days]
+   rn_lf_cutoff  = 5.0e0            !  cutoff frequency for low-pass filter  [days]
+   rn_zdef_max   = 0.9e0            !  maximum fractional e3t deformation
+   ln_vvl_dbg    = .true.           !  debug prints    (T/F)
+/
+!-----------------------------------------------------------------------
+&namdyn_vor    !   Vorticity / Coriolis scheme                          (default: NO)
+!-----------------------------------------------------------------------
+   ln_dynvor_ene = .false. !  enstrophy conserving scheme
+   ln_dynvor_ens = .false. !  energy conserving scheme
+   ln_dynvor_mix = .false. !  mixed scheme
+   ln_dynvor_een = .false. !  energy & enstrophy scheme
+      nn_een_e3f = 1          ! e3f = masked averaging of e3t divided by 4 (=0) or by the sum of mask (=1)
+   ln_dynvor_msk = .false. !  vorticity multiplied by fmask (=T) or not (=F) (all vorticity schemes)  ! PLEASE DO NOT ACTIVATE
+/
+!-----------------------------------------------------------------------
+&namdyn_hpg    !   Hydrostatic pressure gradient option                 (default: zps)
+!-----------------------------------------------------------------------
+   ln_hpg_zco  = .false.   !  z-coordinate - full steps
+   ln_hpg_zps  = .true.    !  z-coordinate - partial steps (interpolation)
+   ln_hpg_sco  = .false.   !  s-coordinate (standard jacobian formulation)
+   ln_hpg_isf  = .false.   !  s-coordinate (sco ) adapted to isf
+   ln_hpg_djc  = .false.   !  s-coordinate (Density Jacobian with Cubic polynomial)
+   ln_hpg_prj  = .false.   !  s-coordinate (Pressure Jacobian scheme)
+/
+!-----------------------------------------------------------------------
+&namdyn_spg    !   surface pressure gradient                            (default: NO)
+!-----------------------------------------------------------------------
+   ln_dynspg_exp  = .false.   ! explicit free surface
+   ln_dynspg_ts   = .false.   ! split-explicit free surface
+      ln_bt_fw      = .true.     ! Forward integration of barotropic Eqs.
+      ln_bt_av      = .true.     ! Time filtering of barotropic variables
+         nn_bt_flt     = 1          ! Time filter choice  = 0 None
+         !                          !                     = 1 Boxcar over   nn_baro sub-steps
+         !                          !                     = 2 Boxcar over 2*nn_baro  "    "
+      ln_bt_auto    = .true.     ! Number of sub-step defined from:
+         rn_bt_cmax   =  0.8        ! =T : the Maximum Courant Number allowed
+         nn_baro      = 30          ! =F : the number of sub-step in rn_rdt seconds
+/
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum                        (default: NO)
+!-----------------------------------------------------------------------
+   !                       !  Type of the operator :
+   !                           !  no diffusion: set ln_dynldf_lap=..._blp=F 
+   ln_dynldf_lap =  .false.    !    laplacian operator
+   ln_dynldf_blp =  .false.    !  bilaplacian operator
+   !                       !  Direction of action  :
+   ln_dynldf_lev =  .false.    !  iso-level
+   ln_dynldf_hor =  .false.    !  horizontal (geopotential)
+   ln_dynldf_iso =  .false.    !  iso-neutral
+   !                       !  Coefficient
+   nn_ahm_ijk_t  = 0           !  space/time variation of eddy coef
+   !                                !  =-30  read in eddy_viscosity_3D.nc file
+   !                                !  =-20  read in eddy_viscosity_2D.nc file
+   !                                !  =  0  constant 
+   !                                !  = 10  F(k)=c1d
+   !                                !  = 20  F(i,j)=F(grid spacing)=c2d
+   !                                !  = 30  F(i,j,k)=c2d*c1d
+   !                                !  = 31  F(i,j,k)=F(grid spacing and local velocity)
+   rn_ahm_0      =  40000.     !  horizontal laplacian eddy viscosity   [m2/s]
+   rn_ahm_b      =      0.     !  background eddy viscosity for ldf_iso [m2/s]
+   rn_bhm_0      = 1.e+12      !  horizontal bilaplacian eddy viscosity [m4/s]
+   !
+   ! Caution in 20 and 30 cases the coefficient have to be given for a 1 degree grid (~111km)
+/
+
+!!======================================================================
+!!             Tracers & Dynamics vertical physics namelists
+!!======================================================================
+!!    namzdf        vertical physics
+!!    namzdf_ric    richardson number dependent vertical mixing         ("key_zdfric")
+!!    namzdf_tke    TKE dependent vertical mixing                       ("key_zdftke")
+!!    namzdf_gls    GLS vertical mixing                                 ("key_zdfgls")
+!!    namzdf_ddm    double diffusive mixing parameterization            ("key_zdfddm")
+!!    namzdf_tmx    tidal mixing parameterization                       ("key_zdftmx")
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics
+!-----------------------------------------------------------------------
+   rn_avm0     =   1.2e-4  !  vertical eddy viscosity   [m2/s]          (background Kz if not "key_zdfcst")
+   rn_avt0     =   1.2e-5  !  vertical eddy diffusivity [m2/s]          (background Kz if not "key_zdfcst")
+   nn_avb      =    0      !  profile for background avt & avm (=1) or not (=0)
+   nn_havtb    =    0      !  horizontal shape for avtb (=1) or not (=0)
+   ln_zdfevd   = .true.    !  enhanced vertical diffusion (evd) (T) or not (F)
+      nn_evdm     =    0        ! evd apply on tracer (=0) or on tracer and momentum (=1)
+      rn_avevd    =  100.       !  evd mixing coefficient [m2/s]
+   ln_zdfnpc   = .false.   !  Non-Penetrative Convective algorithm (T) or not (F)
+      nn_npc      =    1        ! frequency of application of npc
+      nn_npcp     =  365        ! npc control print frequency
+   ln_zdfexp   = .false.   !  time-stepping: split-explicit (T) or implicit (F) time stepping
+      nn_zdfexp   =    3        ! number of sub-timestep for ln_zdfexp=T
+/
+!-----------------------------------------------------------------------
+&namzdf_ric    !   richardson number dependent vertical diffusion       ("key_zdfric" )
+!-----------------------------------------------------------------------
+   rn_avmri    =  100.e-4  !  maximum value of the vertical viscosity
+   rn_alp      =    5.     !  coefficient of the parameterization
+   nn_ric      =    2      !  coefficient of the parameterization
+   rn_ekmfc    =    0.7    !  Factor in the Ekman depth Equation
+   rn_mldmin   =    1.0    !  minimum allowable mixed-layer depth estimate (m)
+   rn_mldmax   = 1000.0    !  maximum allowable mixed-layer depth estimate (m)
+   rn_wtmix    =   10.0    !  vertical eddy viscosity coeff [m2/s] in the mixed-layer
+   rn_wvmix    =   10.0    !  vertical eddy diffusion coeff [m2/s] in the mixed-layer
+   ln_mldw     =  .true.   !  Flag to use or not the mixed layer depth param.
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+!-----------------------------------------------------------------------
+   rn_ediff    =   0.1     !  coef. for vertical eddy coef. (avt=rn_ediff*mxl*sqrt(e) )
+   rn_ediss    =   0.7     !  coef. of the Kolmogoroff dissipation
+   rn_ebb      =  67.83    !  coef. of the surface input of tke (=67.83 suggested when ln_mxl0=T)
+   rn_emin     =   1.e-6   !  minimum value of tke [m2/s2]
+   rn_emin0    =   1.e-4   !  surface minimum value of tke [m2/s2]
+   rn_bshear   =   1.e-20  ! background shear (>0) currently a numerical threshold (do not change it)
+   nn_mxl      =   2       !  mixing length: = 0 bounded by the distance to surface and bottom
+                           !                 = 1 bounded by the local vertical scale factor
+                           !                 = 2 first vertical derivative of mixing length bounded by 1
+                           !                 = 3 as =2 with distinct disspipative an mixing length scale
+   nn_pdl      =   1       !  Prandtl number function of richarson number (=1, avt=pdl(Ri)*avm) or not (=0, avt=avm)
+   ln_mxl0     = .true.    !  surface mixing length scale = F(wind stress) (T) or not (F)
+   rn_mxl0     =   0.04    !  surface  buoyancy lenght scale minimum value
+   ln_lc       = .true.    !  Langmuir cell parameterisation (Axell 2002)
+   rn_lc       =   0.15    !  coef. associated to Langmuir cells
+   nn_etau     =   1       !  penetration of tke below the mixed layer (ML) due to near intertial waves
+                           !        = 0 no penetration
+                           !        = 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
+/
+!-----------------------------------------------------------------------
+&namzdf_gls    !   GLS vertical diffusion                               ("key_zdfgls")
+!-----------------------------------------------------------------------
+   rn_emin       = 1.e-7   !  minimum value of e   [m2/s2]
+   rn_epsmin     = 1.e-12  !  minimum value of eps [m2/s3]
+   ln_length_lim = .true.  !  limit on the dissipation rate under stable stratification (Galperin et al., 1988)
+   rn_clim_galp  = 0.267   !  galperin limit
+   ln_sigpsi     = .true.  !  Activate or not Burchard 2001 mods on psi schmidt number in the wb case
+   rn_crban      = 100.    !  Craig and Banner 1994 constant for wb tke flux
+   rn_charn      = 70000.  !  Charnock constant for wb induced roughness length
+   rn_hsro       =  0.02   !  Minimum surface roughness
+   rn_frac_hs    =   1.3   !  Fraction of wave height as roughness (if nn_z0_met=2)
+   nn_z0_met     =     2   !  Method for surface roughness computation (0/1/2)
+   nn_bc_surf    =     1   !  surface condition (0/1=Dir/Neum)
+   nn_bc_bot     =     1   !  bottom condition (0/1=Dir/Neum)
+   nn_stab_func  =     2   !  stability function (0=Galp, 1= KC94, 2=CanutoA, 3=CanutoB)
+   nn_clos       =     1   !  predefined closure type (0=MY82, 1=k-eps, 2=k-w, 3=Gen)
+/
+!-----------------------------------------------------------------------
+&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
+!-----------------------------------------------------------------------
+   rn_avts     = 1.e-4     !  maximum avs (vertical mixing on salinity)
+   rn_hsbfr    = 1.6       !  heat/salt buoyancy flux ratio
+/
+!-----------------------------------------------------------------------
+&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
+!-----------------------------------------------------------------------
+   rn_htmx     = 500.      !  vertical decay scale for turbulence (meters)
+   rn_n2min    = 1.e-8     !  threshold of the Brunt-Vaisala frequency (s-1)
+   rn_tfe      = 0.333     !  tidal dissipation efficiency
+   rn_me       = 0.2       !  mixing efficiency
+   ln_tmx_itf  = .true.    !  ITF specific parameterisation
+   rn_tfe_itf  = 1.        !  ITF tidal dissipation efficiency
+/
+!-----------------------------------------------------------------------
+&namzdf_tmx_new !   internal wave-driven mixing parameterization        ("key_zdftmx_new" & "key_zdfddm")
+!-----------------------------------------------------------------------
+   nn_zpyc     = 1         !  pycnocline-intensified dissipation scales as N (=1) or N^2 (=2)
+   ln_mevar    = .true.    !  variable (T) or constant (F) mixing efficiency
+   ln_tsdiff   = .true.    !  account for differential T/S mixing (T) or not (F)
+/
+
+
+!!======================================================================
+!!                  ***  Miscellaneous namelists  ***
+!!======================================================================
+!!   nammpp            Massively Parallel Processing                    ("key_mpp_mpi)
+!!   namctl            Control prints & Benchmark
+!!   namsto            Stochastic parametrization of EOS
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
+!-----------------------------------------------------------------------
+   cn_mpi_send =  'I'      !  mpi send/recieve type   ='S', 'B', or 'I' for standard send,
+                           !  buffer blocking send or immediate non-blocking sends, resp.
+   nn_buffer   =   0       !  size in bytes of exported buffer ('B' case), 0 no exportation
+   ln_nnogather=  .false.  !  activate code to avoid mpi_allgather use at the northfold
+   jpni        =   0       !  jpni   number of processors following i (set automatically if < 1)
+   jpnj        =   0       !  jpnj   number of processors following j (set automatically if < 1)
+   jpnij       =   0       !  jpnij  number of local domains (set automatically if < 1)
+/
+!-----------------------------------------------------------------------
+&namctl        !   Control prints & Benchmark
+!-----------------------------------------------------------------------
+   ln_ctl      = .false.   !  trends control print (expensive!)
+   nn_print    =    0      !  level of print (0 no extra print)
+   nn_ictls    =    0      !  start i indice of control sum (use to compare mono versus
+   nn_ictle    =    0      !  end   i indice of control sum        multi processor runs
+   nn_jctls    =    0      !  start j indice of control               over a subdomain)
+   nn_jctle    =    0      !  end   j indice of control
+   nn_isplt    =    1      !  number of processors in i-direction
+   nn_jsplt    =    1      !  number of processors in j-direction
+   nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
+                           !     (no physical validity of the results)
+   nn_timing   =    0      !  timing by routine activated (=1) creates timing.output file, or not (=0)
+   nn_diacfl   =    0      !  Write out CFL diagnostics (=1) in cfl_diagnostics.ascii, or not (=0)
+/
+!-----------------------------------------------------------------------
+&namsto        ! Stochastic parametrization of EOS                      (default: NO)
+!-----------------------------------------------------------------------
+   ln_sto_eos  = .false.   ! stochastic equation of state
+   nn_sto_eos  = 1         ! number of independent random walks
+   rn_eos_stdxy= 1.4       ! random walk horz. standard deviation (in grid points)
+   rn_eos_stdz = 0.7       ! random walk vert. standard deviation (in grid points)
+   rn_eos_tcor = 1440.     ! random walk time correlation (in timesteps)
+   nn_eos_ord  = 1         ! order of autoregressive processes
+   nn_eos_flt  = 0         ! passes of Laplacian filter
+   rn_eos_lim  = 2.0       ! limitation factor (default = 3.0)
+   ln_rststo   = .false.   ! start from mean parameter (F) or from restart file (T)
+   ln_rstseed  = .true.    ! read seed of RNG from restart file
+   cn_storst_in  = "restart_sto" !  suffix of stochastic parameter restart file (input)
+   cn_storst_out = "restart_sto" !  suffix of stochastic parameter restart file (output)
+/
+
+!!======================================================================
+!!                  ***  Diagnostics namelists  ***
+!!======================================================================
+!!   namtrd       dynamics and/or tracer trends                         (default F)
+!!   namptr       Poleward Transport Diagnostics                        (default F)
+!!   namhsb       Heat and salt budgets                                 (default F)
+!!   namdiu       Cool skin and warm layer models                       (default F)
+!!   namflo       float parameters                                      ("key_float")
+!!   nam_diaharm  Harmonic analysis of tidal constituents               ("key_diaharm")
+!!   namdct       transports through some sections                      ("key_diadct")
+!!   nam_dia25h   25h Mean Output                                       (default F)
+!!   namnc4       netcdf4 chunking and compression settings             ("key_netcdf4")
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namtrd        !   trend diagnostics                                    (default F)
+!-----------------------------------------------------------------------
+   ln_glo_trd  = .false.   ! (T) global domain averaged diag for T, T^2, KE, and PE
+   ln_dyn_trd  = .false.   ! (T) 3D momentum trend output
+   ln_dyn_mxl  = .false.   ! (T) 2D momentum trends averaged over the mixed layer (not coded yet)
+   ln_vor_trd  = .false.   ! (T) 2D barotropic vorticity trends (not coded yet)
+   ln_KE_trd   = .false.   ! (T) 3D Kinetic   Energy     trends
+   ln_PE_trd   = .false.   ! (T) 3D Potential Energy     trends
+   ln_tra_trd  = .false.   ! (T) 3D tracer trend output
+   ln_tra_mxl  = .false.   ! (T) 2D tracer trends averaged over the mixed layer (not coded yet)
+   nn_trd      = 365       !  print frequency (ln_glo_trd=T) (unit=time step)
+/
+!!gm   nn_ctls     =   0       !  control surface type in mixed-layer trends (0,1 or n<jpk)
+!!gm   rn_ucf      =   1.      !  unit conversion factor (=1 -> /seconds ; =86400. -> /day)
+!!gm   cn_trdrst_in      = "restart_mld"   ! suffix of ocean restart name (input)
+!!gm   cn_trdrst_out     = "restart_mld"   ! suffix of ocean restart name (output)
+!!gm   ln_trdmld_restart = .false.         !  restart for ML diagnostics
+!!gm   ln_trdmld_instant = .false.         !  flag to diagnose trends of instantantaneous or mean ML T/S
+!!gm
+!-----------------------------------------------------------------------
+&namptr        !   Poleward Transport Diagnostic                         (default F)
+!-----------------------------------------------------------------------
+   ln_diaptr   = .false.   !  Poleward heat and salt transport (T) or not (F)
+   ln_subbas   = .false.   !  Atlantic/Pacific/Indian basins computation (T) or not
+/
+!-----------------------------------------------------------------------
+&namhsb        !  Heat and salt budgets                                  (default F)
+!-----------------------------------------------------------------------
+   ln_diahsb   = .false.   !  check the heat and salt budgets (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namdiu        !   Cool skin and warm layer models                       (default F)
+!-----------------------------------------------------------------------
+   ln_diurnal      = .false.   ! 
+   ln_diurnal_only = .false.   !
+/
+!-----------------------------------------------------------------------
+&namflo        !   float parameters                                      ("key_float")
+!-----------------------------------------------------------------------
+   jpnfl       = 1         !  total number of floats during the run
+   jpnnewflo   = 0         !  number of floats for the restart
+   ln_rstflo   = .false.   !  float restart (T) or not (F)
+   nn_writefl  =      75   !  frequency of writing in float output file
+   nn_stockfl  =    5475   !  frequency of creation of the float restart file
+   ln_argo     = .false.   !  Argo type floats (stay at the surface each 10 days)
+   ln_flork4   = .false.   !  trajectories computed with a 4th order Runge-Kutta (T)
+   !                       !  or computed with Blanke' scheme (F)
+   ln_ariane   = .true.    !  Input with Ariane tool convention(T)
+   ln_flo_ascii= .true.    !  Output with Ariane tool netcdf convention(F) or ascii file (T)
+/
+!-----------------------------------------------------------------------
+&nam_diaharm   !   Harmonic analysis of tidal constituents               ("key_diaharm")
+!-----------------------------------------------------------------------
+    nit000_han = 1         ! First time step used for harmonic analysis
+    nitend_han = 75        ! Last time step used for harmonic analysis
+    nstep_han  = 15        ! Time step frequency for harmonic analysis
+    tname(1)   = 'M2'      ! Name of tidal constituents
+    tname(2)   = 'K1'
+/
+!-----------------------------------------------------------------------
+&namdct        ! transports through some sections                        ("key_diadct")
+!-----------------------------------------------------------------------
+    nn_dct     = 15        !  time step frequency for transports computing
+    nn_dctwri  = 15        !  time step frequency for transports writing
+    nn_secdebug= 112       !      0 : no section to debug
+    !                      !     -1 : debug all section
+    !                      !  0 < n : debug section number n
+/
+!-----------------------------------------------------------------------
+&nam_dia25h    !  25h Mean Output                                        (default F)
+!-----------------------------------------------------------------------
+   ln_dia25h   = .false.   ! Choose 25h mean output or not
+/
+!-----------------------------------------------------------------------
+&namnc4        !   netcdf4 chunking and compression settings             ("key_netcdf4")
+!-----------------------------------------------------------------------
+   nn_nchunks_i=   4       !  number of chunks in i-dimension
+   nn_nchunks_j=   4       !  number of chunks in j-dimension
+   nn_nchunks_k=   31      !  number of chunks in k-dimension
+   !                       !  setting nn_nchunks_k = jpk will give a chunk size of 1 in the vertical which
+   !                       !  is optimal for postprocessing which works exclusively with horizontal slabs
+   ln_nc4zip   = .true.    !  (T) use netcdf4 chunking and compression
+   !                       !  (F) ignore chunking information and produce netcdf3-compatible files
+/
+
+!!======================================================================
+!!               ***  Observation & Assimilation  ***
+!!======================================================================
+!!   namobs       observation and model comparison
+!!   nam_asminc   assimilation increments                               ('key_asminc')
+!!======================================================================
+!
+!-----------------------------------------------------------------------
+&namobs        !  observation usage switch
+!-----------------------------------------------------------------------
+   ln_diaobs   = .false.             ! Logical switch for the observation operator
+   ln_t3d      = .false.             ! Logical switch for T profile observations
+   ln_s3d      = .false.             ! Logical switch for S profile observations
+   ln_sla      = .false.             ! Logical switch for SLA observations
+   ln_sst      = .false.             ! Logical switch for SST observations
+   ln_sic      = .false.             ! Logical switch for Sea Ice observations
+   ln_vel3d    = .false.             ! Logical switch for velocity observations
+   ln_altbias  = .false.             ! Logical switch for altimeter bias correction
+   ln_nea      = .false.             ! Logical switch for rejection of observations near land
+   ln_grid_global = .true.           ! Logical switch for global distribution of observations
+   ln_grid_search_lookup = .false.   ! Logical switch for obs grid search w/lookup table
+   ln_ignmis   = .true.              ! Logical switch for ignoring missing files
+   ln_s_at_t   = .false.             ! Logical switch for computing model S at T obs if not there
+   ln_sstnight = .false.             ! Logical switch for calculating night-time average for SST obs
+! All of the *files* variables below are arrays. Use namelist_cfg to add more files
+   cn_profbfiles = 'profiles_01.nc'  ! Profile feedback input observation file names
+   cn_slafbfiles = 'sla_01.nc'       ! SLA feedback input observation file names
+   cn_sstfbfiles = 'sst_01.nc'       ! SST feedback input observation file names
+   cn_sicfbfiles = 'sic_01.nc'       ! SIC feedback input observation file names
+   cn_velfbfiles = 'vel_01.nc'       ! Velocity feedback input observation file names
+   cn_altbiasfile = 'altbias.nc'     ! Altimeter bias input file name
+   cn_gridsearchfile='gridsearch.nc' ! Grid search file name
+   rn_gridsearchres = 0.5            ! Grid search resolution
+   rn_dobsini  = 00010101.000000     ! Initial date in window YYYYMMDD.HHMMSS
+   rn_dobsend  = 00010102.000000     ! Final date in window YYYYMMDD.HHMMSS
+   nn_1dint    = 0                   ! Type of vertical interpolation method
+   nn_2dint    = 0                   ! Type of horizontal interpolation method
+   nn_msshc    = 0                   ! MSSH correction scheme
+   rn_mdtcorr  = 1.61                ! MDT  correction
+   rn_mdtcutoff = 65.0               ! MDT cutoff for computed correction
+   nn_profdavtypes = -1              ! Profile daily average types - array
+   ln_sstbias  = .false.             !
+   cn_sstbias_files = 'sstbias.nc'   !
+/
+!-----------------------------------------------------------------------
+&nam_asminc    !   assimilation increments                              ('key_asminc')
+!-----------------------------------------------------------------------
+    ln_bkgwri  = .false.   !  Logical switch for writing out background state
+    ln_trainc  = .false.   !  Logical switch for applying tracer increments
+    ln_dyninc  = .false.   !  Logical switch for applying velocity increments
+    ln_sshinc  = .false.   !  Logical switch for applying SSH increments
+    ln_asmdin  = .false.   !  Logical switch for Direct Initialization (DI)
+    ln_asmiau  = .false.   !  Logical switch for Incremental Analysis Updating (IAU)
+    nitbkg     = 0         !  Timestep of background in [0,nitend-nit000-1]
+    nitdin     = 0         !  Timestep of background for DI in [0,nitend-nit000-1]
+    nitiaustr  = 1         !  Timestep of start of IAU interval in [0,nitend-nit000-1]
+    nitiaufin  = 15        !  Timestep of end of IAU interval in [0,nitend-nit000-1]
+    niaufn     = 0         !  Type of IAU weighting function
+    ln_salfix  = .false.   !  Logical switch for ensuring that the sa > salfixmin
+    salfixmin  = -9999     !  Minimum salinity after applying the increments
+    nn_divdmp  = 0         !  Number of iterations of divergence damping operator
+/
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/dom_oce.f90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/dom_oce.f90	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/dom_oce.f90	(revision 15121)
@@ -175,4 +175,5 @@
    LOGICAL, PUBLIC ::   ln_zps       !: z-coordinate - partial step
    LOGICAL, PUBLIC ::   ln_sco       !: s-coordinate or hybrid z-s coordinate
+   LOGICAL, PUBLIC ::   ln_mes       !: Multi Enveloped s-coordinate (MEs)
    LOGICAL, PUBLIC ::   ln_isfcav    !: presence of ISF 
    LOGICAL, PUBLIC ::   ln_linssh    !: variable grid flag
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domain.f90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domain.f90	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domain.f90	(revision 15121)
@@ -133,6 +133,6 @@
       ENDIF
       !
-      CALL dom_wri           ! DB create mesh_mask
-      CALL cfg_write         ! create the configuration file
+      IF( nmsh /= 0 ) CALL dom_wri ! DB create mesh_mask
+      CALL cfg_write               ! create the configuration file
       !
       IF( nn_timing == 1 )   CALL timing_stop('dom_init')
@@ -422,7 +422,7 @@
       !
       !                                   ! type of vertical coordinate
-      IF( ln_zco    ) THEN   ;   izco = 1   ;   ELSE   ;   izco = 0   ;   ENDIF
-      IF( ln_zps    ) THEN   ;   izps = 1   ;   ELSE   ;   izps = 0   ;   ENDIF
-      IF( ln_sco    ) THEN   ;   isco = 1   ;   ELSE   ;   isco = 0   ;   ENDIF
+      IF( ln_zco             ) THEN   ;   izco = 1   ;   ELSE   ;   izco = 0   ;   ENDIF
+      IF( ln_zps             ) THEN   ;   izps = 1   ;   ELSE   ;   izps = 0   ;   ENDIF
+      IF( ln_sco .OR. ln_mes ) THEN   ;   isco = 1   ;   ELSE   ;   isco = 0   ;   ENDIF
       CALL iom_rstput( 0, 0, inum, 'ln_zco'   , REAL( izco, wp), ktype = jp_i4 )
       CALL iom_rstput( 0, 0, inum, 'ln_zps'   , REAL( izps, wp), ktype = jp_i4 )
@@ -490,5 +490,5 @@
 
       !
-      IF( ln_sco ) THEN             ! s-coordinate: store grid stiffness ratio  (Not required anyway)
+      IF( ln_sco .OR. ln_mes ) 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
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domwri.f90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domwri.f90	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domwri.f90	(revision 15121)
@@ -273,4 +273,7 @@
          CALL iom_rstput( 0, 0, inum4, 'esigt', esigt )
          CALL iom_rstput( 0, 0, inum4, 'esigw', esigw )
+      ENDIF
+
+      IF( ln_sco .OR. ln_mes ) THEN                             ! s- / MEs-coordinate
          !
          CALL iom_rstput( 0, 0, inum4, 'e3t_0', e3t_0 )         !    ! scale factors
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domzgr.f90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domzgr.f90	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domzgr.f90	(revision 15121)
@@ -45,4 +45,5 @@
    USE wrk_nemo          ! Memory allocation
    USE timing            ! Timing
+   USE zgrmes            ! MES
 
    IMPLICIT NONE
@@ -112,5 +113,5 @@
       INTEGER ::   ios
       !
-      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav, ln_linssh
+      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_mes, ln_isfcav, ln_linssh
       !!----------------------------------------------------------------------
       !
@@ -134,4 +135,5 @@
          WRITE(numout,*) '      z-coordinate - partial steps   ln_zps    = ', ln_zps
          WRITE(numout,*) '      s- or hybrid z-s-coordinate    ln_sco    = ', ln_sco
+         WRITE(numout,*) '      MES-coordinate                 ln_mes    = ', ln_mes
          WRITE(numout,*) '      ice shelf cavities             ln_isfcav = ', ln_isfcav
          WRITE(numout,*) '      linear free surface            ln_linssh = ', ln_linssh
@@ -144,4 +146,5 @@
       IF( ln_zps      )   ioptio = ioptio + 1
       IF( ln_sco      )   ioptio = ioptio + 1
+      IF( ln_mes      )   ioptio = ioptio + 1
       IF( ioptio /= 1 )   CALL ctl_stop( ' none or several vertical coordinate options used' )
       !
@@ -158,4 +161,5 @@
       IF( ln_zps      )   CALL zgr_zps          ! Partial step z-coordinate
       IF( ln_sco      )   CALL zgr_sco          ! s-coordinate or hybrid z-s coordinate
+      IF( ln_mes      )   CALL zgr_mes          ! MES-coordinate
       !
       ! final adjustment of mbathy & check 
@@ -613,5 +617,5 @@
       IF( nn_closea == 0 )   CALL clo_bat( bathy, mbathy )    !==  NO closed seas or lakes  ==!
       !                       
-      IF ( .not. ln_sco ) THEN                                !==  set a minimum depth  ==!
+      IF ( (.not. ln_sco) .OR. (.not. ln_mes) ) THEN          !==  set a minimum depth  ==!
          IF( rn_hmin < 0._wp ) THEN    ;   ik = - INT( rn_hmin )                                      ! from a nb of level
          ELSE                          ;   ik = MINLOC( gdepw_1d, mask = gdepw_1d > rn_hmin, dim = 1 )  ! from a depth
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domzgr_substitute.h90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domzgr_substitute.h90	(revision 15121)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/domzgr_substitute.h90	(revision 15121)
@@ -0,0 +1,122 @@
+   !!----------------------------------------------------------------------
+   !!                    ***  domzgr_substitute.h90   ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute fsdep. and fse.., the vert. depth and scale
+   !!      factors depending on the vertical coord. used, using CPP macro.
+   !!----------------------------------------------------------------------
+   !! History :  1.0  !  2005-10  (A. Beckmann, G. Madec) generalisation to all coord.
+   !!            3.1  !  2009-02  (G. Madec, M. Leclair)  pure z* coordinate
+   !!----------------------------------------------------------------------
+
+#if defined key_vvl
+! s* or z*-coordinate (3D + time dependency) + use of additional now arrays (..._n)
+
+#   define  fse3t_b(i,j,k)   e3t_b(i,j,k)
+#   define  fse3u_b(i,j,k)   e3u_b(i,j,k)
+#   define  fse3v_b(i,j,k)   e3v_b(i,j,k)
+#   define  fse3uw_b(i,j,k)  e3uw_b(i,j,k)
+#   define  fse3vw_b(i,j,k)  e3vw_b(i,j,k)
+
+#   define  fsdept_n(i,j,k)  gdept_n(i,j,k)
+#   define  fsdepw_n(i,j,k)  gdepw_n(i,j,k)
+#   define  fsde3w_n(i,j,k)  gdep3w_n(i,j,k)
+#   define  fse3t_n(i,j,k)   e3t_n(i,j,k)
+#   define  fse3u_n(i,j,k)   e3u_n(i,j,k)
+#   define  fse3v_n(i,j,k)   e3v_n(i,j,k)
+#   define  fse3f_n(i,j,k)   e3f_n(i,j,k)
+#   define  fse3w_n(i,j,k)   e3w_n(i,j,k)
+#   define  fse3uw_n(i,j,k)  e3uw_n(i,j,k)
+#   define  fse3vw_n(i,j,k)  e3vw_n(i,j,k)
+
+#   define  fsdept_b(i,j,k)  gdept_b(i,j,k)
+#   define  fsdepw_b(i,j,k)  gdepw_b(i,j,k)
+#   define  fse3w_b(i,j,k)   e3w_b(i,j,k)
+
+#   define  fse3t_a(i,j,k)   e3t_a(i,j,k)
+#   define  fse3u_a(i,j,k)   e3u_a(i,j,k)
+#   define  fse3v_a(i,j,k)   e3v_a(i,j,k)
+
+#   define  fse3t_m(i,j)     e3t_m(i,j)
+
+#   define  hu_a(i,j)        ehu_a(i,j)
+#   define  hur_a(i,j)       ehur_a(i,j)
+#   define  hv_a(i,j)        ehv_a(i,j)
+#   define  hvr_a(i,j)       ehvr_a(i,j)
+#   define  hu_b(i,j)        ehu_b(i,j)
+#   define  hur_b(i,j)       ehur_b(i,j)
+#   define  hv_b(i,j)        ehv_b(i,j)
+#   define  hvr_b(i,j)       ehvr_b(i,j)
+
+! This part should be removed one day ...
+! ... In that case all occurence of the above statement functions
+!     have to be replaced in the code by xxx_n
+#   define  fsdept(i,j,k)    gdept_n(i,j,k)
+#   define  fsdepw(i,j,k)    gdepw_n(i,j,k)
+#   define  fsde3w(i,j,k)    gdep3w_n(i,j,k)
+#   define  fse3t(i,j,k)     e3t_n(i,j,k) 
+#   define  fse3u(i,j,k)     e3u_n(i,j,k) 
+#   define  fse3v(i,j,k)     e3v_n(i,j,k) 
+#   define  fse3f(i,j,k)     e3f_n(i,j,k) 
+#   define  fse3w(i,j,k)     e3w_n(i,j,k) 
+#   define  fse3uw(i,j,k)    e3uw_n(i,j,k)
+#   define  fse3vw(i,j,k)    e3vw_n(i,j,k)
+
+#else
+! z- or s-coordinate (1D or 3D + no time dependency) use reference in all cases
+
+#   define  fse3t_b(i,j,k)   e3t_0(i,j,k)
+#   define  fse3u_b(i,j,k)   e3u_0(i,j,k)
+#   define  fse3v_b(i,j,k)   e3v_0(i,j,k)
+#   define  fse3uw_b(i,j,k)  e3uw_0(i,j,k)
+#   define  fse3vw_b(i,j,k)  e3vw_0(i,j,k)
+
+#   define  fsdept_n(i,j,k)  gdept_0(i,j,k)
+#   define  fsdepw_n(i,j,k)  gdepw_0(i,j,k)
+#   define  fsde3w_n(i,j,k)  gde3w_0(i,j,k)
+#   define  fse3t_n(i,j,k)   e3t_0(i,j,k)
+#   define  fse3u_n(i,j,k)   e3u_0(i,j,k)
+#   define  fse3v_n(i,j,k)   e3v_0(i,j,k)
+#   define  fse3f_n(i,j,k)   e3f_0(i,j,k)
+#   define  fse3w_n(i,j,k)   e3w_0(i,j,k)
+#   define  fse3uw_n(i,j,k)  e3uw_0(i,j,k)
+#   define  fse3vw_n(i,j,k)  e3vw_0(i,j,k)
+
+#   define  fsdept_b(i,j,k)  gdept_0(i,j,k)
+#   define  fsdepw_b(i,j,k)  gdepw_0(i,j,k)
+#   define  fse3w_b(i,j,k)   e3w_0(i,j,k)
+
+#   define  fse3t_a(i,j,k)   e3t_0(i,j,k)
+#   define  fse3u_a(i,j,k)   e3u_0(i,j,k)
+#   define  fse3v_a(i,j,k)   e3v_0(i,j,k)
+
+#   define  fse3t_m(i,j)     e3t_0(i,j,1)
+
+#   define  hu_a(i,j)        hu(i,j)
+#   define  hur_a(i,j)       hur(i,j)
+#   define  hv_a(i,j)        hv(i,j)
+#   define  hvr_a(i,j)       hvr(i,j)
+#   define  hu_b(i,j)        hu(i,j)
+#   define  hur_b(i,j)       hur(i,j)
+#   define  hv_b(i,j)        hv(i,j)
+#   define  hvr_b(i,j)       hvr(i,j)
+
+! This part should be removed one day ...
+! ... In that case all occurence of the above statement functions
+!     have to be replaced in the code by xxx_n
+#   define  fsdept(i,j,k)    gdept_0(i,j,k)
+#   define  fsdepw(i,j,k)    gdepw_0(i,j,k)
+#   define  fsde3w(i,j,k)    gde3w_0(i,j,k)
+#   define  fse3t(i,j,k)     e3t_0(i,j,k)
+#   define  fse3u(i,j,k)     e3u_0(i,j,k)
+#   define  fse3v(i,j,k)     e3v_0(i,j,k)
+#   define  fse3f(i,j,k)     e3f_0(i,j,k)
+#   define  fse3w(i,j,k)     e3w_0(i,j,k)
+#   define  fse3uw(i,j,k)    e3uw_0(i,j,k)
+#   define  fse3vw(i,j,k)    e3vw_0(i,j,k)
+
+#endif
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: domzgr_substitute.h90 4488 2014-02-06 10:43:09Z rfurner $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/dtatsd.f90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/dtatsd.f90	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/dtatsd.f90	(revision 15121)
@@ -182,5 +182,5 @@
       ptsd(:,:,:,jp_sal) = sf_tsd(jp_sal)%fnow(:,:,:) 
       !
-      IF( ln_sco ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
+      IF( ln_sco .OR. ln_mes ) THEN                   !==   s- or mixed s-zps-coordinate   ==!
          !
          CALL wrk_alloc( jpk, ztp, zsp )
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/mppini_2.h90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/mppini_2.h90	(revision 15111)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/mppini_2.h90	(revision 15121)
@@ -72,5 +72,5 @@
 
       ! read namelist for ln_zco
-      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav, ln_linssh
+      NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_mes, ln_isfcav, ln_linssh
 
       !!----------------------------------------------------------------------
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/vectopt_loop_substitute.h90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/vectopt_loop_substitute.h90	(revision 15121)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/vectopt_loop_substitute.h90	(revision 15121)
@@ -0,0 +1,18 @@
+   !!----------------------------------------------------------------------
+   !!                   ***  vectopt_loop_substitute  ***
+   !!----------------------------------------------------------------------
+   !! ** purpose :   substitute the inner loop start/end indices with CPP macro
+   !!                allow unrolling of do-loop (useful with vector processors)
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.7 , NEMO Consortium (2014)
+   !! $Id: vectopt_loop_substitute.h90 4990 2014-12-15 16:42:49Z timgraham $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+#if defined key_vectopt_loop
+#  define   fs_2       1
+#  define   fs_jpim1   jpi
+#else
+#  define   fs_2       2
+#  define   fs_jpim1   jpim1
+#endif
Index: NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/zgrmes.f90
===================================================================
--- NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/zgrmes.f90	(revision 15121)
+++ NEMO/branches/UKMO/tools_r4.0-HEAD_dev_MEs/DOMAINcfg/src/zgrmes.f90	(revision 15121)
@@ -0,0 +1,1630 @@
+MODULE zgrmes
+   !!==============================================================================
+   !!                       ***  MODULE zgrmes   ***
+   !! Ocean initialization : Multiple Enveloped s coordinate (MES)
+   !!==============================================================================
+   !!  NEMO      3.6  ! 2017-05  (D. Bruciaferri)   
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_mes          : define the MES vertical coordinate system
+   !!       fs_ma96      : tanh stretch function Madec 1996
+   !!       fs_sh94      : Song and Haidvogel 1994 stretch function
+   !!---------------------------------------------------------------------
+   USE oce               ! ocean variables
+   USE dom_oce           ! ocean domain
+   USE closea            ! closed seas
+   !
+   USE in_out_manager    ! I/O manager
+   USE iom               ! I/O library
+   USE lbclnk            ! ocean lateral boundary conditions (or mpp link)
+   USE lib_mpp           ! distributed memory computing library
+   USE wrk_nemo          ! Memory allocation
+   USE timing            ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zgr_mes        ! called by domzgr.F90
+   ! Bruciaferri, Shapiro & Wobus (2018) envelopes and stretching parameters
+   CHARACTER(lc)      :: ctlmes                  ! control message error (lc=256)
+   INTEGER, PARAMETER :: max_nn_env = 5          ! Maximum allowed number of envelopes.
+   REAL(wp)           :: rn_bot_min              ! minimum depth of ocean bottom (>0) (m)
+   REAL(wp)           :: rn_bot_max              ! maximum depth of ocean bottom (= ocean depth) (>0) (m)
+   LOGICAL            :: ln_envl(max_nn_env)     ! Array with flags (T/F) specifing which envelope is used
+   INTEGER            :: nn_strt(max_nn_env)     ! Array specifing the stretching function for each envelope:
+                                                 ! Madec 1996 (0), Song and Haidvogel 1994 (1) 
+   REAL(wp)           :: rn_ebot_min(max_nn_env) ! minimum depth of envelopes (>0) (m)
+   REAL(wp)           :: rn_ebot_max(max_nn_env) ! maximum depth of envelopes (= envelopes depths) (>0) (m)
+   INTEGER            :: nn_slev(max_nn_env)     ! Array specifing number of levels of each enveloped vertical zone
+   REAL(wp)           :: rn_e_hc(max_nn_env)     ! Array specifing critical depth for transition to stretched 
+                                                 ! coordinates of each envelope
+   REAL(wp)           :: rn_e_th(max_nn_env)     ! Array specifing surface control parameter (0<=th<=20) of SH94
+                                                 ! or rn_zs of SF12 for each vertical sub-zone
+   REAL(wp)           :: rn_e_bb(max_nn_env)     ! Array specifing bottom control parameter (0<=bb<=1) of SH94
+                                                 ! or rn_zb_b of SF12 for each vertical sub-zone
+   REAL(wp)           :: rn_e_ba(max_nn_env)     ! Array specifing bottom control parameter rn_zb_a of SF12 for
+                                                 ! each vertical sub-zone
+   REAL(wp)           :: rn_e_al(max_nn_env)     ! Array specifing stretching parameter rn_alpha of SF12 for
+                                                 ! each vertical sub-zone
+      !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+
+CONTAINS
+
+   SUBROUTINE zgr_mes
+      !!-----------------------------------------------------------------------------
+      !!                  ***  ROUTINE zgr_mes  ***
+      !!                     
+      !! ** Purpose :   define the Multi Enveloped S-coordinate (MES) system
+      !!
+      !! ** Method  :   s-coordinate defined respect to multiple
+      !!                externally defined envelope
+      !!
+      !!      The depth of model levels is defined as the product of an
+      !!      analytical function by the externally defined envelopes.
+      !! 
+      !!      - Read envelopes (in meters) at t-point and compute the
+      !!        envelopes at u-, v-, and f-points.
+      !!            hbatu = mi( hbatt )
+      !!            hbatv = mj( hbatt )
+      !!            hbatf = mi( mj( hbatt ) )
+      !!
+      !!      - Compute z_gsigt, z_gsigw, z_esigt, z_esigw from an analytical
+      !!        function and its finite difference derivative.
+      !!            z_gsigt(k) = fssig (k    )
+      !!            z_gsigw(k) = fssig (k-0.5)
+      !!            z_esigt(k) = z_gsigw(k+1) - z_gsigw(k)
+      !!            z_esigw(k) = z_gsigt(k+1) - z_gsigt(k)
+      !!
+      !!      Three options for stretching are given:
+      !! 
+      !!          *) nn_strt = 0 : Madec et al 1996 cosh/tanh function
+      !!          *) nn_strt = 1 : Song and Haidvogel 1994 sinh/tanh function  
+      !!          *) nn_strt = 2 : Siddorn and Furner gamma function
+      !!
+      !!----------------------------------------------------------------------
+      !!        SKETCH of the GEOMETRY OF THE S-S-Z COORDINATE SYSTEM
+      !!
+      !!        Lines represent W-levels:
+      !!
+      !!        0: First s-level part. The total number
+      !!           of levels in this part is controlled
+      !!           by the nn_slev(1) namelist parameter.
+      !!
+      !!           Depth first W-lev: 0 m (surfcace)
+      !!           Depth last  W-lev: depth of 1st envelope
+      !!
+      !!        o: Second  s-level part. The total number
+      !!           of levels in this part is controlled
+      !!           by the nn_slev(2) namelist parameter.
+      !!        
+      !!           Depth last  W-lev: depth of 2nd envelope
+      !!
+      !!        @: Third s-level part. The total number
+      !!           of levels in this part is controlled
+      !!           by the nn_slev(3) namelist parameter.
+      !!        
+      !!           Depth last  W-lev: depth of 3rd envelope  
+      !!    
+      !! z |~~~~~~~~~~~~~~~~~~~~~~~0~~~~~~~~~~~~~~~~~~~~~~~          SURFACE                 
+      !!   | 
+      !!   |-----------------------0-----------------------   ln_envl(1) = true, nn_slev(1) = 3
+      !!   |
+      !!   |=======================0=======================          ENVELOPE 1
+      !!   | 
+      !!   |-----------------------o-----------------------
+      !!   |                                                 ln_envl(2) = true, nn_slev(2) = 3
+      !!   |-----------------------o-----------------------
+      !!   |
+      !!   |¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬o¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬          ENVELOPE 2
+      !!   |
+      !!   |-----------------------@-----------------------  ln_envl(3) = true, nn_slev(3) = 2
+      !!   |
+      !!   |_______________________@_______________________          ENVELOPE 3
+      !!  \|/
+      !!
+      !!
+      !!-----------------------------------------------------------------------------
+      !! Author: Diego Bruciaferri (University of Plymouth), September 2017
+      !!-----------------------------------------------------------------------------
+
+      !
+      CHARACTER(lc)                       ::   env_name                 ! name of the externally defined envelope
+      INTEGER                             ::   ji, jj, jk, jl, je       ! dummy loop argument
+      INTEGER                             ::   ios                      ! Local integer output status for namelist read
+      INTEGER                             ::   inum                     ! temporary logical unit
+      INTEGER                             ::   tot_env, cor_env
+      INTEGER                             ::   num_s, s_1st, ind        ! for loops over envelopes
+      INTEGER                             ::   num_s_up, num_s_dw       ! for loops over envelopes
+      REAL(wp)                            ::   D1s_up, D1s_dw           ! for loops over envelopes
+      INTEGER                             ::   ibcbeg, ibcend           ! boundary condition for cubic splines
+      INTEGER, PARAMETER                  ::   n = 2                    ! number of considered points for each interval
+      REAL(wp)                            ::   c(4,n)                   ! matrix for cubic splines coefficents
+      REAL(wp)                            ::   d(2,2)                   ! matrix for depth values and depth derivative 
+                                                                        ! at intervals' boundaries
+      REAL(wp)                            ::   tau(n)                   ! abscissas of intervals' boundaries
+      REAL(wp)                            ::   coefa, coefb             ! for loops over envelopes
+      REAL(wp)                            ::   alpha, env_hc            ! for loops over envelopes
+      REAL(wp)                            ::   dep_up, dep_dw           ! for loops over envelopes
+      REAL(wp)                            ::   dep0, dep1, dep2, dep3   ! for loops over envelopes 
+                                                                        ! for cubic splines
+      REAL(wp)                            ::   zcoeft, zcoefw, sw, st   ! temporary scalars
+      REAL(wp)                            ::   max_env_up, min_env_up   ! to identify geopotential levels
+      REAL(wp)                            ::   max_env_dw, min_env_dw   ! to identify geopotential levels
+      REAL(wp), POINTER, DIMENSION(:)     ::   z_gsigw1, z_gsigt1       ! MES-coordinates analytical trans. 
+                                                                        ! (0.<= s <= 1.) for T- and W-points
+      REAL(wp), POINTER, DIMENSION(:)     ::   z_esigw1, z_esigt1       ! MES analytical scale factors  
+                                                                        ! of T- and W-points
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: env_up, env_dw             ! for loops over envelopes
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: env0, env1, env2, env3     ! for loops over envelopes
+                                                                        ! for cubic splines
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: envlt                      ! array for the envelopes
+      INTEGER                             :: gst_envl(max_nn_env)       ! Array to deal with a ghost last envelope 
+
+      NAMELIST/namzgr_mes/rn_bot_min , rn_bot_max , ln_envl, nn_strt, &
+                          rn_ebot_min, rn_ebot_max, nn_slev, rn_e_hc, &
+                          rn_e_th, rn_e_bb, rn_e_ba, rn_e_al
+
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('zgr_mes')
+      !
+      CALL wrk_alloc( jpi, jpj, max_nn_env , envlt )
+      CALL wrk_alloc( jpi, jpj, env_up, env_dw, env0, env1, env2, env3 )
+      CALL wrk_alloc( jpk, z_gsigw1, z_gsigt1, z_esigw1, z_esigt1 )
+      !
+      ! Namelist namzgr_mes in reference namelist : envelopes and
+      ! sigma-stretching parameters
+      REWIND( numnam_ref )         
+      READ  ( numnam_ref, namzgr_mes, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr_mes in reference namelist', lwp )
+      ! Namelist namzgr_mes in configuration namelist : envelopes and
+      ! sigma-stretching parameters
+      REWIND( numnam_cfg )
+      READ  ( numnam_cfg, namzgr_mes, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr_mes in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namzgr_mes )
+
+      IF(lwp) THEN                           ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'domzgr_mes : Multi Enveloped S-coordinate (Bruciaferri, Shapiro and Wobus 2017)'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namzgr_mes'
+         WRITE(numout,*) ''
+         WRITE(numout,*) '   Minimum depth of the ocean   rn_bot_min, ', rn_bot_min
+         WRITE(numout,*) '   Maximum depth of the ocean   rn_bot_max, ', rn_bot_max
+         WRITE(numout,*) ''
+         WRITE(numout,*) '-------------------------------------------------------------------------------'
+         DO je = 1, max_nn_env
+            WRITE(numout,*) 'SUBDOMAIN ', je,':'
+            IF ( je == 1) THEN
+               WRITE(numout,*) '   Envelope up  : envelope 0, free surface'
+               WRITE(numout,*) '   Envelope down: envelope ',je,',ln_envl(',je,') = ',ln_envl(je)
+            ELSE
+               WRITE(numout,*) '   Envelope up  : envelope ',je-1,',ln_envl(',je,') = ',ln_envl(je-1)
+               WRITE(numout,*) '   Envelope down: envelope ',je  ,',ln_envl(',je,') = ',ln_envl(je)
+            END IF
+            WRITE(numout,*) '   min dep of envlp down rn_ebot_min(',je,') = ',rn_ebot_min(je)
+            WRITE(numout,*) '   max dep of envlp down rn_ebot_max(',je,') =',rn_ebot_max(je)
+            WRITE(numout,*) '   num. of MEs-lev.          nn_slev(',je,') = ',nn_slev(je)
+            IF ( isodd(je) ) THEN
+               WRITE(numout,*) '   Stretched s-coordinates: '
+            ELSE
+               WRITE(numout,*) '   Stretched CUBIC SPLINES: '
+            END IF
+            IF (nn_strt(je) == 0) WRITE(numout,*) '     M96  stretching function'
+            IF (nn_strt(je) == 1) WRITE(numout,*) '     SH94 stretching function'
+            IF (nn_strt(je) == 2) WRITE(numout,*) '     SF12 stretching function'
+            WRITE(numout,*) '     critical depth        rn_e_hc(',je,') = ',rn_e_hc(je)
+            WRITE(numout,*) '     surface stretc. coef. rn_e_th(',je,') = ',rn_e_th(je)
+            IF (nn_strt(je) == 2) THEN
+               WRITE(numout,*) '     bottom  stretc. coef. rn_e_ba(',je,') = ',rn_e_ba(je)
+            END IF
+            WRITE(numout,*) '     bottom  stretc. coef. rn_e_bb(',je,') = ',rn_e_bb(je)
+            IF (nn_strt(je) == 2) THEN
+               WRITE(numout,*) '     bottom  stretc. coef. rn_e_al(',je,') = ',rn_e_al(je)
+            END IF
+            WRITE(numout,*) '-------------------------------------------------------------------------------'
+         ENDDO
+      ENDIF
+
+      ! Check if namelist is defined correctly.
+      ! Not strictly needed but we force the user
+      ! to define the namelist correctly.
+
+      tot_env = 0 ! total number of requested envelopes
+      cor_env = 0 ! total number of correctly defined envelopes
+      DO je = 1, max_nn_env
+         IF ( ln_envl(je) )                        tot_env = tot_env + 1
+         IF ( ln_envl(je) .AND. cor_env == (je-1)) cor_env = cor_env + 1
+      ENDDO
+      WRITE(ctlmes,*) 'number of REQUESTED envelopes and number of CORRECTLY defined envelopes are DIFFERENT'
+      IF ( tot_env /= cor_env ) CALL ctl_stop( ctlmes )
+
+      !Checking consistency of user defined parameters
+      WRITE(ctlmes,*) 'TOT number of levels (jpk) IS DIFFERENT from sum over nn_slev(:)'
+      IF ( SUM(nn_slev(:)) /= jpk ) CALL ctl_stop( ctlmes )
+
+      ! Determining if there is a "ghost" envelope: 
+      gst_envl(:) = 0
+      IF ( nn_slev(tot_env) == 0 ) gst_envl(tot_env) = 1
+
+      ! Reading bathymetry and envelopes.
+      ! In future should be included in zgr_bat.
+
+      IF( ntopo == 1 ) THEN
+
+        CALL iom_open ( 'bathy_meter.nc', inum )
+        CALL iom_get  ( inum, jpdom_data, 'Bathymetry' , bathy, lrowattr=ln_use_jattr  )
+
+        DO je = 1, tot_env
+           WRITE (env_name, '(A6,I0)') 'hbatt_', je
+           CALL iom_get  ( inum, jpdom_data, TRIM(env_name) , envlt(:,:,je), lrowattr=ln_use_jattr  )
+        ENDDO
+
+        CALL iom_close( inum )
+
+      ELSE
+
+        WRITE(ctlmes,*) 'parameter , ntopo = ', ntopo
+        CALL ctl_stop( ctlmes )
+
+      ENDIF
+      IF( nn_closea == 0 )   CALL clo_bat( bathy, mbathy ) !==  NO closed seas or lakes  ==!  
+
+      ! Checking consistency of envelopes
+
+      DO je = 1, tot_env-1
+         WRITE(ctlmes,*) 'Envelope ', je+1, ' is shallower that Envelope ', je
+         IF (MAXVAL(envlt(:,:,je+1)) < MAXVAL(envlt(:,:,je))) CALL ctl_stop( ctlmes )
+      ENDDO
+
+      ! Set maximum and minimum ocean depth
+      bathy(:,:) = MIN( rn_bot_max, bathy(:,:) )
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+           IF( bathy(ji,jj) > 0._wp )   bathy(ji,jj) = MAX( rn_bot_min, bathy(ji,jj) )
+         END DO
+      END DO
+
+      ! Initializing to 0.0 some arrays:
+      !
+      ! *) gdept_1d, gdepw_1d : depth of T- and W-point (m)
+      ! *) e3t_1d  , e3w_1d   : scale factors at T- and W-levels (m)
+      ! *) z_gsigt1, z_gsigw1 : MES-coordinates (0.<= s <= 1.) of T- and W-points
+
+      gdept_1d = 0._wp   ;   gdepw_1d = 0._wp   ;
+      e3t_1d   = 0._wp   ;   e3w_1d   = 0._wp   ;
+      z_gsigw1 = 0._wp   ;   z_gsigt1 = 0._wp   ;
+      z_esigw1 = 0._wp   ;   z_esigt1 = 0._wp   ;
+
+      ! Initialize mbathy to the maximum ocean level available
+
+      mbathy(:,:) = jpkm1
+
+      ! Defining scosrf and scobot
+
+      scosrf(:,:) = 0._wp             ! ocean surface depth (here zero: no under ice-shelf sea)
+      scobot(:,:) = bathy(:,:)        ! ocean bottom  depth
+
+      !==================================================================
+      ! 1. Defining 1D MEs-levels and computing their depths 
+      !    (they will be used in diawri.F90)
+      !==================================================================
+
+      ! Computing gdept_1d and gdepw_1d
+
+      DO je = 1, tot_env ! LOOP over all the requested envelopes
+         IF (je == 1) THEN
+            s_1st  = 1
+            num_s  = nn_slev(je)
+            dep_up = 0._wp      ! surface
+         ELSE
+            s_1st = s_1st + num_s - 1
+            num_s  = nn_slev(je)  + 1
+            dep_up = rn_ebot_max(je-1)
+         ENDIF
+
+         dep_dw  = rn_ebot_max(je)
+         env_hc  = rn_e_hc(je)
+         coefa   = rn_e_th(je)
+         coefb   = rn_e_bb(je)
+         alpha   = rn_e_al(je)
+
+         IF (nn_strt(je) == 2) THEN
+            coefa = coefa / (dep_dw - dep_up)
+            coefb = coefb + ((dep_dw - dep_up)*rn_e_ba(je))
+            coefb = 1.0_wp - (coefb/(dep_dw - dep_up))
+         ENDIF
+
+         IF ( isodd(je) ) THEN
+            IF ( gst_envl(je) == 0 ) THEN
+               DO jk = 1, num_s
+                  ind = s_1st+jk-1
+                  ! W-GRID
+                  z_gsigw1(ind) = -s_coord(sigma(1,jk,num_s), coefa, &
+                                           coefb, alpha, num_s, nn_strt(je))
+                  ! T-GRID
+                  z_gsigt1(ind) = -s_coord(sigma(0,jk,num_s), coefa, &
+                                           coefb, alpha, num_s, nn_strt(je))
+                  zcoefw = z_gsigw1(ind)
+                  zcoeft = z_gsigt1(ind)
+                              
+                  IF (nn_strt(je) /= 2) THEN
+                     gdept_1d(ind) = z_mes(dep_up, dep_dw, zcoeft, &
+                                           -sigma(0,jk,num_s), env_hc)
+                     gdepw_1d(ind) = z_mes(dep_up, dep_dw, zcoefw, &
+                                           -sigma(1,jk,num_s), env_hc)
+                  ELSE
+                     gdept_1d(ind) = z_mes(dep_up, dep_dw, zcoeft, &
+                                           -sigma(0,jk,num_s), 0._wp)
+                     gdepw_1d(ind) = z_mes(dep_up, dep_dw, zcoefw, &
+                                           -sigma(1,jk,num_s), 0._wp)
+                  END IF
+               ENDDO
+            ENDIF
+
+         ELSE
+
+            ! Ensure that for splines we do not use SF12
+            !IF (nn_strt(je) > 1) nn_strt(je) = 1
+
+            ! Interval's endpoints TAU are 0 and 1.
+            tau(1) = 0._wp
+            tau(n) = 1._wp
+
+            IF ( je == 2 ) THEN
+               dep0 = 0._wp
+            ELSE 
+               dep0 = rn_ebot_max(je-2)
+            END IF 
+            dep1   = dep_up
+            dep2   = dep_dw
+            dep3   = rn_ebot_max(je+1)
+
+            ! Computing derivative analytically
+            !
+            ! 1. Derivative for upper envelope
+            ibcbeg = 1
+            IF (nn_strt(je-1) == 2) THEN
+               alpha    = rn_e_al(je-1)
+               num_s_up = nn_slev(je-1)
+               coefa    = rn_e_th(je-1) / (dep1-dep0)
+               coefb    = rn_e_bb(je-1) + ((dep1-dep0)*rn_e_ba(je-1))
+               coefb    = 1.0_wp-(coefb/(dep1-dep0))
+            ELSE
+               alpha    = 0._wp
+               num_s_up = 1
+               coefa    = rn_e_th(je-1)
+               coefb    = rn_e_bb(je-1)
+            END IF
+            D1s_up = D1s_coord(-1._wp, coefa, coefb, &
+                               alpha, num_s_up, nn_strt(je-1))
+            d(1,1) = dep_up
+            IF (nn_strt(je-1) == 2) THEN
+               d(2,1) = D1z_mes(dep0, dep1, D1s_up, 0._wp, 1)
+            ELSE
+               d(2,1) = D1z_mes(dep0, dep1, D1s_up, rn_e_hc(je-1), 1)
+            END IF
+            !
+            ! 2. Derivative for deeper envelope
+            IF ( gst_envl(je+1) == 0 ) THEN
+               ibcend = 1 ! Bound. cond for the 1st derivative          
+               IF (nn_strt(je+1) == 2) THEN
+                  alpha    = rn_e_al(je+1)
+                  num_s_dw = nn_slev(je+1)
+                  coefa    = rn_e_th(je+1) / (dep3-dep2)
+                  coefb    = rn_e_bb(je+1) + ((dep3-dep2)*rn_e_ba(je+1))
+                  coefb    = 1.0_wp-(coefb/(dep3-dep2))
+               ELSE
+                  alpha    = 0._wp
+                  num_s_dw = 1
+                  coefa    = rn_e_th(je+1)
+                  coefb    = rn_e_bb(je+1)
+               END IF
+               D1s_dw = D1s_coord(0._wp, coefa, coefb, &
+                                  alpha, num_s_dw, nn_strt(je+1))
+               d(1,2) = dep_dw
+               IF (nn_strt(je+1) == 2) THEN
+                  d(2,2) = D1z_mes(dep2, dep3, D1s_dw, 0._wp, 1)
+               ELSE
+                  d(2,2) = D1z_mes(dep2, dep3, D1s_dw, rn_e_hc(je+1), 1)
+               END IF
+            ELSE
+               ibcend = 2     ! Bound. cond for the 2nd derivative
+               d(2,2) = 0._wp ! 2nd der = 0
+            ENDIF
+            !
+            ! Computing spline's coefficients
+            IF ( lwp ) THEN
+               WRITE(numout,*) "BOUNDARY COND. to CONSTRAIN SPLINES:"
+               WRITE(numout,*) "ibcbeg: ", ibcbeg
+               WRITE(numout,*) "ibcend: ", ibcend
+            ENDIF
+            c = cub_spl(tau, d, n, ibcbeg, ibcend )
+
+            IF ( lwp ) THEN
+               WRITE(numout,*) "Subzone between depth ", dep1, " and depth ", dep2 
+               WRITE(numout,*) ""
+               WRITE(numout,*) "D1s_up = ", D1s_up
+               WRITE(numout,*) "1st deriv. of z(mes) at depth ", dep1, " is ", d(2,1)
+               WRITE(numout,*) "D1s_dw = ", D1s_dw
+               WRITE(numout,*) "1st deriv. of z(mes) at depth ", dep2, " is ", d(2,2)
+               WRITE(numout,*) ""
+               WRITE(numout,*) "CUBIC SPLINE COEFFICENTS"
+               WRITE(numout,*) "c1 = ", c(1,1)
+               WRITE(numout,*) "c2 = ", c(2,1)
+               WRITE(numout,*) "c3 = ", c(3,1)
+               WRITE(numout,*) "c4 = ", c(4,1)
+               WRITE(numout,*) ""
+               WRITE(numout,*) "CUB. SPL. at s = ", -sigma(1, 1, num_s),      &
+                               " is ", z_cub_spl(-sigma(1, 1, num_s), tau, c)
+               WRITE(numout,*) "1st deriv. of CUB. SPL. at s = ", -sigma(1, 1, num_s) ,     & 
+                               " is ", D1z_cub_spl(-sigma(1, 1, num_s), tau, c, 1)
+               WRITE(numout,*) "CUB. SPL. at s = ", -sigma(1, num_s, num_s) , &
+                               " is ", z_cub_spl(-sigma(1, num_s, num_s), tau, c)
+               WRITE(numout,*) "1st deriv. of CUB. SPL. at s = ", -sigma(1, num_s, num_s) , &
+                               " is ", D1z_cub_spl(-sigma(1, num_s, num_s), tau, c, 1)
+            END IF
+
+            env_hc  = rn_e_hc(je)
+            coefa   = rn_e_th(je)
+            coefb   = rn_e_bb(je)
+            alpha   = rn_e_al(je)
+
+            DO jk = 1, num_s
+               ind = s_1st+jk-1
+               ! W-GRID
+               z_gsigw1(s_1st+jk-1) = -s_coord( sigma(1,jk,num_s), coefa, &
+                                                coefb, alpha, num_s, nn_strt(je) )
+               ! T-GRID
+               z_gsigt1(s_1st+jk-1) = -s_coord( sigma(0,jk,num_s), coefa, &
+                                                coefb, alpha, num_s, nn_strt(je) )
+               st  = z_gsigt1(ind)
+               sw  = z_gsigw1(ind)
+               gdept_1d(ind) = z_cub_spl(st, tau, c)
+               gdepw_1d(ind) = z_cub_spl(sw, tau, c)
+            END DO
+ 
+         END IF
+
+      END DO
+
+      !==================================================================
+      ! 2. Computing derivative of MEs-coordinate and scale factors
+      !    as finite differences
+      !==================================================================
+
+      ! Computing derivative of MEs-coordinate as finite differences
+      DO jk = 1, jpkm1
+         z_esigt1(jk)   = z_gsigw1(jk+1) - z_gsigw1(jk)
+         z_esigw1(jk+1) = z_gsigt1(jk+1) - z_gsigt1(jk)
+      END DO
+      ! Surface
+      z_esigw1( 1 ) = 2._wp * ( z_gsigt1( 1 ) - z_gsigw1( 1 ) )
+      ! Bottom
+      z_esigt1(jpk) = 2._wp * ( z_gsigt1(jpk) - z_gsigw1(jpk) )
+
+      ! Computing scale factors as finite differences
+      DO jk=1,jpkm1
+         e3t_1d(jk)   = gdepw_1d(jk+1) - gdepw_1d(jk)
+         e3w_1d(jk+1) = gdept_1d(jk+1) - gdept_1d(jk)
+      ENDDO
+      ! Bottom:
+      jk = jpk
+      e3t_1d(jk) = 2.0_wp * (gdept_1d(jk) - gdepw_1d(jk))
+      ! and Surface  (H. Liu)
+      jk = 1
+      e3w_1d(jk) = 2.0_wp * (gdept_1d(1) - gdepw_1d(1))
+
+ 
+      ! Control print
+      IF ( lwp ) THEN
+        WRITE(numout,*) ""
+        WRITE(numout,*) "1a. MEs-levels and first derivative"
+        WRITE(numout,*) ""
+        WRITE(numout,*) "      k     z_gsigw1      z_esigw1     z_gsigt1      z_esigt1"
+        WRITE(numout,*) ""
+        DO jk = 1, jpk
+           WRITE(numout,*) jk, z_gsigw1(jk), z_esigw1(jk), z_gsigt1(jk), z_esigt1(jk)
+        ENDDO
+        WRITE(numout,*) "-----------------------------------------------------------------"
+        
+        WRITE(numout,*) ""
+        WRITE(numout,*) "2a. Depth of MEs-levels and scale factors"
+        WRITE(numout,*) ""
+        WRITE(numout,*) "      k     gdepw_1d      e3w_1d       gdepw_1d      e3w_1d"
+        WRITE(numout,*) ""
+        DO jk = 1, jpk
+           WRITE(numout,*) jk, gdepw_1d(jk), e3w_1d(jk), gdept_1d(jk), e3t_1d(jk)
+        ENDDO
+        WRITE(numout,*) "-----------------------------------------------------------------"
+      ENDIF
+
+      ! Checking monotonicity for cubic splines
+      DO jk = 1, jpk-1
+         IF ( gdept_1d(jk+1) < gdept_1d(jk) ) THEN
+            WRITE(ctlmes,*) 'NOT MONOTONIC gdept_1d: change envelopes'
+            CALL ctl_stop( ctlmes )
+         END IF
+         IF ( gdepw_1d(jk+1) < gdepw_1d(jk) ) THEN
+            WRITE(ctlmes,*) 'NOT MONOTONIC gdepw_1d: change envelopes'
+            CALL ctl_stop( ctlmes )
+         END IF
+      END DO
+
+      !========================
+      ! 3. Compute 3D MEs mesh
+      !========================
+
+      DO je = 1, tot_env ! LOOP over all the requested envelopes
+
+         IF (je == 1) THEN
+            s_1st  = 1
+            num_s  = nn_slev(je)
+            env_up = scosrf       ! surface
+         ELSE
+            s_1st  = s_1st + num_s - 1
+            num_s  = nn_slev(je) + 1
+            env_up = envlt(:,:,je-1)
+         ENDIF
+
+         env_dw  = envlt(:,:,je)
+         env_hc  = rn_e_hc(je)
+         alpha   = rn_e_al(je)
+
+         IF ( isodd(je) ) THEN
+
+            IF ( gst_envl(je) == 0 ) THEN
+               DO jk = 1, num_s
+                  ind = s_1st+jk-1
+                  DO jj = 1,jpj
+                     DO ji = 1,jpi
+                        IF (env_dw(ji,jj) < env_hc) THEN   
+                           ! shallow water, uniform sigma
+                           zcoefw = -sigma(1, jk, num_s) 
+                           zcoeft = -sigma(0, jk, num_s)
+                           !IF (nn_strt(je) == 2) THEN
+                           !   ! shallow water, z coordinates
+                           !   ! SF12 in AMM* configurations uses 
+                           !   ! this (ln_sigcrit=.false.)
+                           !   zcoefw = zcoefw*(env_hc/(env_dw(ji,jj)-env_up(ji,jj)))
+                           !   zcoeft = zcoeft*(env_hc/(env_dw(ji,jj)-env_up(ji,jj)))
+                           !ENDIF
+                        ELSE                               ! deep water, stretched s
+                           IF (nn_strt(je) == 2) THEN
+                              coefa = rn_e_th(je) /  (env_dw(ji,jj)-env_up(ji,jj))
+                              coefb = rn_e_bb(je) + ((env_dw(ji,jj)-env_up(ji,jj))*rn_e_ba(je))
+                              coefb = 1.0_wp-(coefb/(env_dw(ji,jj)-env_up(ji,jj)))
+                              ! W-GRID
+                              zcoefw = -s_coord( sigma(1,jk,num_s), coefa, &
+                                                 coefb, alpha, num_s, nn_strt(je) )
+                              ! T-GRID
+                              zcoeft = -s_coord( sigma(0,jk,num_s), coefa, &
+                                                 coefb, alpha, num_s, nn_strt(je) )
+                           ELSE
+                              zcoefw = z_gsigw1(ind)
+                              zcoeft = z_gsigt1(ind)
+                           END IF
+                        ENDIF
+
+                        IF (nn_strt(je) /= 2) THEN
+                           gdept_0(ji,jj,ind) = z_mes(env_up(ji,jj), env_dw(ji,jj), zcoeft, &
+                                                      -sigma(0, jk, num_s), env_hc)
+                                                
+                           gdepw_0(ji,jj,ind) = z_mes(env_up(ji,jj), env_dw(ji,jj), zcoefw, &
+                                                      -sigma(1, jk, num_s), env_hc)
+                        ELSE
+                           gdept_0(ji,jj,ind) = z_mes(env_up(ji,jj), env_dw(ji,jj), zcoeft, &
+                                                      -sigma(0, jk, num_s), 0._wp)
+
+                           gdepw_0(ji,jj,ind) = z_mes(env_up(ji,jj), env_dw(ji,jj), zcoefw, &
+                                                      -sigma(1, jk, num_s), 0._wp)
+                        END IF
+                     END DO
+                  END DO
+               END DO
+            END IF
+
+         ELSE
+
+            ! Interval's endpoints TAU are 0 and 1.
+            tau(1) = 0._wp
+            tau(n) = 1._wp
+
+            IF ( je == 2 ) THEN
+               env0 = scosrf
+            ELSE
+               env0 = envlt(:,:,je-2) 
+            END IF
+            env1   = env_up
+            env2   = env_dw
+            env3   = envlt(:,:,je+1)
+
+            DO jj = 1,jpj
+               DO ji = 1,jpi
+                  d(1,1) = env_up(ji,jj)
+                  d(1,2) = env_dw(ji,jj)
+                  !
+                  ! Computing derivative analytically
+                  !
+                  ! 1. Derivative for upper envelope
+                  ibcbeg = 1
+                  IF (nn_strt(je-1) == 2) THEN
+                     alpha    = rn_e_al(je-1)
+                     num_s_up = nn_slev(je-1)
+                     coefa    = rn_e_th(je-1) / &
+                                (env1(ji,jj)-env0(ji,jj))
+                     coefb    = rn_e_bb(je-1) + &
+                               ((env1(ji,jj)-env0(ji,jj))*rn_e_ba(je-1))
+                     coefb    = 1.0_wp-(coefb/(env1(ji,jj)-env0(ji,jj)))                   
+                  ELSE
+                     alpha    = 0._wp
+                     num_s_up = 1
+                     coefa    = rn_e_th(je-1)
+                     coefb    = rn_e_bb(je-1)
+                  END IF
+                  D1s_up = D1s_coord(-1._wp, coefa, coefb, &
+                                     alpha, num_s_up, nn_strt(je-1))
+                  IF (nn_strt(je-1) == 2) THEN
+                     d(2,1) = D1z_mes(env0(ji,jj), env1(ji,jj), D1s_up, &
+                                      0._wp, 1)
+                  ELSE
+                     d(2,1) = D1z_mes(env0(ji,jj), env1(ji,jj), D1s_up, &
+                                      rn_e_hc(je-1), 1)
+                  END IF
+                  !
+                  ! 2. Derivative for lower envelope
+                  IF ( gst_envl(je+1) == 0 ) THEN
+                     ibcend = 1 ! Bound. cond for the 1st derivative
+                     IF (nn_strt(je+1) == 2) THEN
+                        alpha    = rn_e_al(je+1)
+                        num_s_dw = nn_slev(je+1)
+                        coefa    = rn_e_th(je+1) / &
+                                   (env3(ji,jj)-env2(ji,jj))
+                        coefb    = rn_e_bb(je+1) + &
+                                   ((env3(ji,jj)-env2(ji,jj))*rn_e_ba(je+1))
+                        coefb    = 1.0_wp-(coefb/(env3(ji,jj)-env2(ji,jj)))
+                     ELSE
+                        alpha    = 0._wp
+                        num_s_dw = 1
+                        coefa    = rn_e_th(je+1)
+                        coefb    = rn_e_bb(je+1)
+                     END IF
+                     D1s_dw = D1s_coord(0._wp, coefa, coefb, &
+                                        alpha, num_s_dw, nn_strt(je+1))
+                  
+                     IF (nn_strt(je+1) == 2) THEN
+                        d(2,2) = D1z_mes(env2(ji,jj), env3(ji,jj), D1s_dw, &
+                                         0._wp, 1)
+                     ELSE
+                        d(2,2) = D1z_mes(env2(ji,jj), env3(ji,jj), D1s_dw, &
+                                         rn_e_hc(je+1), 1)
+                     END IF
+                  ELSE
+                     ibcend = 2     ! Bound. cond for the 2nd derivative
+                     d(2,2) = 0._wp ! 2nd der = 0
+                  ENDIF
+
+                  ! Computing spline's coefficients
+                  !IF ( lwp ) THEN
+                  !   WRITE(numout,*) "BOUNDARY COND. to CONSTRAIN SPLINES:"
+                  !   WRITE(numout,*) "ibcbeg: ", ibcbeg
+                  !   WRITE(numout,*) "ibcend: ", ibcend
+                  !ENDIF
+                  c = cub_spl(tau, d, n, ibcbeg, ibcend )
+
+                  ! Computing model level depths
+                  DO jk = 1, num_s
+                     ind = s_1st+jk-1
+                     st  = z_gsigt1(ind)
+                     sw  = z_gsigw1(ind)
+                     gdept_0(ji,jj,ind) = z_cub_spl(st, tau, c)
+                     gdepw_0(ji,jj,ind) = z_cub_spl(sw, tau, c)
+                  END DO
+
+                  ! Control print
+                  IF ( lwp ) THEN
+                     IF ( jj == 25 .AND. ji == 7 ) THEN
+                        WRITE(numout,*) ""
+                  !   WRITE(numout,*) "env_up = ", env1(ji,jj)
+                        WRITE(numout,*) "1st deriv. at TAU = 0._wp is ", d(2,1)
+                  !   WRITE(numout,*) "env_dw = ", env2(ji,jj)
+                        WRITE(numout,*) "1st deriv. at TAU = 1._wp is ", d(2,2)
+                  !   WRITE(numout,*) "CUBIC SPLINE at s = ", -sigma(1, 1, num_s) , " is ", &
+                  !                   z_cub_spl(-sigma(1, 1, num_s), tau, c)
+                        WRITE(numout,*) "1st deriv. at s = ", -sigma(1, 1, num_s) , " is ", &
+                                        D1z_cub_spl(-sigma(1, 1, num_s), tau, c, 1)
+                  !   WRITE(numout,*) "CUBIC SPLINE at s = ", -sigma(1, num_s, num_s) , " is ", &
+                  !                   z_cub_spl(-sigma(1, num_s, num_s), tau, c)
+                        WRITE(numout,*) "1st deriv. at s = ", -sigma(1, num_s, num_s) , " is ", &
+                                        D1z_cub_spl(-sigma(1, num_s, num_s), tau, c, 1)
+                     END IF
+                  END IF
+ 
+               END DO
+            END DO
+
+         END IF
+
+      END DO
+
+      ! =============================================
+      ! 4. COMPUTE e3t, e3w for ALL general levels
+      !    as finite differences
+      ! =============================================
+      !
+      DO jk=1,jpkm1
+         e3t_0(:,:,jk)   = gdepw_0(:,:,jk+1) - gdepw_0(:,:,jk)
+         e3w_0(:,:,jk+1) = gdept_0(:,:,jk+1) - gdept_0(:,:,jk)
+      ENDDO
+      ! Surface
+      jk = 1
+      e3w_0(:,:,jk) = 2.0_wp * (gdept_0(:,:,1) - gdepw_0(:,:,1))
+      !
+      ! Bottom
+      jk = jpk
+      e3t_0(:,:,jk) = 2.0_wp * (gdept_0(:,:,jk) - gdepw_0(:,:,jk))
+
+      IF ( lwp ) THEN
+         jj = 25 
+         ji = 7
+         WRITE(numout,*) ""
+         WRITE(numout,*) "      k    gdepw_0(k)    gdept_0(k)    e3w_0(k)    e3t_0(k)"
+         WRITE(numout,*) ""
+         DO jk = 1, jpk
+            WRITE(numout,*) jk, gdepw_0(ji,jj,jk), gdept_0(ji,jj,jk), e3w_0(ji,jj,jk), e3t_0(ji,jj,jk)
+         ENDDO
+      END IF
+
+      !==============================
+      ! Computing gdept3w
+      !==============================
+
+      gde3w_0(:,:,1) = 0.5 * e3w_0(:,:,1)
+      DO jk = 2, jpk
+         gde3w_0(:,:,jk) = gde3w_0(:,:,jk-1) + e3w_0(:,:,jk)
+      END DO
+      e3t_0(:,:,jpk) = 2.0_wp * (gdept_0(:,:,jpk) - gdepw_0(:,:,jpk))
+
+      !==============================
+      ! Computing mbathy
+      !==============================
+
+      IF( lwp ) WRITE(numout,*) ''
+      IF( lwp ) WRITE(numout,*) 'MES mbathy:'
+      IF( lwp ) WRITE(numout,*) ''
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            DO jk = 1, jpkm1
+               !IF( lwp ) WRITE(numout,*) 'scobot: ', scobot(ji,jj), 'gdept_0: ', gdept_0(ji,jj,jk)
+               IF( scobot(ji,jj) >= gdept_0(ji,jj,jk) ) mbathy(ji,jj) = MAX( 2, jk )
+               IF( scobot(ji,jj) == 0.e0              ) mbathy(ji,jj) = 0
+               IF( scobot(ji,jj) < 0.e0               ) mbathy(ji,jj) = int( scobot(ji,jj)) !???? do we need it?                               
+            END DO
+            !IF( lwp ) WRITE(numout,*) 'mbathy(',ji,',',jj,') = ', mbathy(ji,jj)
+         END DO
+      END DO
+
+      !==============================================
+      ! Computing e3u_0, e3v_0, e3f_0, e3uw_0, e3vw_0
+      !==============================================
+
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            DO jk = 1, jpk
+
+               e3u_0(ji,jj,jk)=(MIN(1,mbathy(ji,jj))* e3t_0(ji,jj,jk)      +         &
+                                MIN(1,mbathy(ji+1,jj))*e3t_0(ji+1,jj,jk) ) /         &
+                                MAX( 1, MIN(1,mbathy(ji,jj))+MIN(1,mbathy(ji+1,jj))  )
+
+               e3v_0(ji,jj,jk)=(MIN(1,mbathy(ji,jj))* e3t_0(ji,jj,jk)      +         &
+                                MIN(1,mbathy(ji,jj+1))*e3t_0(ji,jj+1,jk) ) /         &
+                                MAX( 1, MIN(1,mbathy(ji,jj))+MIN(1,mbathy(ji,jj+1))  )
+
+               e3uw_0(ji,jj,jk)=(MIN(1,mbathy(ji,jj))* e3w_0(ji,jj,jk)      +         &
+                                 MIN(1,mbathy(ji+1,jj))*e3w_0(ji+1,jj,jk) ) /         &
+                                 MAX( 1, MIN(1,mbathy(ji,jj))+MIN(1,mbathy(ji+1,jj))  )
+
+               e3vw_0(ji,jj,jk)=(MIN(1,mbathy(ji,jj))* e3w_0(ji,jj,jk)      +         &
+                                 MIN(1,mbathy(ji,jj+1))*e3w_0(ji,jj+1,jk) ) /         &
+                                 MAX( 1, MIN(1,mbathy(ji,jj))+MIN(1,mbathy(ji,jj+1))  )
+
+               e3f_0(ji,jj,jk)=(MIN(1,mbathy(ji,jj))* e3t_0(ji,jj,jk)         +       &
+                                MIN(1,mbathy(ji+1,jj))*e3t_0(ji+1,jj,jk)      +       &
+                                MIN(1,mbathy(ji+1,jj+1))* e3t_0(ji+1,jj+1,jk) +       &
+                                MIN(1,mbathy(ji,jj+1))*e3t_0(ji,jj+1,jk) )    /       &
+                                MAX(  1, MIN(1,mbathy(ji,jj))+MIN(1,mbathy(ji,jj+1))  &
+                                 +   MIN(1,mbathy(ji+1,jj))+MIN(1,mbathy(ji+1,jj+1))  )
+            ENDDO
+         ENDDO
+      ENDDO     
+
+      ! Adjusting for geopotential levels, if any
+
+      DO je = 1, tot_env ! LOOP over all the requested envelopes
+
+         IF (je == 1) THEN
+            s_1st  = 1
+            num_s  = nn_slev(je)
+            max_env_up = 0._wp      ! surface
+            min_env_up = 0._wp      ! surface
+         ELSE
+            s_1st  = s_1st + num_s - 1
+            num_s  = nn_slev(je) + 1
+            max_env_up = rn_ebot_max(je-1)
+            min_env_up = rn_ebot_min(je-1)
+         ENDIF
+
+         max_env_dw  = rn_ebot_max(je)
+         min_env_dw  = rn_ebot_min(je)
+
+         IF ( max_env_up == min_env_up .AND. max_env_dw == min_env_dw ) THEN
+
+            DO jj = 1,jpjm1
+               DO ji = 1,jpim1
+                  DO jk = 1, num_s
+
+                     ind = s_1st+jk-1
+                     e3u_0 (ji,jj,ind) = MIN( e3t_0(ji,jj,ind), e3t_0(ji+1,jj,ind))
+                     e3uw_0(ji,jj,ind) = MIN( e3w_0(ji,jj,ind), e3w_0(ji+1,jj,ind))
+                     e3v_0 (ji,jj,ind) = MIN( e3t_0(ji,jj,ind), e3t_0(ji,jj+1,ind))
+                     e3vw_0(ji,jj,ind) = MIN( e3w_0(ji,jj,ind), e3w_0(ji,jj+1,ind))
+                     e3f_0 (ji,jj,ind) = MIN( e3t_0(ji,jj,ind), e3t_0(ji+1,jj,ind))
+
+                  ENDDO
+               ENDDO
+            ENDDO
+
+         ENDIF
+
+      ENDDO
+
+      !==============================
+      ! Computing gdept3w
+      !==============================
+
+      gde3w_0(:,:,1) = 0.5 * e3w_0(:,:,1)
+      DO jk = 2, jpk
+         gde3w_0(:,:,jk) = gde3w_0(:,:,jk-1) + e3w_0(:,:,jk)
+      END DO
+
+      !=================================================================================
+      ! From here equal to sco code - domzgr.F90 line 2079
+      ! Lateral B.C.
+
+      CALL lbc_lnk( e3t_0 , 'T', 1._wp )
+      CALL lbc_lnk( e3u_0 , 'U', 1._wp )
+      CALL lbc_lnk( e3v_0 , 'V', 1._wp )
+      CALL lbc_lnk( e3f_0 , 'F', 1._wp )
+      CALL lbc_lnk( e3w_0 , 'W', 1._wp )
+      CALL lbc_lnk( e3uw_0, 'U', 1._wp )
+      CALL lbc_lnk( e3vw_0, 'V', 1._wp )
+
+      fsdepw(:,:,:) = gdepw_0 (:,:,:)
+      fsde3w(:,:,:) = gde3w_0(:,:,:)
+      !
+      where (e3t_0   (:,:,:).eq.0.0)  e3t_0(:,:,:) = 1.0
+      where (e3u_0   (:,:,:).eq.0.0)  e3u_0(:,:,:) = 1.0
+      where (e3v_0   (:,:,:).eq.0.0)  e3v_0(:,:,:) = 1.0
+      where (e3f_0   (:,:,:).eq.0.0)  e3f_0(:,:,:) = 1.0
+      where (e3w_0   (:,:,:).eq.0.0)  e3w_0(:,:,:) = 1.0
+      where (e3uw_0  (:,:,:).eq.0.0)  e3uw_0(:,:,:) = 1.0
+      where (e3vw_0  (:,:,:).eq.0.0)  e3vw_0(:,:,:) = 1.0
+
+#if defined key_agrif
+      ! Ensure meaningful vertical scale factors in ghost lines/columns
+      IF( .NOT. Agrif_Root() ) THEN
+         !  
+         IF((nbondi == -1).OR.(nbondi == 2)) THEN
+            e3u_0(1,:,:) = e3u_0(2,:,:)
+         ENDIF
+         !
+         IF((nbondi ==  1).OR.(nbondi == 2)) THEN
+            e3u_0(nlci-1,:,:) = e3u_0(nlci-2,:,:)
+         ENDIF
+         !
+         IF((nbondj == -1).OR.(nbondj == 2)) THEN
+            e3v_0(:,1,:) = e3v_0(:,2,:)
+         ENDIF
+         !
+         IF((nbondj ==  1).OR.(nbondj == 2)) THEN
+            e3v_0(:,nlcj-1,:) = e3v_0(:,nlcj-2,:)
+         ENDIF
+         !
+      ENDIF
+#endif    
+
+      fsdept(:,:,:) = gdept_0 (:,:,:)
+      fsdepw(:,:,:) = gdepw_0 (:,:,:)
+      fsde3w(:,:,:) = gde3w_0(:,:,:)
+      fse3t (:,:,:) = e3t_0   (:,:,:)
+      fse3u (:,:,:) = e3u_0   (:,:,:)
+      fse3v (:,:,:) = e3v_0   (:,:,:)
+      fse3f (:,:,:) = e3f_0   (:,:,:)
+      fse3w (:,:,:) = e3w_0   (:,:,:)
+      fse3uw(:,:,:) = e3uw_0  (:,:,:)
+      fse3vw(:,:,:) = e3vw_0  (:,:,:)
+
+      IF( lwp ) WRITE(numout,*) 'Refine mbathy'
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            DO jk = 1, jpkm1
+               IF( scobot(ji,jj) >= fsdept(ji,jj,jk) )   mbathy(ji,jj) = MAX( 2, jk )
+            END DO
+            IF( scobot(ji,jj) == 0._wp               )   mbathy(ji,jj) = 0
+         END DO
+      END DO
+
+      IF( nprint == 1 .AND. lwp ) WRITE(numout,*) ' MIN val mbathy h90 ', MINVAL( mbathy(:,:) ),   &
+         &                                                       ' MAX ', MAXVAL( mbathy(:,:) )
+
+      IF( nprint == 1  .AND. lwp )   THEN         ! min max values over the local domain
+         WRITE(numout,*) 'zgr_sco : mbathy'
+         WRITE(numout,*) '~~~~~~~'
+         WRITE(numout,*) ' MIN val mbathy  ', MINVAL( mbathy(:,:)    ), ' MAX ', MAXVAL( mbathy(:,:) )
+         WRITE(numout,*) ' MIN val depth t ', MINVAL( gdept_0(:,:,:) ),   &
+            &                          ' w ', MINVAL( gdepw_0(:,:,:) ), '3w '  , MINVAL( gde3w_0(:,:,:) )
+         WRITE(numout,*) ' MIN val e3    t ', MINVAL( e3t_0  (:,:,:) ), ' f '  , MINVAL( e3f_0   (:,:,:) ),   &
+            &                          ' u ', MINVAL( e3u_0  (:,:,:) ), ' u '  , MINVAL( e3v_0   (:,:,:) ),   &
+            &                          ' uw', MINVAL( e3uw_0 (:,:,:) ), ' vw'  , MINVAL( e3vw_0  (:,:,:) ),   &
+            &                          ' w ', MINVAL( e3w_0  (:,:,:) )
+
+         WRITE(numout,*) ' MAX val depth t ', MAXVAL( gdept_0(:,:,:) ),   &
+            &                          ' w ', MAXVAL( gdepw_0(:,:,:) ), '3w '  , MAXVAL( gde3w_0(:,:,:) )
+         WRITE(numout,*) ' MAX val e3    t ', MAXVAL( e3t_0  (:,:,:) ), ' f '  , MAXVAL( e3f_0   (:,:,:) ),   &
+            &                          ' u ', MAXVAL( e3u_0  (:,:,:) ), ' u '  , MAXVAL( e3v_0   (:,:,:) ),   &
+            &                          ' uw', MAXVAL( e3uw_0 (:,:,:) ), ' vw'  , MAXVAL( e3vw_0  (:,:,:) ),   &
+            &                          ' w ', MAXVAL( e3w_0  (:,:,:) )
+      ENDIF
+
+      !================================================================================
+      ! Check coordinates makes sense
+      !================================================================================
+
+      DO ji = 1, jpi
+         DO jj = 1, jpj
+            DO jk = 1, mbathy(ji,jj)
+               ! check coordinate is monotonically increasing
+               IF (fse3w(ji,jj,jk) <= 0._wp .OR. fse3t(ji,jj,jk) <= 0._wp ) THEN
+                  WRITE(ctmp1,*) 'ERROR zgr_mes :   e3w   or e3t   =< 0  at point (i,j,k)= ', ji, jj, jk
+                  WRITE(numout,*) 'ERROR zgr_mes :   e3w   or e3t   =< 0  at point (i,j,k)= ', ji, jj, jk
+                  WRITE(numout,*) 'e3w',fse3w(ji,jj,:)
+                  WRITE(numout,*) 'e3t',fse3t(ji,jj,:)
+                  CALL ctl_stop( ctmp1 )
+               ENDIF
+               ! and check it has never gone negative
+               IF ( fsdepw(ji,jj,jk) < 0._wp .OR. fsdept(ji,jj,jk) < 0._wp ) THEN
+                  WRITE(ctmp1,*) 'ERROR zgr_mes :   gdepw or gdept =< 0  at point (i,j,k)= ', ji, jj, jk
+                  WRITE(numout,*) 'ERROR zgr_mes :   gdepw   or gdept   =< 0  at point (i,j,k)= ', ji, jj, jk
+                  WRITE(numout,*) 'gdepw',fsdepw(ji,jj,:)
+                  WRITE(numout,*) 'gdept',fsdept(ji,jj,:)
+                  CALL ctl_stop( ctmp1 )
+               ENDIF
+!              ! and check it never exceeds the total depth
+!               IF ( fsdepw(ji,jj,jk) > hbatt(ji,jj) ) THEN
+!                  WRITE(ctmp1,*) 'ERROR zgr_sco :   gdepw > hbatt  at point (i,j,k)= ', ji, jj, jk
+!                  WRITE(numout,*) 'ERROR zgr_sco :   gdepw > hbatt  at point (i,j,k)= ', ji, jj, jk
+!                  WRITE(numout,*) 'gdepw',fsdepw(ji,jj,:)
+!                  CALL ctl_stop( ctmp1 )
+!               ENDIF
+            END DO
+
+!            DO jk = 1, mbathy(ji,jj)-1
+!               ! and check it never exceeds the total depth
+!               IF ( fsdept(ji,jj,jk) > hbatt(ji,jj) ) THEN
+!                  WRITE(ctmp1,*) 'ERROR zgr_sco :   gdept > hbatt  at point (i,j,k)= ', ji, jj, jk
+!                  WRITE(numout,*) 'ERROR zgr_sco :   gdept > hbatt  at point (i,j,k)= ', ji, jj, jk
+!                  WRITE(numout,*) 'gdept',fsdept(ji,jj,:)
+!                  CALL ctl_stop( ctmp1 )
+!               ENDIF
+!            END DO
+         END DO
+      END DO
+      !
+      CALL wrk_dealloc( jpi, jpj, max_nn_env , envlt )
+      CALL wrk_dealloc( jpi, jpj, env_up, env_dw )
+      CALL wrk_dealloc( jpk, z_gsigw1, z_gsigt1, z_esigw1, z_esigt1 )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('zgr_mes')
+
+   END SUBROUTINE zgr_mes
+
+! =====================================================================================================
+
+   FUNCTION isodd( a ) RESULT(odd)
+      ! Notice that this method uses a btest intrinsic function. If you look at any number in binary 
+      ! notation, you'll note that the Least Significant Bit (LSB) will always be set for odd numbers 
+      ! and cleared for even numbers. Hence, all that is necessary to determine if a number is even or 
+      ! odd is to check the LSB. Since bitwise operations like AND, OR, XOR etc. are usually much faster 
+      ! than the arithmetic operations, this method will run a lot faster than the one with modulo 
+      ! operation.
+      ! http://forums.devshed.com/software-design-43/quick-algorithm-determine-odd-29843.html
+         
+      INTEGER, INTENT (in) :: a
+      LOGICAL              :: odd
+      odd = btest(a, 0)
+   END FUNCTION isodd
+
+! =====================================================================================================
+ 
+   FUNCTION iseven( a ) RESULT(even)
+      INTEGER, INTENT (in) :: a
+      LOGICAL              :: even
+      even = .NOT. isodd(a)
+   END FUNCTION iseven
+
+! =====================================================================================================
+
+   FUNCTION sech( x ) RESULT( seh )
+
+      REAL(wp), INTENT(in   ) :: x
+      REAL(wp)                :: seh
+
+      seh = 1._wp / COSH(x)
+      
+   END FUNCTION sech
+
+! =====================================================================================================
+
+   FUNCTION sigma( vgrid, pk, kmax ) RESULT( ps1 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE sigma  ***
+      !!       
+      !! ** Purpose :   provide the analytical function for sigma-coordinate
+      !!                (not stretched s-coordinate).
+      !!          
+      !! ** Method  :   the function provide the non-dimensional position of
+      !!                T and W points (i.e. between 0 and 1).
+      !!                T-points at integer values (between 1 and jpk)
+      !!                W-points at integer values - 1/2 (between 0.5 and
+      !!                jpk-0.5)
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT (in) ::   pk    ! continuous k coordinate
+      INTEGER, INTENT (in) ::   kmax  ! number of levels
+      INTEGER, INTENT (in) ::   vgrid ! type of vertical grid: 0 = T, 1 = W
+      REAL(wp)             ::   kindx ! index of T or W points
+      REAL(wp)             ::   ps1   ! value of sigma coordinate (-1 <= ps1 <=0)
+      !
+      SELECT CASE (vgrid)
+
+        CASE (0) ! T-points at integer values (between 1 and jpk)
+             kindx = REAL(pk,wp)
+        CASE (1) ! W-points at integer values - 1/2 (between 0.5 and jpk-0.5)
+             kindx = REAL(pk,wp) - 0.5_wp
+        CASE DEFAULT
+             WRITE(ctlmes,*) 'No valid vertical grid option selected'
+
+      END SELECT
+
+
+       ps1 = -(kindx - 0.5) / REAL(kmax-1) ! The surface is at the first W level
+                                           ! while the bottom coincides with the
+                                           ! last W level
+   END FUNCTION sigma
+
+! =====================================================================================================
+
+   FUNCTION s_coord( s, ca, cb, alpha, kmax, ftype ) RESULT ( pf1 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE s_coord ***
+      !!
+      !! ** Purpose :   provide the analytical stretching function 
+      !!                for s-coordinate.
+      !!
+      !! ** Method  :   if ftype = 2: Siddorn and Furner 2012
+      !!                              analytical function is used
+      !!                if ftype = 1: Song and Haidvogel 1994 
+      !!                              analytical function is used
+      !!                if ftype = 0: Madec et al. 1996
+      !!                              analytical function is used
+      !!                              (pag 65 of NEMO Manual)
+      !!                              Reference  : Madec, Lott, Delecluse and
+      !!                              Crepon, 1996. JPO, 26, 1393-1408
+      !!
+      !!                s MUST be NEGATIVE: -1 <= s <= 0
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in) ::   s              ! continuous not stretched 
+                                               ! "s" coordinate
+      REAL(wp), INTENT(in) ::   ca             ! surface stretch. coeff
+      REAL(wp), INTENT(in) ::   cb             ! bottom stretch. coeff
+      REAL(wp), INTENT(in) ::   alpha          ! alpha stretch. coeff for SF12
+      INTEGER, INTENT (in) ::   kmax           ! number of levels
+      INTEGER,  INTENT(in) ::   ftype          ! type of stretching function
+      REAL(wp)             ::   pf1            ! "s" stretched value
+      ! SF12 stretch. funct. parameters
+      REAL(wp)             ::   psmth          ! smoothing parameter for transition
+                                               ! between shallow and deep areas
+      REAL(wp)             ::   za1,za2,za3    ! local variables
+      REAL(wp)             ::   zn1,zn2,ps     ! local variables
+      REAL(wp)             ::   za,zb,zx       ! local variables
+      !!----------------------------------------------------------------------
+      SELECT CASE (ftype)
+
+        CASE (0) ! M96  stretching function
+           pf1 =   (   TANH( ca * ( s + cb )  ) - TANH( cb * ca ) ) &
+            &    * (   COSH( ca )                                   &
+            &        + COSH( ca * ( 2.e0 * cb - 1.e0 ) )          ) &
+            &    / ( 2._wp * SINH( ca ) )
+        CASE (1) ! SH94 stretching function
+           IF ( ca == 0 ) THEN      ! uniform sigma
+              pf1 = s
+           ELSE                     ! stretched sigma
+              pf1 = (1._wp - cb) * SINH(ca*s) / SINH(ca) + &
+            &       cb * ( ( TANH(ca*(s + 0.5_wp)) - TANH(0.5_wp*ca) ) / &
+            &       (2._wp*TANH(0.5_wp*ca)) )
+           END IF
+        CASE (2) ! SF12 stretching function
+           psmth = 1.0_wp ! We consider only the case for efold = 0
+           ps  = -s
+           zn1 =  1. / REAL(kmax-1)
+           zn2 =  1. -  zn1
+
+           za1 = (alpha+2.0_wp)*zn1**(alpha+1.0_wp)-(alpha+1.0_wp)*zn1**(alpha+2.0_wp)
+           za2 = (alpha+2.0_wp)*zn2**(alpha+1.0_wp)-(alpha+1.0_wp)*zn2**(alpha+2.0_wp)
+           za3 = (zn2**3.0_wp - za2)/( zn1**3.0_wp - za1)
+
+           za  = cb - za3*(ca-za1)-za2
+           za  = za/( zn2-0.5_wp*(za2+zn2**2.0_wp) - za3*(zn1-0.5_wp*(za1+zn1**2.0_wp)) )
+           zb  = (ca - za1 - za*( zn1-0.5_wp*(za1+zn1**2.0_wp ) ) ) / (zn1**3.0_wp - za1)
+           zx  = 1.0_wp-za/2.0_wp-zb
+
+           pf1 = za*(ps*(1.0_wp-ps/2.0_wp))+zb*ps**3.0_wp + &
+            &    zx*( (alpha+2.0_wp)*ps**(alpha+1.0_wp) - &
+            &         (alpha+1.0_wp)*ps**(alpha+2.0_wp) )
+           pf1 = -pf1*psmth+ps*(1.0_wp-psmth)
+        CASE (3) ! stretching function for deeper part of the domain
+           IF ( ca == 0 ) THEN      ! uniform sigma
+              pf1 = s
+           ELSE                     ! stretched sigma
+              pf1 = (1._wp - cb) * SINH(ca*s) / SINH(ca) 
+           END IF
+      END SELECT
+       
+   END FUNCTION s_coord     
+
+! =====================================================================================================
+
+   FUNCTION D1s_coord( s, ca, cb, alpha, kmax, ftype) RESULT( pf1 )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE D1s_coord ***
+      !!
+      !! ** Purpose :   provide the 1st derivative of the analytical 
+      !!                stretching function for s-coordinate.
+      !!
+      !! ** Method  :   if ftype = 2: Siddorn and Furner 2012
+      !!                              analytical function is used
+      !!                if ftype = 1: Song and Haidvogel 1994 
+      !!                              analytical function is used
+      !!                if ftype = 0: Madec et al. 1996
+      !!                              analytical function is used
+      !!                              (pag 65 of NEMO Manual)
+      !!                              Reference  : Madec, Lott, Delecluse and
+      !!                              Crepon, 1996. JPO, 26, 1393-1408
+      !!
+      !!                s MUST be NEGATIVE: -1 <= s <= 0
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   ) ::   s           ! continuous not stretched 
+                                               ! "s" coordinate
+      REAL(wp), INTENT(in)    ::   ca          ! surface stretch. coeff
+      REAL(wp), INTENT(in)    ::   cb          ! bottom stretch. coeff
+      REAL(wp), INTENT(in)    ::   alpha       ! alpha stretch. coeff for SF12
+      INTEGER, INTENT (in)    ::   kmax        ! number of levels
+      INTEGER,  INTENT(in   ) ::   ftype       ! type of stretching function
+      REAL(wp)                ::   pf1         ! "s" stretched value
+      ! SF12 stretch. funct. parameters
+      REAL(wp)                ::   psmth       ! smoothing parameter for transition
+                                               ! between shallow and deep areas
+      REAL(wp)                ::   za1,za2,za3 ! local variables
+      REAL(wp)                ::   zn1,zn2,ps  ! local variables
+      REAL(wp)                ::   za,zb,zx    ! local variables
+      REAL(wp)                ::   zt1,zt2,zt3 ! local variables
+      !!----------------------------------------------------------------------
+      SELECT CASE (ftype)
+
+        CASE (0) ! M96  stretching function
+           pf1 =  ( ca * ( COSH(ca*(2._wp * cb - 1._wp)) + COSH(ca)) * &
+                     sech(ca * (s+cb))**2 ) / (2._wp * SINH(ca))
+        CASE (1) ! SH94 stretching function
+           IF ( ca == 0 ) then      ! uniform sigma
+              pf1 = 1._wp / REAL(kmax,wp)
+           ELSE                     ! stretched sigma
+              pf1 = (1._wp - cb) * ca * COSH(ca*s) / (SINH(ca) * REAL(kmax,wp)) + &
+                    cb * ca * &
+                   (sech((s+0.5_wp)*ca)**2) / (2._wp * TANH(0.5_wp*ca) * REAL(kmax,wp))
+           END IF
+        CASE (2) ! SF12 stretching function
+           ps  = -s
+           zn1 =  1. / REAL(kmax-1)
+           zn2 =  1. -  zn1
+
+           za1 = (alpha+2.0_wp)*zn1**(alpha+1.0_wp)-(alpha+1.0_wp)*zn1**(alpha+2.0_wp)
+           za2 = (alpha+2.0_wp)*zn2**(alpha+1.0_wp)-(alpha+1.0_wp)*zn2**(alpha+2.0_wp)
+           za3 = (zn2**3.0_wp - za2)/( zn1**3.0_wp - za1)
+
+           za  = cb - za3*(ca-za1)-za2
+           za  = za/( zn2-0.5_wp*(za2+zn2**2.0_wp) - za3*(zn1-0.5_wp*(za1+zn1**2.0_wp)) )
+           zb  = (ca - za1 - za*( zn1-0.5_wp*(za1+zn1**2.0_wp ) ) ) / (zn1**3.0_wp - za1)
+           zx  = (alpha+2.0_wp)*(alpha+1.0_wp)
+
+           zt1 = 0.5_wp*za*(ps-1._wp)*((ps**2.0_wp + 3._wp*ps + 2._wp)*ps**alpha - 2._wp)
+           zt2 = zb*(zx*ps**(alpha+1.0_wp) - zx*ps**(alpha) + 3._wp*ps**2._wp)
+           zt3 = zx*(ps-1._wp)*ps**(alpha)
+
+           pf1 = zt1 + zt2 - zt3
+
+      END SELECT
+
+   END FUNCTION D1s_coord
+
+! =====================================================================================================
+
+  FUNCTION z_mes(dep_up, dep_dw, Cs, s, hc) RESULT( z )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE z_mes ***
+      !!
+      !! ** Purpose :   provide the analytical trasformation from the 
+      !!                computational space (mes-coordinate) to the  
+      !!                physical space (depth z)
+      !!
+      !!    N.B.: z is downward positive defined as well as envelope surfaces.
+      !!          Therefore, Cs MUST be positive, meaning 0. <= Cs <= 1.
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   ) :: dep_up  ! shallower envelope
+      REAL(wp), INTENT(in   ) :: dep_dw  ! deeper envelope
+      REAL(wp), INTENT(in   ) :: Cs      ! stretched s coordinate   
+      REAL(wp), INTENT(in   ) :: s       ! not stretched s coordinate
+      REAL(wp), INTENT(in   ) :: hc      ! critical depth
+      REAL                    :: z       ! downward positive depth
+      !!----------------------------------------------------------------------
+      ! 
+
+      z = dep_up + hc * s + Cs * (dep_dw - hc - dep_up)
+
+  END FUNCTION z_mes
+
+! =====================================================================================================
+
+  FUNCTION D1z_mes(dep_up, dep_dw, d1Cs, hc, kmax) RESULT( d1z )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE D1z_mes ***
+      !!
+      !! ** Purpose :   provide the 1st derivative of the analytical 
+      !!                trasformation from the computational space 
+      !!                (mes-coordinate) to the physical space (depth z)
+      !!
+      !!    N.B.: z is downward positive defined as well as envelope surfaces.
+      !!          Therefore, Cs MUST be positive, meaning 0. <= Cs <= 1.
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(in   ) :: dep_up  ! shallower envelope
+      REAL(wp), INTENT(in   ) :: dep_dw  ! deeper envelope
+      REAL(wp), INTENT(in   ) :: d1Cs    ! 1st derivative of the 
+                                         ! stretched s coordinate   
+      REAL(wp), INTENT(in   ) :: hc      ! critical depth
+      INTEGER,  INTENT(in   ) :: kmax    ! number of levels
+      REAL(wp)                :: d1z     ! 1st derivative of downward
+                                                 ! positive depth
+      !!----------------------------------------------------------------------
+      ! 
+
+      d1z = hc / REAL(kmax,wp) + d1Cs * (dep_dw - hc - dep_up)
+      !d1z = hc + d1Cs * (dep_dw - hc - dep_up)
+
+  END FUNCTION D1z_mes
+
+! =====================================================================================================
+
+  FUNCTION cub_spl(tau, d, n, ibcbeg, ibcend) RESULT ( c )
+      !!----------------------------------------------------------------------
+      !!
+      !! CUBSPL defines an interpolatory cubic spline.
+      !!
+      !! Discussion:
+      !!
+      !!    A tridiagonal linear system for the unknown slopes S(I) of
+      !!    F at TAU(I), I=1,..., N, is generated and then solved by Gauss
+      !!    elimination, with S(I) ending up in C(2,I), for all I.
+      !!
+      !! Author: Carl de Boor
+      !!
+      !! Reference: Carl de Boor, Practical Guide to Splines,
+      !!             Springer, 2001, ISBN: 0387953663, LC: QA1.A647.v27.
+      !!
+      !! Parameters:
+      !!
+      !!    Input: 
+      !!            TAU(N) : the abscissas or X values of the data points.  
+      !!                     The entries of TAU are assumed to be strictly 
+      !!                     increasing.
+      !!
+      !!            N      : the number of data points.  N is assumed to be 
+      !!                     at least 2.
+      !! 
+      !!            IBCBEG : boundary condition indicator at TAU(1).
+      !!                     = 0 no boundary condition at TAU(1) is given.
+      !!                         In this case, the "not-a-knot condition" 
+      !!                         is used.
+      !!                     = 1 the 1st derivative at TAU(1) is equal to 
+      !!                         the input value D(2,1).
+      !!                     = 2 the 2nd derivative at TAU(1) is equal to 
+      !!                         the input value D(2,1).
+      !!
+      !!            IBCEND : boundary condition indicator at TAU(N).
+      !!                     = 0 no boundary condition at TAU(N) is given.
+      !!                         In this case, the "not-a-knot condition" 
+      !!                         is used.
+      !!                     = 1 the 1st derivative at TAU(N) is equal to 
+      !!                         the input value D(2,2).
+      !!                     = 2 the 2nd derivative at TAU(N) is equal to 
+      !!                         the input value D(2,2).                                 
+      !!
+      !!            D(1,1): value of the function at TAU(1)
+      !!            D(1,1): value of the function at TAU(N)
+      !!            D(2,1): if IBCBEG is 1 (2) it is the value of the
+      !!                    1st (2nd) derivative at TAU(1)
+      !!            D(2,2): if IBCBEG is 1 (2) it is the value of the
+      !!                    1st (2nd) derivative at TAU(N) 
+      !!
+      !!    Output: 
+      !!            C(4,N) : contains the polynomial coefficients of the 
+      !!                     cubic interpolating spline.
+      !!                     In the interval interval (TAU(I), TAU(I+1)), 
+      !!                     the spline F is given by
+      !!
+      !!                          F(X) = 
+      !!                                  C(1,I) + 
+      !!                                  C(2,I) * H +
+      !!                                  C(3,I) * H^2 / 2 + 
+      !!                                  C(4,I) * H^3 / 6.
+      !!
+      !!                     where H = X - TAU(I).  
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER,  INTENT(in   ) :: n
+      REAL(wp), INTENT(in   ) :: tau(n)
+      REAL(wp), INTENT(in   ) :: d(2,2)
+      INTEGER,  INTENT(in   ) :: ibcbeg, ibcend
+      REAL(wp)                :: c(4,n)
+      REAL(wp)                :: divdf1
+      REAL(wp)                :: divdf3
+      REAL(wp)                :: dtau
+      REAL(wp)                :: g
+      INTEGER(wp)             :: i
+      !!----------------------------------------------------------------------
+      !  Initialise c and copy d values to c
+      c(:,:) = 0.0D+00
+      c(1,1) = d(1,1)
+      c(1,n) = d(1,2)
+      c(2,1) = d(2,1)
+      c(2,n) = d(2,2)
+      ! 
+      !  C(3,*) and C(4,*) are used initially for temporary storage.
+      !  Store first differences of the TAU sequence in C(3,*).
+      !  Store first divided difference of data in C(4,*).
+      DO i = 2, n
+         c(3,i) = tau(i) - tau(i-1)
+         c(4,i) = ( c(1,i) - c(1,i-1) ) / c(3,i)
+      END DO
+
+      !  Construct the first equation from the boundary condition
+      !  at the left endpoint, of the form:
+      !
+      !    C(4,1) * S(1) + C(3,1) * S(2) = C(2,1)
+      !
+      !  IBCBEG = 0: Not-a-knot
+      IF ( ibcbeg == 0 ) THEN
+
+         IF ( n <= 2 ) THEN
+            c(4,1) = 1._wp
+            c(3,1) = 1._wp
+            c(2,1) = 2._wp * c(4,2)
+         ELSE
+            c(4,1) = c(3,3)
+            c(3,1) = c(3,2) + c(3,3)
+            c(2,1) = ( ( c(3,2) + 2._wp * c(3,1) ) * c(4,2) &
+                     * c(3,3) + c(3,2)**2 * c(4,3) ) / c(3,1)
+         END IF
+
+      !  IBCBEG = 1: derivative specified.
+      ELSE IF ( ibcbeg == 1 ) then
+
+         c(4,1) = 1._wp
+         c(3,1) = 0._wp
+
+      !  IBCBEG = 2: Second derivative prescribed at left end.
+      ELSE IF ( ibcbeg == 2 ) then
+
+         c(4,1) = 2._wp
+         c(3,1) = 1._wp
+         c(2,1) = 3._wp * c(4,2) - c(3,2) / 2._wp * c(2,1)
+
+      ELSE
+         WRITE(ctlmes,*) 'CUBSPL - Error, invalid IBCBEG input option!'
+         CALL ctl_stop( ctlmes )
+      END IF
+  
+      !  If there are interior knots, generate the corresponding
+      !  equations and carry out the forward pass of Gauss,
+      !  elimination after which the I-th equation reads:
+      !
+      !    C(4,I) * S(I) + C(3,I) * S(I+1) = C(2,I).
+
+      IF ( n > 2 ) THEN
+
+         DO i = 2, n-1
+            g = -c(3,i+1) / c(4,i-1)
+            c(2,i) = g * c(2,i-1) + 3._wp * &
+                     ( c(3,i) * c(4,i+1) + c(3,i+1) * c(4,i) )
+            c(4,i) = g * c(3,i-1) + 2._wp * ( c(3,i) + c(3,i+1))
+         END DO
+
+         !  Construct the last equation from the second boundary,
+         !  condition of the form
+         !
+         !    -G * C(4,N-1) * S(N-1) + C(4,N) * S(N) = C(2,N)
+         !
+         !  If 1st der. is prescribed at right end ( ibcend == 1 ), 
+         !  one can go directly to back-substitution, since the C
+         !  array happens to be set up just right for it at this 
+         !  point.
+
+         IF ( ibcend < 1 ) THEN
+            !  Not-a-knot and 3 <= N, and either 3 < N or also 
+            !  not-a-knot at left end point.
+            IF ( n /= 3 .OR. ibcbeg /= 0 ) THEN
+               g      = c(3,n-1) + c(3,n)
+               c(2,n) = ( ( c(3,n) + 2._wp * g ) * c(4,n) * c(3,n-1) &
+                        + c(3,n)**2 * ( c(1,n-1) - c(1,n-2) ) / &
+                        c(3,n-1) ) / g
+               g      = - g / c(4,n-1)
+               c(4,n) = c(3,n-1)
+               c(4,n) = c(4,n) + g * c(3,n-1)
+               c(2,n) = ( g * c(2,n-1) + c(2,n) ) / c(4,n)
+            ELSE
+            !  N = 3 and not-a-knot also at left.
+               c(2,n) = 2._wp * c(4,n)
+               c(4,n) = 1._wp
+               g      = -1._wp / c(4,n-1)
+               c(4,n) = c(4,n) - c(3,n-1) / c(4,n-1)
+               c(2,n) = ( g * c(2,n-1) + c(2,n) ) / c(4,n)
+            END IF
+
+         ELSE IF ( ibcend == 2 ) THEN
+         !  IBCEND = 2: Second derivative prescribed at right endpoint.
+               c(2,n) = 3._wp * c(4,n) + c(3,n) / 2._wp * c(2,n)
+               c(4,n) = 2._wp
+               g      = -1._wp / c(4,n-1)
+               c(4,n) = c(4,n) - c(3,n-1) / c(4,n-1)
+               c(2,n) = ( g * c(2,n-1) + c(2,n) ) / c(4,n)
+         END IF
+
+      ELSE
+         !  N = 2 (assumed to be at least equal to 2!).
+
+         IF ( ibcend == 2  ) THEN
+
+            c(2,n) = 3._wp * c(4,n) + c(3,n) / 2._wp * c(2,n)
+            c(4,n) = 2._wp
+            g      = -1._wp / c(4,n-1)
+            c(4,n) = c(4,n) - c(3,n-1) / c(4,n-1)
+            c(2,n) = ( g * c(2,n-1) + c(2,n) ) / c(4,n)
+
+         ELSE IF ( ibcend == 0 .AND. ibcbeg /= 0 ) THEN
+
+            c(2,n) = 2._wp * c(4,n)
+            c(4,n) = 1._wp
+            g      = -1._wp / c(4,n-1)
+            c(4,n) = c(4,n) - c(3,n-1) / c(4,n-1)
+            c(2,n) = ( g * c(2,n-1) + c(2,n) ) / c(4,n)
+
+         ELSE IF ( ibcend == 0 .AND. ibcbeg == 0 ) THEN
+
+            c(2,n) = c(4,n)
+
+         END IF
+
+      END IF
+  
+      !  Back solve the upper triangular system 
+      !
+      !    C(4,I) * S(I) + C(3,I) * S(I+1) = B(I)
+      !
+      !  for the slopes C(2,I), given that S(N) is already known.
+      ! 
+      DO i = n-1, 1, -1
+         c(2,i) = ( c(2,i) - c(3,i) * c(2,i+1) ) / c(4,i)
+      END DO
+
+      !  Generate cubic coefficients in each interval, that is, the
+      !  derivatives at its left endpoint, from value and slope at its
+      !  endpoints.
+      DO i = 2, n
+         dtau     = c(3,i)
+         divdf1   = ( c(1,i) - c(1,i-1) ) / dtau
+         divdf3   = c(2,i-1) + c(2,i) - 2._wp * divdf1
+         c(3,i-1) = 2._wp * ( divdf1 - c(2,i-1) - divdf3 ) / dtau
+         c(4,i-1) = 6._wp * divdf3 / dtau**2
+      END DO
+
+  END FUNCTION cub_spl
+
+! =====================================================================================================
+
+  FUNCTION z_cub_spl(s, tau, c) RESULT ( z_cs )
+      !----------------------------------------------------------------------
+      !                 ***  function z_cub_spl ***
+      !
+      ! ** Purpose : evaluate the cubic spline F in the interval 
+      !              (TAU(I), TAU(I+1)). F is given by 
+      !              
+      !
+      !           F(X) = C1 + C2*H + (C3*H^2)/2 + (C4*H^3)/6
+      !
+      !              where H = S-TAU(I).
+      !
+      !              s MUST be positive: 0 <= s <= 1
+      !---------------------------------------------------------------------
+      INTEGER, PARAMETER      :: n = 2
+      REAL(wp), INTENT(in   ) :: s
+      REAL(wp), INTENT(in   ) :: tau(n)
+      REAL(wp), INTENT(in   ) :: c(4,n)
+      REAL(wp)                :: z_cs
+      REAL(wp)                :: c1, c2, c3, c4
+      REAL(wp)                :: H
+      !---------------------------------------------------------------------
+      c1 = c(1,1)
+      c2 = c(2,1)
+      c3 = c(3,1)
+      c4 = c(4,1)
+
+      H    = s - tau(1)
+
+      z_cs = c1 + c2 * H + (c3 * H**2._wp)/2._wp + (c4 * H**3._wp)/6._wp
+
+  END FUNCTION z_cub_spl  
+
+! =====================================================================================================
+
+  FUNCTION D1z_cub_spl(s, tau, c, kmax) RESULT ( d1z_cs )
+      !----------------------------------------------------------------------
+      !                 ***  function D1z_cub_spl ***
+      !
+      ! ** Purpose : evaluate the 1st derivative of cubic spline F  
+      !              in the interval (TAU(I), TAU(I+1)). 
+      !              The 1st derivative D1F is given by 
+      !              
+      !
+      !           D1F(S) = C1 + C2*H + (C3*H^2)/2 + (C4*H^3)/6
+      !
+      !              where H = S-TAU(I).
+      !
+      !              s MUST be positive: 0 <= s <= 1
+      !---------------------------------------------------------------------
+      INTEGER,  PARAMETER     :: n = 2
+      REAL(wp), INTENT(in   ) :: s
+      REAL(wp), INTENT(in   ) :: tau(n)
+      REAL(wp), INTENT(in   ) :: c(4,n)
+      INTEGER,  INTENT(in   ) :: kmax 
+      REAL(wp)                :: d1z_cs
+      REAL(wp)                :: c2, c3, c4
+      REAL(wp)                :: H
+      !---------------------------------------------------------------------
+      c2 = c(2,1) / REAL(kmax,wp)
+      c3 = c(3,1) / REAL(kmax,wp)
+      c4 = c(4,1) / REAL(kmax,wp)
+
+      H    = s - tau(1)
+
+      d1z_cs = c2 + c3 * H + (c4 * H**2._wp)/2._wp
+
+  END FUNCTION D1z_cub_spl
+
+! =====================================================================================================
+
+
+END MODULE zgrmes
